$(document).ready(function(){
	topmenu();
	tooltip();
	
	jQuery('.topmenu').find('a[href='+window.location.href+']').parent().attr('id', function() {
  		return this.id + '_active' });
  
 
if ( $('.catfilters').length > 0) {
	var urlcheck = location.href ;
	$('.catfilters select option').each(function(){
		if ( $(this).attr('value') == urlcheck ) { $(this).attr('selected','selected') }	
	});		
}
if ( $('.catfiltersjs').length > 0) {
	initCatfilters();	
}

if ( $('.favdatesel').length > 0) {
	$('.favdatesel').datepicker();
	}

if ( $('.autogallery').length > 0 ) {
		 $('.autogallery a').attr('rel','fancygroup').fancybox();
}


if ( $('.listprodotto').length <= 0 ) {
	
	$('.offerPager').css('display','none') ;
} else {
	jQuery(".numelepage").change(function()
				{
					var vars = window.location.href.split("/");
					newloc=window.location.href;
					if(vars[vars.length-2]!='listino') newloc=window.location.href.replace("/"+vars[vars.length-2]+"/","/");
					
					window.location.href = cartellaWeb+"/redirect.php?op=setcookie&name=pagercatalog&value="+ jQuery(this).val()+"&url="+newloc;
					/*
					alert("sono qui");
					$.ajax({
					 type: "POST",
					 url: "../ajax.php?op=setcookie",
					 data: "name=pagercatalog&value="+ jQuery(this).val(),
					 success: function(msg){
							 
					 }
					});
					*/
					
				});
				jQuery(".numelepage").attr("disabled",false);

}
bizslide();

setTimeout("sidebarEq()",1000);
/*initHunt();	*/

}); /* /ready */

function topmenu(){
	
$('.topmenu').children('ul').children('li').css('cursor','pointer').click(function(){
	var go2 = $(this).find('a').attr('href');
	$(this).find('a').click(function(){ return false; });
	location.href = go2 ;
});


};/**/





	
	function tooltip(){
	
		$('.tooltip').hover(function(){
		
			$(this).children('.showtip').fadeIn('fast');
		
		},function(){
		
			$(this).children('.showtip').fadeOut('fast');
		
		} );
	
	};
	
	
	
function sidebarEq() {
	
var rfullH = $('.right_box').height();
var lfullH = $('.left_box').height();
var cfullH = $('.central_box').height() ;
var lh= 0; var rh = 0;


if ($.browser.msie) { }
else  {
	/*console.log(cfullH+','+lfullH+','+rfullH);*/
	if ( cfullH > rfullH && cfullH > lfullH ) {
		
		$('.left_box').children().each(function(){
			lh = lh + parseInt($(this).height()) +parseInt($(this).css('paddingTop'))+parseInt($(this).css('paddingBottom'))+parseInt($(this).css('marginTop'))+parseInt($(this).css('marginBottom')) ;		
		});
		var lh = cfullH - (lh) ;
		$('.left_spacer').css('height',lh);	
		$('.right_box').children().each(function(){
		
		rh = rh + parseInt($(this).height()) +parseInt($(this).css('paddingTop'))+parseInt($(this).css('paddingBottom'))+parseInt($(this).css('marginTop'))+parseInt($(this).css('marginBottom')) ;
		
		});
		var rh = cfullH - (rh) ;
		$('.right_spacer').css('height',rh);
		
		
							
	}  if ( lfullH < rfullH ) {
		$('.left_box').children().each(function(){
		
		lh = lh + parseInt($(this).height()) +parseInt($(this).css('paddingTop'))+parseInt($(this).css('paddingBottom'))+parseInt($(this).css('marginTop'))+parseInt($(this).css('marginBottom')) ;
		
		});
		var lh = rfullH - (lh) ;
		$('.left_spacer').css('height',lh);	
		
		
		
	} else if (rfullH < lfullH ){
	
		$('.right_box').children().each(function(){
		
		rh = rh + parseInt($(this).height()) +parseInt($(this).css('paddingTop'))+parseInt($(this).css('paddingBottom'))+parseInt($(this).css('marginTop'))+parseInt($(this).css('marginBottom')) ;
		
		});
		var rh = lfullH - (rh) ;
		$('.right_spacer').css('height',rh);	
			
		
	}
		
} /* /endif msie */
};



