// JavaScript Document
var acptPolitica=false;
var menuOpened=true;

var userAgent;
var flash=false;
var doIncombo="abc";

var _i=0;
var arrJS=["js/jquery.simplemodal.js", "js/jquery.preload.js",
           "js/flash_detect.js", "js/jquery.pngFix.js",
           "js/jquery.swfobject.js", "js/conex.js",
           "js/jquery.lightbox.js", "js/jquery.slider.js"
           ];
$(document).ready(function(){
	loader(_i);
});
function loader(i){	
	$.getScript(arrJS[i], function(){
		if(_i<arrJS.length-1){
			_i++;
			loader(_i);
		}else{
			init();
		}
	});
}
function init(){
	$("#idioma").find("a[type='idiom']").click(function(){		
		var data_={idiom:$(this).attr("title")}
		
		$.post("beta/admin/tofront/idiom.php", data_, function(e){
			if(e.status)location.reload();
				//document.location.href="index.php";
		}, "json");
		return false;
	});
	drawLogotipo();
	drawFlash();
	showBigPhoto();
	uploadUser();
	activateIDIOM();
	userAgent= navigator.userAgent.toLowerCase();
	$("p#copy a").click(function(){
		flash=FlashDetect.installed;
		$.modal('<iframe src="Politica.php?idiom='+idioma+'" height=298" width="448" style="border:0" frameborder="0">', {
			closeHTML:"",			
			opacity :80,
			containerCss:{
				background:"#e3e1d2",
				height:298,
				padding:0,										
				width:448
			},
			
			closeClass: "modalClose",
			closeHTML: "<img src='img/btClose.gif' />",
			onOpen:function (dialog) {
				dialog.overlay.fadeIn('fast', function(){
					dialog.container.fadeIn('fast', function(){dialog.data.show();});
				});
			},
			onClose:function (dialog) {
				dialog.container.fadeOut('fast', function(){
					dialog.overlay.fadeOut('fast', function(){
						$.modal.close();
					});
				});
			}

		});
		return false;
	});
	
	$("li.MenuP").click(updateMenuP);
	$("#check").click(changeAcept);
	$("#btSendNews").click(sendNews);
	$("#btSendNews").bind("mouseenter", function(){
		$(this).css("background-position", "0px -16px");
	});
	$("#btSendNews").bind("mouseleave", function(){
		$(this).css("background-position", "0px 0px");
	});
	$(".MenuP").bind("mouseenter", function(){
		if(!menuOpened){
			$(this).css("background-position", "0px -36px");
		}else{								
			$(this).css("background-position", "0px -24px");
		}
			
	});
	$(".MenuP").bind("mouseleave", function(){
		if(!menuOpened){
			$(this).css("background-position", "0px -12px");
		}else{
			$(this).css("background-position", "0px 0px");
		}
	});
	$("#logotipo").click(function(){
		document.location.href="index.php";
	});
	
	setTitles();	
	sameHeight();
	setTitProduct();
	activateCombos();
	$(".overflowden").slider({
		left:$(".contPhoto").find("p.navLeftPhoto"),
		right:$(".contPhoto").find("p.navRightPhoto")
	});
	$("a.clean").lightBox({txtImage:$(this).attr("user-text"), showFooter:true, showData:true});
}
function activateIDIOM(){
	var bt_="#bt_"+idioma.toLowerCase();
	$(bt_).css("background-position", "0px -11px");
}
function drawLogotipo(){
	if($("#logotipo").attr("type")=="swf"){
		var random=Math.random()*4590;		
		$("#logotipo").flash({
			swf:$("#logotipo").find("img").attr("src")+"?rnd="+random,
			height:97,
			width:104,
			wmode:"transparent",
			quality:"high"
		});
	}else if($("#logotipo").attr("type")=="png"){
		$("#logotipo").pngFix();
	}
	$("#logotipo").show();	
}
function drawFlash(){
	/*var random=Math.random()*4590;
	$("#sofa").flash(
			{
				swf:"swf/productos_home.swf?rand="+random,
				height:412,
				width:417,
				wmode:"transparent",
				quality:"high"
			}
		);
		*/
	if($("#sofa").attr("type")=="swf"){
		var random=Math.random()*4590;		
		$("#sofa").flash({
			swf:$("#sofa").find("img").attr("src")+"?rnd="+random,
			height:412,
			width:417,
			wmode:"transparent",
			quality:"high"
		});
	}else if($("#sofa").attr("type")=="png"){
		$("#sofa").pngFix();
	}
	$("#sofa").show();
		
}
function sameHeight(){
	var _h=0;
	$(".columna").each(function(){
		var min=$(this).height();
		if(min>_h) _h=min;
	});
	var isIE = '\v' == 'v';
	$(".columna").each(function(){
		if(isIE)$(this).css("height", _h);
		else $(this).css("height", _h+40);
	});
	/////same height for list product
	_h=0;
	var _pos=0;
	$class1=$("#listado ul.class_1").children();
	$class2=$("#listado ul.class_2").children();
	$class3=$("#listado ul.class_3").children();
	$class4=$("#listado ul.class_4").children();
	
	var _h1=$class1.length*136;
	var _h2=$class2.length*136;
	var _h3=$class3.length*136;
	$("#listado ul.class_2").height(_h1);
	$("#listado ul.class_3").height(_h2);
	$("#listado ul.class_4").height(_h3);
}
function sameHeightLostadoUL(_item){
	
}
function setTitProduct(){
	$("div.titProduct").each(function(){
		$(this).flash({
			swf:"swf/titProduct.swf",
			height:20,
			width:182,
			wmode:"transparent",
			quality:"high",
			flashvars:{
				text:$(this).text()						
			}
					
		});
	});
}
function changeAcept(){
	/////////////////////////
	if(acptPolitica){
		$(this).css("background-position", "0px 0px");
		acptPolitica=false;
	}else{
		$(this).css("background-position", "0px -14px");
		acptPolitica=true;
	}
}
function updateMenuP(){
	
	if(!menuOpened){
		$(".MenuP").css("background-position", "0px 0px");
		$("div.quit").slideDown(500);
		$("div.sep").slideDown(500);
		$("#menuContent").animate({height:"96px"}, 500);
		$("#menu").animate({height:"103px"}, 500);
		$("#contLogotipo").animate({top:"80px"}, 500);
		menuOpened=true;
	}else{
		$(".MenuP").css("background-position", "0px -12px");
		$("div.quit").slideUp(500);
		$("div.sep").slideUp(500);
		$("#menuContent").animate({height:"34px"}, 500);
		$("#menu").animate({height:"41px"}, 500);
		$("#contLogotipo").animate({top:"18px"}, 500);
		menuOpened=false;
	}
}
function setTitles(){
	$("div.item").each( function(){

		
		var img=$(this).find("img");
		
		var prf=$(this).find("p");
		var txt="";
		
		
		
		var titular=$(prf).text();
		var multiline=false;
		if(titular.length>17) multiline=true;
		
		//alert("---"+ titular+"RRR")
		var _new=$(prf).attr("isNew");
		var _a=$(this).find("a");
		var _url=$(_a).attr("href");
		///alert(_url);
		var src=$(img).attr("src");
		///alert(unescape(_url)+" sdin "+escape(_url))
		random=Math.random()*4590;
		$(this).html("");
		$(this).flash(
			{
				
				swf:"swf/titDestacado.swf?rnd="+random,
				height:130,
				width:110,
				wmode:"transparent",
				quality:"high",
				flashvars:{
					titulo:titular,
					multiline:multiline,
					isnew:_new,
					img:src,
					url:_url
				}
				
			}
		);
		$(this).css("display", "block");
	});
}
function activateCombos(){
	
	$("#combo1").change(function(){
		if(!_beta)document.location.href="productos.php?category="+$(this).val();	
		else document.location.href="_productos.php?category="+$(this).val();
	});
	if(catSelected!=undefined){
		if(catSelected!="" && catSelected!="abc"){
			$("#combo1").val(catSelected);		
		}
	}
	
	$("#combo2").change(function(){
		if($(this).val==-1){
			document.location.href="productos.php";
		}else{
			//document.location.href="producto.php?id="+$(this).val();
			if(!_beta){
				if($(this).val()!=-1)document.location.href="producto.php?name="+$(this).val();
				else document.location.href="productos.php";
			}else{
				if($(this).val()!=-1)document.location.href="_producto.php?name="+$(this).val();
				else document.location.href="_producto.php";
			}
		}
	});
}
function getListCombo(value){
	doIncombo=value;
	data={getter:value};
	
	$.post("beta/admin/tofront/getComboList.php", data, onListCombo, "json");
}
function onListCombo(e){
	$("#combo1").removeAttr("disabled");
	$("#combo2").removeAttr("disabled");
	$("#combo2").html(e.option);
	
	
}
/**
 * 
 * @return void
 */
function showBigPhoto(){
	$('a[@rel*=ligthBox]').lightBox();
	$('a.prensa-recorte').lightBox();
}
function uploadUser(){
	$(".boton a").click(function(){
		$.modal('<iframe src="beta/admin/modules/uploadUser.php?idiom='+idioma+'" width="333" height="451" frameborder="0"></iframe>',{
			closeClass:"close"
		});
		return false;
	});
}
function closeUploader(){
	$.modal.close();
}
function showIt(){
	
}
