$(function() { 

	// --------------------------------------------------
	// per gestione rullo home page
	$('#homeButtons a.butt').mouseenter(function(event) {
		$("#homeButtons a.butt").removeClass("selected");
		$("#homeBigpic a img").attr("src", "css/img/rullo/" + $(this).attr("id") + ".jpg" );
		$("#homeBigpic a").attr("href", $(this).attr("href") );
		$(this).addClass("selected");
	});
	$('#homeButtons a').mouseleave(function(event) {
		//$("#homeButtons a.butt").removeClass("selected");
		$(this).addClass("selected");
	});
	// --------------------------------------------------

	try
	{
		// inizializzo lo shadowbox (non è in tutte le pagine)
		Shadowbox.init({overlayOpacity:0.6, overlayColor:"#FF0033"});
	}
	catch (e) { }

	setTimeout("fixColumns();",1500);
	
});


function fixColumns() {

if ($('#mainRight').length > 0) {
	// --------------------------------------------------
	// fix altezza colonne float
	var y1,y2,y;
	$('#mainRight').css("height","auto");
	$('#mainLeft').css("height","auto");
	y1 = $('#mainRight').height();
	y2 = $('#mainLeft').height();
	if (y1>y2) y=y1; else y=y2;
	$('#mainRight').css("height",y+"px");
	$('#mainLeft').css("height",y+"px");

	$('#mainHome').css("height","auto");
	//$('#homeMainRight').css("height","auto");
	//$('#homeMainLeft').css("height","auto");
	y1 = $('#homeMainRight').height();
	y2 = $('#homeMainLeft').height();
	if (y1>y2) y=y1; else y=y2;
	$('#homeMainRight').css("height",y+"px");
	$('#homeMainLeft').css("height",y+"px");
	$('#mainHome').css("height",y+"px");
	// --------------------------------------------------
}
}


/*
function showTip() { 
	$("#TipBox").show("fast");
}
function hideTip() {
	$("#TipBox").hide("");
}
*/
function check_login() {
	if (document.forms["tryLogin"].username.value!="" && document.forms["tryLogin"].password.value!="") {
		document.forms["tryLogin"].submit();
	} else {
		alert("Inserisci uno Username e una Password validi!");
	}
}
function openShadowbox(content, player, title, w, h){
	Shadowbox.open({
		content:    content,
		player:     player,
		title:      title,
		height:     (h?h:120),
		width:      (w?w:320)
	});
}
/*
function nosondaggio() {
	openShadowbox("<div id='alertsb'><div style='padding:10px;'>Per accedere ai sondaggi è necessario registrarsi.</div></div>","html","",400,200);
}
function iscrizopen() {
	openShadowbox("<div id='alertsb'><div style='padding:10px;'><form method=\"post\" target='_top' action =\"record.php\" id=\"tryCode\">" +
		"<div id=\"codice\"><img src='img/titolodiventa.jpg' alt='Diventa Amica di Lierac'/><p>Stringere un'amicizia non è mai stato così semplice: basta inserire qui sotto la tua e-mail e il codice a barre che trovi sulla confezione di tutti i prodotti Lierac." +
		"<table><tr>" +
		"<td><h6>Email</h6></td>" + 
		"<td><h6>Codice a barre</h6></td>" +
		"</tr><tr>" +
		"<td><input name=\"cod_mail\" id=\"cod_mail\" type=\"text\" class=\"buca\" /></td>" +
		"<td><input name=\"cod_ean\" id=\"cod_ean\" type=\"text\" class=\"buca\" /></td>" +
		"<td><a href=\"javascript:$('#tryCode').submit();\"><img src='img/btndiventa.jpg'/></a></td>" +
		"</tr></table>" +
		"</div></form></div></div>","html","",650,200);
}
*/

var LOGID = null;

function checkLogged(gotothis) {
	// verifica se l'utente è loggato,
	// se lo è manda a gotothis
	// altrimenti visualizza il messaggio d'errore
	// è utilizzata per alcuni link tipo quello dei solari
	// 
	if (LOGID) {
		document.location.href=gotothis;
	} else {
		document.location.href="registrazione.php";
		/*
		openShadowbox("<div id='alertsb'><div style='padding:10px;'><form method=\"post\" target='_top' action =\"record.php\" id=\"tryCode\">" +
			"<div id=\"codice\"><p>Questo link è accessibile solo agli utenti registrati e loggati sul sito di Amiche Di Lierac, se vuoi puoi registrarti adesso, oppure se hai già username e password puoi inserirle in alto a destra nella pagina:<br/><br/></p><img src='img/titolodiventa.jpg' alt='Diventa Amica di Lierac' height='20'/><p>Inserisci qui sotto la tua e-mail e il codice a barre che trovi sulla confezione di tutti i prodotti Lierac." +
			"<table><tr>" +
			"<td><h6>Email</h6></td>" + 
			"<td><h6>Codice a barre</h6></td>" +
			"</tr><tr>" +
			"<td><input name=\"cod_mail\" id=\"cod_mail\" type=\"text\" class=\"buca\" /></td>" +
			"<td><input name=\"cod_ean\" id=\"cod_ean\" type=\"text\" class=\"buca\" /></td>" +
			"<td><a href=\"javascript:$('#tryCode').submit();\"><img src='img/btndiventa.jpg'/></a></td>" +
			"</tr></table>" +
			"</div></form></div></div>","html","",650,240);
		*/
	}
}

function gup( name ) { /* prende i parametri da una querystring get */
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null ) return ""; else return results[1];
}


/*
	images preloader
*/
var cache = [];
// Arguments are image paths relative to the current page.
function preLoadImages() {
	var args_len = arguments.length;
	for (var i = args_len; i--;) {
	  var cacheImage = document.createElement('img');
	  cacheImage.src = arguments[i];
	  cache.push(cacheImage);
	}
}


