var id=GetUrlParam('id');

$(document).ready(function(){
	//$(document).pngFix();
	if($.browser.msie && $.browser.version==6.0){handleIe6();}
	if($('#news_wrap').is('div')){slideNews();}
	if($('#top').is('div')){showGallery();showContent();}		
	if($('#layout').is('div')){randomBg();}
	if($('.lightbox').is('a')){openImg();}
	//if($('#gallery_content').is('div')){showSectionGallery();}
})

function handleIe6(){
	$('#top h1').css({'background':'url("img/logo.gif") no-repeat'});
	$('#top ul').css({'background':'url("img/menu_bg.gif") no-repeat'});
	$('.prev').css({'background':'url("img/arrow_prev_big.gif") no-repeat'});
	$('.next').css({'background':'url("img/arrow_next_big.gif") no-repeat'});
}

function randomBg(){
	var totalNum = 15;
	var rndNum = Math.floor(Math.random() * totalNum);
	$('#layout').css({'background':'url(img/bg/bg_'+rndNum+'.jpg)'});
	window.setTimeout("randomBg();",25000);
}

/*function showSectionGallery(){
	$('.ul_link a').click(function(){
		var section=$(this).parent().attr('id');
		if($('.photogallery_wrap:visible')){
			$('.photogallery_wrap:visible').animate({height: 490,opacity:'hide'},'slow');	
		}
		$('#load_section').load('catalogo/'+section+'.html', function(){
			$('#photo_'+section).animate({height: 490,opacity:'show'},'slow',function(){
				slideGallery();
				openImg();
				if($.browser.msie && $.browser.version==6.0){handleIe6();}
				if($('.photogallery_wrap:visible p').length>12){
					$('.photogallery_wrap .prev, .photogallery_wrap .next').css({'visibility':'visible'});
				}
				
			});
		});
	})
}*/

function slideGallery(){
	$('.photogallery_content').jCarouselLite({
		btnNext: ".photogallery_wrap .next",
		btnPrev: ".photogallery_wrap .prev",
		speed:800,
		circular:false,
		visible:1
	});     
}

function slideNews(){
	$("#news").jCarouselLite({
		btnNext: "#news_wrap .next",
		btnPrev: "#news_wrap .prev",
		speed:600,
		visible:6
	});     
}

function openImg(){  
	$(".lightbox").lightbox({loopImages: true});
}

function showContent(){
	$('#top h1 a').click(function(){
		if($('#content .on').is('div')){
			$('.photogallery_wrap').animate({height: 0, opacity:'hide'},'slow');	
			$('#content .on').removeClass('on').animate({height: 0, opacity:'hide'},'slow',function(){
				$('#news_wrap').animate({opacity:'show'},'slow');	
			});
		}
	})
	$('.show_content a').click(function(){
		var section=$(this).parent().attr('id');
		$('#news_wrap').animate({opacity:'hide'},'slow',function(){
			if($('#content .on').is('div')){	
				$('.photogallery_wrap').animate({height: 0, opacity:'hide'},'slow');
				$('#content .on').removeClass('on').animate({height: 0, opacity:'hide'},'slow',function(){
					$('#'+section+'_content').addClass('on').animate({height: 490, opacity:'show'},'slow');
				});
			}else{
				$('#'+section+'_content').addClass('on').animate({height: 490, opacity:'show'},'slow');
			}													 
		});	
	})

}


function showGallery(){
	if(id>0){
		$('#news_wrap').hide();
		$('#chi_siamo_content,#contatti_content').css({'display':'none'}).height(0);
		$('#content #gallery_content').addClass('on').css({'display':'block'}).height(490);
		$('.photogallery_wrap').css({'display':'block'}).height(490);
		slideGallery();
		openImg();
		if($.browser.msie && $.browser.version==6.0){handleIe6();}
		if($('.photogallery_wrap:visible p').length>12){
			$('.photogallery_wrap .prev, .photogallery_wrap .next').css({'visibility':'visible'});
		
		}
	
/*		$('.photogallery_wrap').animate({height: 490,opacity:'show'},'slow',function(){
			slideGallery();
			openImg();
			if($.browser.msie && $.browser.version==6.0){handleIe6();}
			if($('.photogallery_wrap:visible p').length>12){
				$('.photogallery_wrap .prev, .photogallery_wrap .next').css({'visibility':'visible'});
			
			}
		});*/
	}
}


