// JavaScript Document



var div_last_preview;

var last_preview_id = 1;



var selected_item = 1;

var selected_div;



var active_id = 1;

var active_div;



var last_id = 1;

var last_div;



function rollOverDiv(p_div_id){

	

	var t_div = document.getElementById("div_preview_"+p_div_id);

	

	active_id = p_div_id;

	active_div = t_div;

}



function rollOutDiv(p_div_id){



	if(p_div_id != selected_item){

		closePreviewDiv(p_div_id);

	}



	last_id = p_div_id;

	

	//last_preview_id = p_div_id;

}



function openPreviewDiv(p_div){

	var t_div = document.getElementById("div_preview_"+p_div);

	if(t_div != undefined){

		t_div.style.visibility = 'visible';

		t_div.style.height = '50px';

	}

}



function showPreview(p_div_id){

	var t_div = document.getElementById("div_preview_"+p_div_id);

	

	openPreviewDiv(p_div_id);

	

	//



		/*if(div_last_preview != t_div && (last_preview_id != selected_item) && (div_last_preview != undefined)){

			closePreviewDiv(last_preview_id);			

			

			last_preview_id = p_div_id;

			div_last_preview = t_div;

		}*/

		

	//}catch(e){



	//}

	

	

}





function toggleLanguage2(p_language){

	reloadPage();

	//setLanguage(p_language);

	

	/*switch(p_language.toLowerCase()){

		case("eng") : alert("Cambiando a idioma ingles.");

		break;

		case("fra") : alert("Cambiando a idioma frances.");

		break;

		default : alert("Cambiando a idioma espanol.");

	}*/

	

}





function setLanguage(p_language){

	window.open("/beta/zarlek/ipub/set_language.php?language="+p_language, "_self");

}



function reloadPage(){

	loadPage(current_page, current_level);	

	loadLeftSection(current_left_page_1, current_left_page_2);

}



function leftItemClick(p_kw, p_kw2, p_item_id, p_item_number){

	

	closePreviewDiv(selected_item);

	selected_item = p_item_number;



	var arrow = document.getElementById("arrow_"+p_item_number);	

	arrow.style.visibility = 'visible';

	

	loadPage(p_kw+"/"+p_kw2+".php?id="+p_item_id, 1);

}



function closePreviewDiv(p_div_id){



	var t_div = document.getElementById("div_preview_"+p_div_id);

	var arrow = document.getElementById("arrow_"+p_div_id);



	if(t_div != undefined){

		t_div.style.height = '0px';

		t_div.style.visibility = 'hidden';

		arrow.style.visibility = 'hidden';

	}

}



function zoomMainPhoto(p_src){

	

	var t_div = document.getElementById("div_main_photo_zoom");

	t_div.style.visibility = 'visible';

	t_div.innerHTML = "<img src='"+p_src+"'>";

}



function closeMainPhotoZoom(){

	

	var t_div = document.getElementById("div_main_photo_zoom");

	t_div.style.visibility = 'hidden';

	t_div.innerHTML = "";

}



function activateLightBox(){

	 $(function() {

        $('#gallery a').lightBox();

    });

}





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 null;

}





$$=function(p_id) {

      return(document.getElementById(p_id));

}



function addToCart(p_id){

	

	$.post("content/cart/add.php", function(data){

	

		

		var html = "Handbag " + p_id + " succesfully added!"

		html += "<br><a href='http://avanfeel:1942/projects/inges_2009/ipub/ajax.php?get=cart/view' target='ajax'>view cart</a>"

		

		$$("div_cart_add_button").innerHTML = html;

		

		

	});



}



function swapNavMenu(p_id){

	

	try{

		$$("img_btn_"+active_channel).src="images/menu/secciones/inactive/btn_"+active_channel +".gif";

	}catch(e){

	}



	$$("img_btn_"+p_id).src="images/menu/secciones/active/btn_"+p_id+".gif";

	

	active_channel = p_id;

}



function refreshCart(){

	//$$("div_cart_item_total").innerHTML = "Item Added!";

	//window.open("ajax/cart.php", "iframe_channel");

	

	$.get("ajax/get_cart_item_count.php", 

	

		function(data){	

			$$("div_cart_item_count").innerHTML = data + " items";

		}

	);

	

	$.get("ajax/get_cart_total.php", 

	

		function(data){	

			$$("div_cart_total").innerHTML = data;

		}

	);

	

}



