/**
 * slideanimations
 */
//old animations, with slide-effect
/*jQuery.fn.slideFadeOut = function(speed, easing, callback) {
  return this.animate({opacity: '0', left: '-25%'}, speed, easing, callback);
};

jQuery.fn.slideFadeIn = function(speed, easing, callback) {
  return this.animate({opacity: '1', left: '0px'}, speed, easing, callback);
};*/
//new animations
jQuery.fn.slideFadeOut = function(speed, easing, callback) {
  return this.animate({opacity: '0'}, speed, easing, callback);
};

jQuery.fn.slideFadeIn = function(speed, easing, callback) {
  return this.animate({opacity: '1'}, speed, easing, callback);
};



// start vars
var ajax = false;
var blowup = false;
var produktmain = false; 

/**
 * Function : dump()
 * Arguments: The data - array,hash(associative array),object
 *    The level - OPTIONAL
 * Returns  : The textual representation of the array.
 * This function was inspired by the print_r function of PHP.
 * This will accept some data as the argument and return a
 * text that will be a more readable version of the
 * array/hash/object that is given.
 * Docs: http://www.openjs.com/scripts/others/dump_function_php_print_r.php
 */
function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects 
		for(var item in arr) {
			var value = arr[item];
			
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}


function rmWhiteSpace(str) {	
	str = str.replace(/\s+/g,'');
	return str;
}

function explode (delimiter, string, limit) {
    // http://kevin.vanzonneveld.net
    // +     original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: kenneth
    // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: d3x
    // +     bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: explode(' ', 'Kevin van Zonneveld');
    // *     returns 1: {0: 'Kevin', 1: 'van', 2: 'Zonneveld'}
    // *     example 2: explode('=', 'a=bc=d', 2);
    // *     returns 2: ['a', 'bc=d']
 
    var emptyArray = { 0: '' };
    
    // third argument is not required
    if ( arguments.length < 2 ||
        typeof arguments[0] == 'undefined' ||
        typeof arguments[1] == 'undefined' ) {
        return null;
    }
 
    if ( delimiter === '' ||
        delimiter === false ||
        delimiter === null ) {
        return false;
    }
 
    if ( typeof delimiter == 'function' ||
        typeof delimiter == 'object' ||
        typeof string == 'function' ||
        typeof string == 'object' ) {
        return emptyArray;
    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }
    
    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument
        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;
    }
}




function convert(txt) {

	if(!txt) return '';

	txt = txt.replace(/&/g,"&amp;");

	var new_text = '';

	for(var i = 0; i < txt.length; i++) {

		var c = txt.charCodeAt(i);

		if(typeof ENTITIES[c] != 'undefined') {

			new_text += '&' + ENTITIES[c] + ';';

		} else if(c < 128) {

			new_text += String.fromCharCode(c);

		}else {

			new_text += '&#' + c +';';

		}

	}

 

	return new_text.replace(/</g,"&lt;").replace(/>/g,"&gt;");

}

var ENTITIES = {34: "quot", 60: "lt", 62: "gt", 38: "amp", 160: "nbsp", 161: "iexcl", 162: "cent", 163: "pound", 164: "curren", 165: "yen", 166: "brvbar", 167: "sect", 168: "uml", 169: "copy", 170: "ordf", 171: "laquo", 172: "not", 173: "shy", 174: "reg", 175: "macr", 176: "deg", 177: "plusmn", 178: "sup2", 179: "sup3", 180: "acute", 181: "micro", 182: "para", 183: "middot", 184: "cedil", 185: "sup1", 186: "ordm", 187: "raquo", 188: "frac14", 189: "frac12", 190: "frac34", 191: "iquest", 192: "Agrave", 193: "Aacute", 194: "Acirc", 195: "Atilde", 196: "Auml", 197: "Aring", 198: "AElig", 199: "Ccedil", 200: "Egrave", 201: "Eacute", 202: "Ecirc", 203: "Euml", 204: "Igrave", 205: "Iacute", 206: "Icirc", 207: "Iuml", 208: "ETH", 209: "Ntilde", 210: "Ograve", 211: "Oacute", 212: "Ocirc", 213: "Otilde", 214: "Ouml", 215: "times", 216: "Oslash", 217: "Ugrave", 218: "Uacute", 219: "Ucirc", 220: "Uuml", 221: "Yacute", 222: "THORN", 223: "szlig", 224: "agrave", 225: "aacute", 226: "acirc", 227: "atilde", 228: "auml", 229: "aring", 230: "aelig", 231: "ccedil", 232: "egrave", 233: "eacute", 234: "ecirc", 235: "euml", 236: "igrave", 237: "iacute", 238: "icirc", 239: "iuml", 240: "eth", 241: "ntilde", 242: "ograve", 243: "oacute", 244: "ocirc", 245: "otilde", 246: "ouml", 247: "divide", 248: "oslash", 249: "ugrave", 250: "uacute", 251: "ucirc", 252: "uuml", 253: "yacute", 254: "thorn", 255: "yuml", 34: "quot", 60: "lt", 62: "gt", 38: "amp"};