function GetUrlParam(paramName)
{
  var oRegex = new RegExp( '[\?&]' + paramName + '=([^&]+)', 'i' ) ;
  var oMatch = oRegex.exec( window.top.location.search ) ;
  if ( oMatch && oMatch.length > 1 )
    return decodeURIComponent( oMatch[1] ) ;
  else
    return '' ;
}



//pngfix
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(s($){3.1s.1k=s(j){j=3.1a({12:\'1m.1j\'},j);8 k=(n.P=="r 10 Z"&&U(n.v)==4&&n.v.E("14 5.5")!=-1);8 l=(n.P=="r 10 Z"&&U(n.v)==4&&n.v.E("14 6.0")!=-1);o(3.17.16&&(k||l)){3(2).L("1r[@m$=.M]").z(s(){3(2).7(\'q\',3(2).q());3(2).7(\'p\',3(2).p());8 a=\'\';8 b=\'\';8 c=(3(2).7(\'K\'))?\'K="\'+3(2).7(\'K\')+\'" \':\'\';8 d=(3(2).7(\'A\'))?\'A="\'+3(2).7(\'A\')+\'" \':\'\';8 e=(3(2).7(\'C\'))?\'C="\'+3(2).7(\'C\')+\'" \':\'\';8 f=(3(2).7(\'B\'))?\'B="\'+3(2).7(\'B\')+\'" \':\'\';8 g=(3(2).7(\'R\'))?\'1d:\'+3(2).7(\'R\')+\';\':\'\';8 h=(3(2).1c().7(\'1b\'))?\'19:18;\':\'\';o(2.9.y){a+=\'y:\'+2.9.y+\';\';2.9.y=\'\'}o(2.9.t){a+=\'t:\'+2.9.t+\';\';2.9.t=\'\'}o(2.9.w){a+=\'w:\'+2.9.w+\';\';2.9.w=\'\'}8 i=(2.9.15);b+=\'<x \'+c+d+e+f;b+=\'9="13:11;1q-1p:1o-1n;O:W-V;N:1l;\'+g+h;b+=\'q:\'+3(2).q()+\'u;\'+\'p:\'+3(2).p()+\'u;\';b+=\'J:I:H.r.G\'+\'(m=\\\'\'+3(2).7(\'m\')+\'\\\', D=\\\'F\\\');\';b+=i+\'"></x>\';o(a!=\'\'){b=\'<x 9="13:11;O:W-V;\'+a+h+\'q:\'+3(2).q()+\'u;\'+\'p:\'+3(2).p()+\'u;\'+\'">\'+b+\'</x>\'}3(2).1i();3(2).1h(b)});3(2).L("*").z(s(){8 a=3(2).T(\'N-S\');o(a.E(".M")!=-1){8 b=a.X(\'1g("\')[1].X(\'")\')[0];3(2).T(\'N-S\',\'1f\');3(2).Q(0).Y.J="I:H.r.G(m=\'"+b+"\',D=\'F\')"}});3(2).L("1e[@m$=.M]").z(s(){8 a=3(2).7(\'m\');3(2).Q(0).Y.J=\'I:H.r.G\'+\'(m=\\\'\'+a+\'\\\', D=\\\'F\\\');\';3(2).7(\'m\',j.12)})}1t 3}})(3);',62,92,'||this|jQuery||||attr|var|style|||||||||||||src|navigator|if|height|width|Microsoft|function|padding|px|appVersion|margin|span|border|each|class|alt|title|sizingMethod|indexOf|scale|AlphaImageLoader|DXImageTransform|progid|filter|id|find|png|background|display|appName|get|align|image|css|parseInt|block|inline|split|runtimeStyle|Explorer|Internet|relative|blankgif|position|MSIE|cssText|msie|browser|hand|cursor|extend|href|parent|float|input|none|url|after|hide|gif|pngFix|transparent|blank|line|pre|space|white|img|fn|return'.split('|'),0,{}));