function refreshCost(){



	$.get("ajax/get_cart_total.php", 

	

		function(data){	

			$$("div_cart_total").innerHTML = data;

		}

	);



}



function refreshCartHTML(p_html, p_html_2){

	$$("a_basket").innerHTML = p_html;

	$$("div_cart_user").innerHTML = p_html_2;

}



function setCurrency(p_unit){

	window.open("scripts/set_measure_unit.php?unit="+p_unit, "_self");

}



function showMeasureInUnits(p_unit){



	if(p_unit=='in'){

		$$("div_dimensions_1").style.display = 'none';

		$$("div_dimensions_2").style.display = 'block';

	}else{

		$$("div_dimensions_1").style.display = 'block';

		$$("div_dimensions_2").style.display = 'none';

	}



}



function setCurrency(p_curr){



	window.open("scripts/set_currency.php?curr="+p_curr, "_self");



	/*switch(p_curr){

		case "euro" :

			curr_html = "&euro;0.00";

			break;

		case "pound" :

			curr_html = "&pound;0.01";

			break;

		case "dollar" :

			curr_html = "$0.02";

			break;

	}



	$.get("ajax/set_currency.php?curr="+p_curr, 

	

		function(data){	

			$$("div_cart_total").innerHTML = curr_html;

		}

	);*/

	

}



function toggleHandbagsFilter(p_id){



	if($$("ul_hf_"+p_id).style.display != "none"){

		$$("ul_hf_"+p_id).style.display = "none";

	}else{

		$$("ul_hf_"+p_id).style.display = "block";

	}



}



function getProductCostByCurreny(p_id, p_currency){

	$.get("ajax/get_product_cost.php?curr="+p_curr+"&id="+p_id, 

	

		function(data){	

			$$("hadbags_price").innerHTML = getCurrHTML(p_currency) + " " + data;

		}

	);

	

}





function getCurrHTML(p_curr){



	var curr_html;



	switch(p_curr){

		case "euro" :

			curr_html = "&euro;0.00";

			break;

		case "pound" :

			curr_html = "&pound;0.01";

			break;

		case "dollar" :

			curr_html = "$0.02";

			break;

	}

	

	

	return(curr_html);

}



var last_leather;

function previewLeather(p_id, p_leather){

	var current_leather = document.getElementById("img_leather_"+p_leather);
	var current_leather_div = document.getElementById("div_leather_" + p_leather);
	
	if(current_leather == null) return(false);


	if((current_leather != undefined) && last_leather == document.getElementById("img_leather_"+p_leather)) return(false);

	if(last_leather!=undefined) last_leather.className = "none_selected_leather";
	
	current_leather.className = "selected_leather";

	last_leather = document.getElementById("img_leather_"+p_leather);
	
	//current_leather.style.padding = "50px";

	

	$("#bag_photo").fadeOut("slow",


	function(){

	

		//this.style.display = "block";		

		

		$("#div_preloader").show();
		
		var img = new Image();

		img.src = "images/bag_files/bag_"+ p_id +"/igp_2_"+p_leather+".jpg";

		this.innerHTML = "<img src='images/bag_files/bag_"+ p_id +"/igp_2_"+p_leather+".jpg'>";

		$(img).error(

			function(){
				$("#div_preloader").html("ERROR!");
			}

		);
		

		$(img).load(function() {

		

			$("#div_preloader").hide();

		

			$("#bag_photo").fadeIn("slow");

		});



		//this.innerHTML = "<div class='preloading'><img src='images/bag_files/bag_"+ p_id +"/igp_3.jpg'></div>";

		

		

	

		

	}

	

	

	);

	

}

	


	
	
function setLeather(p_id, p_leather){

	var current_leather = document.getElementById("img_leather_"+p_leather);
	var current_leather_div = document.getElementById("div_leather_" + p_leather);
	
	if(current_leather == null) return(false);


	if((current_leather != undefined) && last_leather == document.getElementById("img_leather_"+p_leather)) return(false);

	if(last_leather!=undefined) last_leather.className = "none_selected_leather";
	
	current_leather.className = "selected_leather";

	last_leather = document.getElementById("img_leather_"+p_leather);
	
	//current_leather.style.padding = "50px";
	

}

