btnClose = '<br><br><br><input type="button" name="close" value="close" onClick="javascript:closeMsg();" class="inputText">';

jQuery.preloadImages = function(){

  for(var i = 0; i<arguments.length; i++){
    jQuery("<img>").attr("src", arguments[i]);
  }

}		


$(document).ready(function(){  	

	$('#flashcontent').flash({ 
		src: '/header.swf',
		width: 984,
		height: 165,
		wmode : 'transparent',
		expressInstall: true,
		allowScriptAccess : 'always',
		flashvars: { sezione: sez}
	},{version: 9});
	
  	//$.preloadImages("images/menu_home_1.gif", "images/menu_explore_1.gif", "images/menu_agenda_1.gif", "images/menu_card_1.gif", "images/menu_reservation_1.gif", "images/menu_contact_1.gif");

	$("img.rollover").mouseover(function (){this.src = this.src.replace("_0","_1");});
	$("img.rollover").mouseout(function (){this.src = this.src.replace("_1","_0");});

});

function closeMsg(){
	
	$('#msgAlert').fadeOut();
	
}

//controllo login
function LogginIn(){
	
	$('#msgAlert').html("Wait while checking account");
	$('#msgAlert').fadeIn();
	
	var ToDoIn 		= document.loginFrm.ToDo.value;
	var emailIn 	= document.loginFrm.email.value;
	var pswIn 		= document.loginFrm.psw.value;
	
	$.post("/phpLib/operazionisuDB.php",{ToDo: ToDoIn, email: emailIn, 	psw: pswIn},
		function(data){	
		
			arrData = data.split('**##**');
			url = window.location.href;
			if ((url.indexOf('cart.php') >-1) && (arrData[0]=="Account correct")) window.location.reload();
			else {				
				$('#msgAlert').html(arrData[0]);
				c = setInterval(function() { $('#msgAlert').fadeOut(); clearInterval(c);}, 2500);
				$('#login').html(arrData[1]);
			}
	 
	 });
	
}

function logOut (){
	
	$('#msgAlert').html("Wait while logging out");
	$('#msgAlert').fadeIn();
	
	$.post("/phpLib/operazionisuDB.php",{ToDo: 'logout'},
		function(data){	
		
			url = window.location.href;
			if (url.indexOf('cart.php') >-1) window.location.reload();
			else {
				c = setInterval(function() { $('#msgAlert').fadeOut(); clearInterval(c);}, 500);
				$('#login').html(data);
			}
	 });
	
}

function recuperoPsw (){
	
	loadFaceBox("/html/sendpassword.php",'');
	
}

function recuperaPassword (){
	
	var valido = $("#recPassword").valid();
	
	if (valido) {
	
		$('#msgAlert').html("Wait while send password");
		$('#msgAlert').fadeIn();
		submitForm ('recPassword', onSentPsw);
	
	}
	
}

function onSentPsw(responseText, statusText){
	
		$.facebox.close(); 
		$('#msgAlert').html(responseText.msg);
		c = setInterval(function() { $('#msgAlert').fadeOut(); clearInterval(c);}, 1500);

}

function submitForm(formName, onSuccess){
	
	var option = { 		   
		dataType : 		'json',			
		success:      onSuccess
	};
	
	$('#' + formName).ajaxForm(option);
	$('#' + formName).submit();
	
}

function loadFaceBox(page, onSuccess){
	
	jQuery.facebox(function() {
	
		$.get(page,
			   
		function(data){
	
			jQuery.facebox(data);
			if (onSuccess !='') eval(onSuccess + '()');
	
		});
	
	}) 
	
}

//Fading delle news

newsSelect = 1;

function setFading (){
	
	var nDiv = $('#news > div').length;
	if (nDiv > 1) setInterval(function() { $('#news_' + newsSelect).fadeOut("slow", function (){ newsSelect++; if(newsSelect>nDiv) newsSelect = 1; $('#news_' + newsSelect).fadeIn(); } ); }, 10000);
	
}

function tellUs (id_prodotto){
	
	loadFaceBox("/html/tellus.php?id_prodotto=" + id_prodotto,'');
	
}

function sizeChart (){
	
	loadFaceBox("/html/sizechart.html",'');
	
}

function shippingCost (){
	
	loadFaceBox("/html/shippingcost.html",'');
	
}
