function createCookie(name,value,days) {
	var expires;
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = "; expires="+date.toGMTString();
	}
	else expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return undefined;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

$(function(){
	if (window.locale.length==2) {
		createCookie("locale", window.locale, 7);
	}
});

function removeAccents(arg) {
	var PLAIN_ASCII =
		  "AaEeIiOoUu"    // grave
		+ "AaEeIiOoUu"  // acute
		+ "AaEeIiOoUu"  // circumflex
		+ "AaOoNn"        // tilde
		+ "AaEeIiOoUuYy"  // umlaut
		//+ "Aa"            // ring
		+ "Cc"            // cedilla
		//+ "OoUu"          // double acute
		;
	var ACCENTS = 
		  "ÀàÈèÌìÒòÙù"    // grave
		+ "ÁáÉéÍíÓóÚú"  // acute
		+ "ÂâÊêÎîÔôÛû"  // circumflex
		+ "ÃãÕõÑñ"        // tilde
		+ "ÄäËëÏïÖöÜüŸÿ"  // umlaut
		//+ "Aa"            // ring
		+ "Çç"            // cedilla
		//+ "OoUu"          // double acute
		;
	
	var il = arg.length;
	var i, c, p;
	var resp = "";
	for (i = 0; i < il; i++) {
		c = arg.charAt(i);
		p = ACCENTS.indexOf(c);
		if (p!=-1) {
			resp += PLAIN_ASCII.charAt(p);
		} else {
			resp += c;
		}
	}
	return resp;
}

function prepareForSearches(arg) {
	return removeAccents(arg).toLowerCase().replace(/[^0-9a-z]/g, " ").replace(/\s+/g, " ");
}

/*
 * jQuery css clip animation support -- Jim Palmer
 * version 0.1.2
 * idea spawned from jquery.color.js by John Resig
 * Released under the MIT license.
 */
(function(jQuery){
	jQuery.fx.step.clip = function(fx){
		if ( fx.state == 0 ) {
			var cRE = /rect\(([0-9]{1,})(px|em)[,]? ([0-9]{1,})(px|em)[,]? ([0-9]{1,})(px|em)[,]? ([0-9]{1,})(px|em)\)/;
			fx.start = cRE.exec( fx.elem.style.clip.replace(/,/g, '') );
			fx.end = cRE.exec( fx.end.replace(/,/g, '') );
		}
		var sarr = new Array(), earr = new Array(), spos = fx.start.length, epos = fx.end.length,
			emOffset = fx.start[ss+1] == 'em' ? ( parseInt($(fx.elem).css('fontSize')) * 1.333 * parseInt(fx.start[ss]) ) : 1;
		for ( var ss = 1; ss < spos; ss+=2 ) { sarr.push( parseInt( emOffset * fx.start[ss] ) ); }
		for ( var es = 1; es < epos; es+=2 ) { earr.push( parseInt( emOffset * fx.end[es] ) ); }
		fx.elem.style.clip = 'rect(' +
			parseInt( ( fx.pos * ( earr[0] - sarr[0] ) ) + sarr[0] ) + 'px ' +
			parseInt( ( fx.pos * ( earr[1] - sarr[1] ) ) + sarr[1] ) + 'px ' +
			parseInt( ( fx.pos * ( earr[2] - sarr[2] ) ) + sarr[2] ) + 'px ' +
			parseInt( ( fx.pos * ( earr[3] - sarr[3] ) ) + sarr[3] ) + 'px)';
	}
})(jQuery);



function video(movie, title, containerId, width, height, autoPlay) {
	var swfVersionStr = "10.0.0";
	var xiSwfUrlStr = "";
	var flashvars = {
		movie:movie,
		title:title,
		autoPlay:autoPlay===true ? "true" : "false"
	};
	var params = {};
	params.quality = "high";
	params.bgcolor = "#000000";
	params.play = "true";
	params.loop = "true";
	params.wmode = "window";
	params.scale = "noscale";
	params.menu = "true";
	params.devicefont = "false";
	params.salign = "";
	params.allowscriptaccess = "sameDomain";
	params.allowfullscreen = "true";
	var attributes = {};
	attributes.id = containerId+"_player";
	attributes.name = containerId+"_player";
	attributes.align = "middle";
	$('#'+containerId).html('');
	$('#'+containerId).append('<span id="'+containerId+'_container____"></span>');
	$('#'+containerId+"_title").html(title);
	swfobject.embedSWF(
			window.contextPath+"/recursos/PlayerDani.swf?v=3", containerId+'_container____',
		width, height,
		swfVersionStr, xiSwfUrlStr,
		flashvars, params, attributes);
}