function previewPP(p_id){
	window.open("images/bag_files/bag_" + p_id + "/igp_4b.jpg", "_blank", "width=233, height=209");
}

function preview360(p_id){

	$("#bag_photo").fadeOut("slow",

		function(){
		
		$("#bag_photo").show();
		
		var h;
		
		if(p_id == "27" || p_id == "25" || p_id == "24"){
			h = "563";
		}else{
			h = "400";
		}
		
		var fvars = "bag="+p_id;
		
		if(p_id == "31"){
			fvars += "&image_count=41";
		}
		
		var html = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0' width='390' height='"+h+"' id='preloader' align='middle'>";
		html += "<param name='allowScriptAccess' value='sameDomain' />";
		html += "<param name='allowFullScreen' value='false' />";
		html += "<param name='scale' value='noorder' />";
		html += "<param name='align' value='t' />";
		html += "<param name='salign' value='t' />";
		html += "<param name='flashvars' value='"+fvars+"' />";
		html += "<param name='movie' value='swf/360_viewer.swf' /><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' />";
		html += "<embed align='t' salign='t' scale='noorder' flashvars='"+fvars+"' src='swf/360_viewer.swf' quality='high' bgcolor='#ffffff' width='390' height='"+h+"' name='preloader' align='middle' allowScriptAccess='sameDomain' allowFullScreen='false' type='application/x-shockwave-flash' pluginspage='http://www.adobe.com/go/getflashplayer' />";
		html += "</object>";
			
		$("#bag_photo").html(html);
		
		}
	
	)

	//window.open("images/bag_files/bag_" + p_id + "/ib_360.swf", "_blank", "width=800, height=700");
}

function exit_360_SG(p_id){

	$("#bag_photo").fadeOut("slow",
		
		function(){
		
			$(this).html("<img src='images/small_goods/img_"+p_id+"b.jpg' /><br /><a href='#' onclick='javascript:preview360_SG("+p_id+");'>click to view 360</a>");
		
			$("#bag_photo").fadeIn("slow",
			
				function(){
					
				}				
			
			)
		}
		
	);

}

function preview360_SG(p_id){

	var img_path = "sg_"+p_id;

	$("#bag_photo").fadeOut("slow",

		function(){
		
		$("#bag_photo").show();
		
		var h;
		
		h = "400";
		
		var fvars = "bag="+img_path;
		fvars += "&image_count=11";
		
		var html = "<div class='sg_360'><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0' width='390' height='"+h+"' id='preloader' align='middle'>";
		html += "<param name='allowScriptAccess' value='sameDomain' />";
		html += "<param name='allowFullScreen' value='false' />";
		html += "<param name='scale' value='noorder' />";
		html += "<param name='wmode' value='opaque' />";
		html += "<param name='align' value='t' />";
		html += "<param name='salign' value='t' />";
		html += "<param name='flashvars' value='"+fvars+"' />";
		html += "<param name='movie' value='swf/360_viewer.swf' /><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' />";
		html += "<embed wmode='opaque' align='t' salign='t' scale='noorder' flashvars='"+fvars+"' src='swf/360_viewer.swf' quality='high' bgcolor='#ffffff' width='390' height='"+h+"' name='preloader' align='middle' allowScriptAccess='sameDomain' allowFullScreen='false' type='application/x-shockwave-flash' pluginspage='http://www.adobe.com/go/getflashplayer' />";
		html += "</object></div><a href='#' onclick='javascript:exit_360_SG("+p_id+");'>Go back</a>";
		
		$("#bag_photo").html(html);
		
		}
	
	)

	//window.open("images/bag_files/bag_" + p_id + "/ib_360.swf", "_blank", "width=800, height=700");
}


function setCartButtonFV(p_leather, p_fvars){

	$("#td_cart_button").html("loading...");
	
	var fvars = p_fvars + "&leather=" + p_leather;
	
	var so = new SWFObject("swf/add_to_basket.swf", "mymovie", "200", "50", "8");
	so.addParam("flashvars", fvars);
	so.write("td_cart_button");
	
}