function fade(object, startopaq, stopopaq, step, pause, hwr){
	var opaque = 0;
	if (startopaq < stopopaq) {
		opaque = startopaq + step;
	}
	else {
		opaque = startopaq - step;
	}
	
	document.getElementById(object).style.filter = 'alpha(opacity=' + opaque + ')';
	if (opaque == 100) {
		document.getElementById(object).style.MozOpacity = '1.00';
		document.getElementById(object).style.opacity = '1.00';
	}
	else {
		document.getElementById(object).style.MozOpacity = '0.' + opaque;
		document.getElementById(object).style.opacity = '0.' + opaque;
	}
	if (stopopaq == opaque) {
		if (hwr == true) {
			document.getElementById(object).style.visibility = 'hidden';
		}
	}
	else {
		setTimeout("fade('" + object + "'," + opaque + "," + stopopaq + "," + step + "," + pause + "," + hwr + ")", pause);
	}
}


function load_blowup(url) {
	if(blowup == false && url != false) {
		var dimmer = $("#dimmer");
		$('#dimmer').css("background-color","RGB(0,0,0)");
		$('#dimmer').css("visibility","visible");
		$('#specialcontent_load').css("visibility","visible");
		fade('dimmer' , 0 , 90 , 10 , 1 , false);
		
	
		blowup = new Image();
		blowup.src = url;
		setTimeout("load_blowup("+false+")",2000);
	} else {
		if(blowup.complete && blowup != false) {
			$('#specialcontent_blowup').attr("src",blowup.src);
			$('#specialcontent_blowup').css("width",blowup.width+"px");
			$('#specialcontent_blowup').css("height",blowup.height+"px");
			$('#specialcontent_blowup').css("margin-left",(blowup.width/2)*(-1)+'px');
					
			$('#specialcontent_closeblowup').css("visibility","visible");
			$('#specialcontent_load').css("visibility","hidden");
			$('#dimmer').css("background-color","RGB(255,255,255)");
			$('#dimmer').css("filter","alpha(opacity=100)");
			$('#dimmer').css("opacity",1);
	
			$('#specialcontent_blowup').css("visibility","visible");
		} else {
			if(blowup != false) {
				setTimeout("load_blowup("+false+")",1000);
			}
		}
	}
}

function load_video(url) {
	var dimmer = $("#dimmer");
	$('#dimmer').css("position","absolute");
	$('#dimmer').css("height",$(document).height()+"px");
	$('#dimmer').css("visibility","visible");
	fade('dimmer' , 0 , 90 , 10 , 1 , false);
	$('#specialcontent_video').css("visibility","visible");
	/*var flashvars = {};
	var params = {
		quality: "high",
		wmode: "transparent"
	};*/
	var attributes = {};
	//swfobject.embedSWF(url, "specialcontent_video", "100%", "100%", "9.0.0","",flashvars,params,attributes);
	
	var params = {
		swf_file: HTTP_ROOT+url
	};
	
	$.post('ajax/get_swf_size.php',params,function(data) {
		//console.debug(dump(data.swf_size));
		//console.debug("URL>>> "+swf_file);
		var new_swf_file = HTTP_ROOT+url;
		$("#specialcontent_video").html('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+data.swf_size[0]+'px" height="'+data.swf_size[1]+'px" type="application/x-shockwave-flash" data="'+new_swf_file+'" style="visibility:visible;"><param name="movie" value="'+new_swf_file+'"><param name="quality" value="high"><param name="wmode" value="transparent"><embed id="special_video_real" src="'+new_swf_file+'" quality="high" wmode="transparent" type="application/x-shockwave-flash" width="'+data.swf_size[0]+'px" height="'+data.swf_size[1]+'px" /></object>');		
	},"json");	
		
	//$(".logo").pixastic("invert");
} 


function kill_sc() {
	//$(".logo").pixastic("invert");
	$('#dimmer').css("position","fixed");
	$('#specialcontent').css("visibility","hidden");
	$('#specialcontent_ajax').html("");
	$('#specialcontent_ajax').css("visibility","hidden");
	$('#specialcontent_load').css("visibility","hidden");
	$('#specialcontent_video').css("visibility","hidden");
	$("#specialcontent_video_wrapper").html("<div id='specialcontent_video'></div>");
	
	

	if(blowup == false) {
		var dimmer = $("#dimmer");
		fade('dimmer' , 90 , 0 , 10 , 1 , true);
	} else {
		$('#specialcontent_closeblowup').css("visibility","hidden");
		$('#specialcontent_blowup').css("visibility","hidden");
		$('#specialcontent_blowup').attr("src","");
		$('#specialcontent_video').html("");
		$('#dimmer').css("visibility","hidden");
		$('#dimmer').css("background-color","RGB(0,0,0)");
	}
	ajax = false;
	blowup = false;
	//flash = false;
}

function kill_flash() {
	kill_sc();
}


function rand (min, max) {
    // http://kevin.vanzonneveld.net
    // +   original by: Leslie Hoare
    // +   bugfixed by: Onno Marsman
    // %          note 1: See the commented out code below for a version which will work with our experimental (though probably unnecessary) srand() function)
    // *     example 1: rand(1, 1);
    // *     returns 1: 1
    
    var argc = arguments.length;
    if (argc === 0) {
        min = 0;
        max = 2147483647;
    } else if (argc === 1) {
        throw new Error('Warning: rand() expects exactly 2 parameters, 1 given');
    }
    return Math.floor(Math.random() * (max - min + 1)) + min;       
}

function open_fb_layer() {
	$(".fb_box").css("display","block");
	
	$(".fb_box").mouseout(function() {
		$(this).css("display","none");
	});
}



