/* +--------------------------------------------------------------------------------------------+ */
/* ! Declaración de funciones para trabajar con cookies                                         ! */
/* !                                                                                            ! */
/* +--------------------------------------------------------------------------------------------+ */

function setCookie(name, value)
{
	//If name is the empty string, it places a ; at the beginning
	//of document.cookie, causing clearCookies() to malfunction.
	if(name != '')
	   document.cookie = name + '=' + value;
}

function getCookie(name)
{
	//Without this, it will return the first value
	//in document.cookie when name is the empty string.
	if(name == '')
	   return('');

	name_index = document.cookie.indexOf(name + '=');

	if(name_index == -1)
	   return('');

	cookie_value =  document.cookie.substr(name_index + name.length + 1,
	                                       document.cookie.length);

	//All cookie name-value pairs end with a semi-colon, except the last one.
	end_of_cookie = cookie_value.indexOf(';');
	if(end_of_cookie != -1)
	   cookie_value = cookie_value.substr(0, end_of_cookie);

	//Restores all the blank spaces.
	space = cookie_value.indexOf('+');
	while(space != -1)
    {
	    cookie_value = cookie_value.substr(0, space) + ' ' +
	    cookie_value.substr(space + 1, cookie_value.length);

	    space = cookie_value.indexOf('+');
    }

return(cookie_value);
}

function clearCookie(name)
{
	expires = new Date();
	expires.setYear(expires.getYear() - 1);

	document.cookie = name + '=null' + '; expires=' + expires;
}

function clearCookies()
{
	Cookies = document.cookie;
	Cookie = Cookies;
	expires = new Date();
	expires.setYear(expires.getYear() - 1);

	while(Cookie.length > 0)
    {
	    //All cookie name-value pairs end with a semi-colon, except the last one.
	    Cookie = Cookies.substr(0, Cookies.indexOf(';'));
	    Cookies = Cookies.substr(Cookies.indexOf(';') + 1, Cookies.length);

	    if(Cookie != '')
	       document.cookie = Cookie + '; expires=' + expires;
	    else
	       document.cookie = Cookies + '; expires=' + expires;
    }
}

/* +--------------------------------------------------------------------------------------------+ */
/* ! Funciones a ejecutar al cargar la página                                                   ! */
/* !                                                                                            ! */
/* +--------------------------------------------------------------------------------------------+ */

$(document).ready(function(){

	/* +----------------------------------------------------------------------------------------+ */
	/* ! Activamos los paneles de la columna derecha. Dependiendo de las cookies, los activa-   ! */
	/* ! remos abiertos o cerrados.                                                             ! */
	/* +----------------------------------------------------------------------------------------+ */

	if (getCookie('pd1') == '1'){
		animatedcollapse.addDiv("panRight_1", "fade=1,height=50px,hide=0");
		animatedcollapse.addDiv("low_abre_1", "fade=1,height=8px,hide=1");
		animatedcollapse.addDiv("low_cierra_1", "fade=1,height=8px,hide=0");
	} else {
		animatedcollapse.addDiv("panRight_1", "fade=1,height=50px,hide=1");
		animatedcollapse.addDiv("low_abre_1", "fade=1,height=8px,hide=0");
		animatedcollapse.addDiv("low_cierra_1", "fade=1,height=8px,hide=1");
	}

	if (getCookie('pd2') == '1') {
		animatedcollapse.addDiv("panRight_2", "fade=1,height=50px,hide=0");
		animatedcollapse.addDiv("low_abre_2", "fade=1,height=8px,hide=1");
		animatedcollapse.addDiv("low_cierra_2", "fade=1,height=8px,hide=0");
	} else {
		animatedcollapse.addDiv("panRight_2", "fade=1,height=50px,hide=1");
		animatedcollapse.addDiv("low_abre_2", "fade=1,height=8px,hide=0");
		animatedcollapse.addDiv("low_cierra_2", "fade=1,height=8px,hide=1");
	}

	if (getCookie('pd3') == '1') {
		animatedcollapse.addDiv("panRight_3", "fade=1,height=50px,hide=0");
		animatedcollapse.addDiv("low_abre_3", "fade=1,height=8px,hide=1");
		animatedcollapse.addDiv("low_cierra_3", "fade=1,height=8px,hide=0");
	} else {
		animatedcollapse.addDiv("panRight_3", "fade=1,height=50px,hide=1");
		animatedcollapse.addDiv("low_abre_3", "fade=1,height=8px,hide=0");
		animatedcollapse.addDiv("low_cierra_3", "fade=1,height=8px,hide=1");
	}
	animatedcollapse.init();

	/* +----------------------------------------------------------------------------------------+ */
	/* ! Inicializamos el panel de scroll de la ficha de ingredientes.                          ! */
	/* !                                                                                        ! */
	/* +----------------------------------------------------------------------------------------+ */

	$(function() {
		$('#scrollPanel').jScrollPane({
			scrollbarWidth : 10,
			scrollbarMargin : 10, /* 5, */
			wheelSpeed : 18,
			showArrows : true, //false,
			arrowSize : 0,
			animateTo : true, //false,
			dragMinHeight : 20, // 1,
			dragMaxHeight : 20, // 99999,
			animateInterval : 100,
			animateStep: 3,
			maintainPosition: false, //true,
			scrollbarOnLeft: false
		});
	});
	
	$(function() {
		$('#legal').jScrollPane({
			scrollbarWidth : 10,
			scrollbarMargin : 10, /* 5, */
			wheelSpeed : 18,
			showArrows : true, //false,
			arrowSize : 0,
			animateTo : true, //false,
			dragMinHeight : 20, // 1,
			dragMaxHeight : 20, // 99999,
			animateInterval : 100,
			animateStep: 3,
			maintainPosition: false, //true,
			scrollbarOnLeft: false
		});
	});

});