function bizslide() {
if ( $('#biz-slide').length > 0 ) {

var maxw = parseInt( $('#biz-slide').children('.wop').width() ) ;
var minw = parseInt( $('#biz-slide').children('li:not(.wop)').width() ) ;


$('.bzspane').click(function(){ 
		var clickedEle = $(this) ;
		
		if( $(clickedEle).parent().hasClass('wop') == true ) {
		
			
		
			
		} else {
			$('.wop').animate({ 'width':minw } ,90 , function(){
				
				
				$(clickedEle).parent().animate({ 'width':maxw  },150).addClass('wop');	
				
			} ).removeClass('wop');
			
		} 
		
	});
}
}; /* end bizslide*/





/*################## CACCIA AL TESORO ############################*/



function initHunt(){
	
	
	$('#submit').click(function() {
  		submitScore('da','dito','email','00:10',1);
	});




	$('.playnow').click( function(){ 
			resetcookie(); 
			
			var flag = false;
			$('#formcaccia').find('input[type=text]').each(function(){
				
				if ( $(this).attr('value') == '' ) {
					$(this).addClass('mandatory').bind('change',function(){ $(this).removeClass('mandatory').unbind('change'); flag=false; });
					flag = true ; 
						
				}
				
			});
			
			if (flag == true) { 
				$('#formcaccia').find('.errorli').show('fast');
			}
			else {
				$('#formcaccia').find('.errorli').hide('fast');

				var wname =  $('#formcaccia').find('input.name').attr('value');
				var wsurname =  $('#formcaccia').find('input.surname').attr('value');
				var wmail =  $('#formcaccia').find('input.email').attr('value');
				var wtempo = '';
				var wwin = '0';  /*alert(wname+','+wsurname+','+wmail+','+wtempo+','+wwin);*/
				writemecookie(wname,wsurname,wmail,wtempo,wwin);
				/*alert( $.cookie('trhunt'));*/
				parent.cbar.location.href= 'cbar.php?start=true' ;
				parent.main.location.reload();
			}
			
		return false;  });
	
	
	$('.rcook').click(function(){
/*		var mycookie = $.cookie('trhunt');
		alert (mycookie) ; return false ;*/
	});
	
	
	hints();
	
};/*inithunt*/


function hints(){
	/*$.cookie('trpath', 'path="1"&hint="2"');*/
	var cook = $.cookie('trpath');
	
	
	if ( cook != null ) {
		
		var op1 = 'path="'; var op2 ='"&hint="' ; 
		var path = cook.substring( cook.indexOf( op1)+op1.length , cook.indexOf(op2) );
		var hint = cook.substring( cook.indexOf( op2)+op2.length, cook.lastIndexOf('"') ); /*console.log('path='+path+', hint='+hint );*/
		$('#formcaccia').hide();
		$('#startsearch').show();
		$('.hint').each(function(){
			
			if( $(this).attr('path') == path && $(this).attr('hint') == hint ) {
				$(this).show().find('.nexthint').click(function(){
					
					numhint = parseInt(hint) ; 
					$.cookie('trpath','path="'+path+'"&hint="'+(numhint+1)+'"', {  path: '/', secure: false } ) ;  	
					parent.main.location.reload();
					return false;
				
				});	
				$(this).find('.showhint').click(function(){ $('.innerhint').show('fast'); return false; });
				
				
			} /*else { console.log('ahi') ; }*/
		}) ;
	
	} else { /*console.log( 'notplaying' );*/ }
	
	
};/**/


function initCatfilters() {
$('.catfiltersjs').each(function(){
	
	var pa = $(this) ;
	
	var closedh = $(pa).children('ul').height();
	var openh = 0;
	$(pa).children('ul').children('li').each(function(){
		
		var sopenh =  $(this).height() + parseInt($(this).css('marginTop')) + parseInt($(this).css('marginBottom')) +parseInt($(this).css('paddingTop')) +parseInt($(this).css('paddingBottom')) +parseInt($(this).css('borderTopWidth')) +parseInt($(this).css('borderBottomWidth')) ;
		openh += sopenh ;
	});
	
	var hidoverlay = '<div id="ctfovrly" style="position:fixed;width:100%;left:0;top:0;height:'+$('body').height()+'px;">&nbsp;</div>';
	$(pa).children('.ddown').toggle(function(){
	
		$(pa).children('ul').animate({ 'height':openh },100).addClass('xpand');
		$('body').prepend(hidoverlay); $(pa).children('ul').children('li:first').addClass('firstex');  $('#ctfovrly').click(function(){ $(pa).children('.ddown').trigger('click'); });
		
	},function(){
		$('#ctfovrly').remove(); $(pa).children('ul').children('li:first').removeClass('firstex');
		$(pa).children('ul').removeClass('xpand').animate({ 'height':closedh },100);  
			
	});/*ddownclick*/
	
	
	
	
/*$(pa).css('display','none');	*/
}); /*/each*/
};/**/















