var menuTimer = 0;

$(document).ready(function(){
	$(document.createElement('a')).attr('href', '/').html(
		$(document.createElement('img')).attr('src', 'images/linea_dombra.png') 
	).addClass('mainLogo').appendTo('#wrap');
	$('#navigation li').each(function(){
		var t=$(this);
		t.find('.submenuArrow').css({'margin-left':Math.round(t.width()/2)});
	});
	

	$('#navigation .submenu').hide();
	$('#navigation > li').hover(function(){
		window.clearTimeout(menuTimer);
		$('#navigation .submenu').hide();
		$(this).find('.submenu').show();
		return false;
	}, function(){
		menuTimer = window.setTimeout(function(){$('#navigation .submenu').hide();$('#navigation li.currentPage .submenu').show();}, 200);
		
	});
	if($.browser.msie && $.browser.version<7){
		DD_belatedPNG.fix('#theFooter .sponsors img');
	}
	if($.browser.msie && $.browser.version>6){
		window.setTimeout(function(){
			$('#navigation li.currentPage .submenu').show();
		}, 50);
	}
	
	$('.submenu').hover(function(){
		$(this).parent().find('a').addClass('hovera');
		},
		function(){
			$(this).parent().find('a').removeClass('hovera');
		}
	);
	
 $('.topTabs a').click(function(){
	 $('.topTabs li').removeClass('currentTab');
	 var t=$(this);
	 t.parent().addClass('currentTab');
	 $('.tabContent .tab').hide();
	 $('.tabContent .tab').eq($('.topTabs a').index(t)).show();
	 return false;
});

	//Playa
	/*
	$(document.createElement('img')).attr('src', 'images/audio_on.png'
	).appendTo('#audio_control');
	
	
	$('#audio_control').click(function() {
		$('#audio_control img').attr('src','images/audio_off.png');
		$('#playa').SetVariable("Request_command", "Stop");
		
	});
	*/
	

	
	$('.photoBook a').each(function(){
		try{
			var t=$(this).metadata();
			var tempHTML = '<dl class="ntzLightBoxDescription"><dt><strong>'+t.operaTitle+'</strong> '+t.operaAnno+'</dt>';
			for(var i=0; i<t.extraLine.length;i++){
				var newStuff = t.extraLine[i].replaceAll('[i]', '<em>').replaceAll('[/i]', '</em>').replaceAll('[b]', '<strong>').replaceAll('[/b]', '</strong>');
				tempHTML = tempHTML + '<dd>'+newStuff+'</dd>';
			}
			tempHTML = tempHTML + '</dl>';
			var th=$(this);
			if(th.attr('title')===''){
				//th.attr('title', tempHTML);
				th.data('newTitle', tempHTML);
			}else {
				th.data('newTitle', th.attr('title'));
			}
		}catch(err){}
	});
	$('.photoBook').each(function(i){
		var t=$(this);
		t.find('a').addClass('set-'+i);
		$('.set-'+i).lightBox({
			overlayBgColor  : '#FFFFFF'
		});
	});
	

});

function zoomSliders() {
 	$('#scelteTopGallery a').click(function(){
 		var t=$(this);
		$('#scelteTopGallery a').removeClass('currentImage');
		t.addClass('currentImage');
		var currentIndex = $('#scelteTopGallery a').index(t);
		var tmpImg = images[currentIndex];
		if(typeof(tmpImg.bigImgWidth)!=='undefined'){
			var zoomWidth = tmpImg.bigImgWidth
		}else {
			var zoomWidth = 450;
		}
		var tmp = $(document.createElement('a')).addClass('MagicZoom clearfix').attr({
			'href' : tmpImg.bigImg,
			'rel' : 'zoom-width:'+zoomWidth+'px zoom-height:350px always-show-zoom:true '
		}).append(	$(document.createElement('img')).attr('src', tmpImg.smallImg).addClass('magicImg') );
		
		$('#magicZoomContainer').empty().append(tmp);
		
		$('.imagesInfo .imageAbout').hide();
		$('.imagesInfo .imageAbout').eq(currentIndex).show();
		
		MagicZoom_findZooms();
		return false;
	});	
	var hash = parseURL(window.location.href);
	if(hash.hash!==''){
		$('#'+hash.hash).click();
	}else {
		$('#scelteTopGallery a:first').click();
	}
	autoHidePrevNextButtons();
	$('.galleryWrap .next, .galleryWrap .prev').click(function(){
		if($('#scelteTopGallery').is(':animated')){return false;}
		var t=$(this);
		var scrolled = parseInt($('#scelteTopGallery').css('left'), 10);
		var maxScroll = -($('#scelteTopGallery li').size()*240 - 960);
		if(t.hasClass('next')){
			if(scrolled>maxScroll){
				$('#scelteTopGallery').animate({
					// left:"-=960px"
					left:"-=480px"
				}, function(){autoHidePrevNextButtons();});
			}
		}else {
			if(scrolled<0){
				$('#scelteTopGallery').animate({
					left:"+=480px"
				}, function(){autoHidePrevNextButtons()});
			}
		}
		return false;
	});
	
	function autoHidePrevNextButtons() {
		//$('shape').hide();
		$('.galleryWrap .next, .galleryWrap .prev').show();
		var scrolled = parseInt($('#scelteTopGallery').css('left'), 10);
		var maxScroll = -($('#scelteTopGallery li').size()*240 - 960);
		if(scrolled<=maxScroll){$('.galleryWrap .next').hide();}
		if(scrolled>=0){$('.galleryWrap .prev').hide();}
	};//autoHidePrevNextButtons
};//zoomSliders

function parseURL(url) {
    var a =  document.createElement('a');
    a.href = url;
    return {
        source: url,
        protocol: a.protocol.replace(':',''),
        host: a.hostname,
        port: a.port,
        query: a.search,
        params: (function(){
            var ret = {},
                seg = a.search.replace(/^\?/,'').split('&'),
                len = seg.length, i = 0, s;
            for (;i<len;i++) {
                if (!seg[i]) { continue; }
                s = seg[i].split('=');
                ret[s[0]] = s[1];
            }
            return ret;
        })(),
        file: (a.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1],
        hash: a.hash.replace('#',''),
        path: a.pathname.replace(/^([^\/])/,'/$1'),
        relative: (a.href.match(/tp:\/\/[^\/]+(.+)/) || [,''])[1],
        segments: a.pathname.replace(/^\//,'').split('/')}
}


if(typeof(console)==='undefined'){
	var console= {
		log : function() {
			
		}
	}
}


String.prototype.replaceAll = function(strTarget, strSubString){
	var strText = this;
	var intIndexOfMatch = strText.indexOf( strTarget );
		while (intIndexOfMatch != -1){
 		strText = strText.replace( strTarget, strSubString )
		intIndexOfMatch = strText.indexOf( strTarget );
 	};
	return( strText );
};


(function($){$.extend({metadata:{defaults:{type:"class",name:"metadata",cre:/({.*})/,single:"metadata"},setType:function(type,name){this.defaults.type=type;this.defaults.name=name},get:function(elem,opts){var settings=$.extend({},this.defaults,opts);if(!settings.single.length){settings.single="metadata"}var data=$.data(elem,settings.single);if(data){return data}data="{}";if(settings.type=="class"){var m=settings.cre.exec(elem.className);if(m){data=m[1]}}else{if(settings.type=="elem"){if(!elem.getElementsByTagName){return undefined}var e=elem.getElementsByTagName(settings.name);if(e.length){data=$.trim(e[0].innerHTML)}}else{if(elem.getAttribute!=undefined){var attr=elem.getAttribute(settings.name);if(attr){data=attr}}}}if(data.indexOf("{")<0){data="{"+data+"}"}data=eval("("+data+")");$.data(elem,settings.single,data);return data}}});$.fn.metadata=function(opts){return $.metadata.get(this[0],opts)}})(jQuery);




(function(a){a.fn.lightBox=function(p){p=jQuery.extend({overlayBgColor:"#000",overlayOpacity:0.8,fixedNavigation:false,imageLoading:"images/lightbox-ico-loading.gif",imageBtnPrev:"images/lightbox-btn-prev.gif",imageBtnNext:"images/lightbox-btn-next.gif",imageBtnClose:"images/lightbox-btn-close.gif",imageBlank:"images/lightbox-blank.gif",containerBorderSize:10,containerResizeSpeed:400,txtImage:"Image",txtOf:"of",keyToClose:"c",keyToPrev:"p",keyToNext:"n",imageArray:[],activeImage:0},p);var i=this;function r(){o(this,i);return false}function o(v,u){a("embed, object, select").css({visibility:"hidden"});c();p.imageArray.length=0;p.activeImage=0;if(u.length==1){p.imageArray.push(new Array(v.getAttribute("href"),a(v).data("newTitle")))}else{for(var t=0;t<u.length;t++){p.imageArray.push(new Array(u[t].getAttribute("href"),a(u[t]).data("newTitle")))}}while(p.imageArray[p.activeImage][0]!=v.getAttribute("href")){p.activeImage++}l()}function c(){a("body").append('<div id="jquery-overlay"></div><div id="jquery-lightbox"><div id="lightbox-container-image-box"><div id="lightbox-container-image"><img id="lightbox-image"><div style="" id="lightbox-nav"><a href="#" id="lightbox-nav-btnPrev"></a><a href="#" id="lightbox-nav-btnNext"></a></div><div id="lightbox-loading"><a href="#" id="lightbox-loading-link"><img src="'+p.imageLoading+'"></a></div></div></div><div id="lightbox-container-image-data-box"><div id="lightbox-container-image-data"><div id="lightbox-image-details"><span id="lightbox-image-details-caption"></span><span id="lightbox-image-details-currentNumber"></span></div><div id="lightbox-secNav"><a href="#" id="lightbox-secNav-btnClose"><img src="'+p.imageBtnClose+'"></a></div></div></div></div>');var t=f();a("#jquery-overlay").css({backgroundColor:p.overlayBgColor,opacity:p.overlayOpacity,width:t[0],height:t[1]}).fadeIn();var u=h();a("#jquery-lightbox").css({top:u[1]+(t[3]/10),left:u[0]}).show();a("#jquery-overlay,#jquery-lightbox").click(function(){b()});a("#lightbox-loading-link,#lightbox-secNav-btnClose").click(function(){b();return false});a(window).resize(function(){var v=f();a("#jquery-overlay").css({width:v[0],height:v[1]});var w=h();a("#jquery-lightbox").css({top:w[1]+(v[3]/10),left:w[0]})})}function l(){a("#lightbox-loading").show();if(p.fixedNavigation){a("#lightbox-image,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber").hide()}else{a("#lightbox-image,#lightbox-nav,#lightbox-nav-btnPrev,#lightbox-nav-btnNext,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber").hide()}var t=new Image();t.onload=function(){a("#lightbox-image").attr("src",p.imageArray[p.activeImage][0]);j(t.width,t.height);t.onload=function(){}};t.src=p.imageArray[p.activeImage][0]}function j(w,z){var t=a("#lightbox-container-image-box").width();var y=a("#lightbox-container-image-box").height();var x=(w+(p.containerBorderSize*2));var v=(z+(p.containerBorderSize*2));var u=t-x;var A=y-v;a("#lightbox-container-image-box").animate({width:x,height:v},p.containerResizeSpeed,function(){g()});if((u==0)&&(A==0)){if(a.browser.msie){n(250)}else{n(100)}}a("#lightbox-container-image-data-box").css({width:w});a("#lightbox-nav-btnPrev,#lightbox-nav-btnNext").css({height:z+(p.containerBorderSize*2)})}function g(){a("#lightbox-loading").hide();a("#lightbox-image").fadeIn(function(){k();s()});q()}function k(){a("#lightbox-container-image-data-box").slideDown("fast");a("#lightbox-image-details-caption").hide();if(p.imageArray[p.activeImage][1]){a("#lightbox-image-details-caption").html(p.imageArray[p.activeImage][1]).show()}if(p.imageArray.length>1){a("#lightbox-image-details-currentNumber").html(p.txtImage+" "+(p.activeImage+1)+" "+p.txtOf+" "+p.imageArray.length).show()}}function s(){a("#lightbox-nav").show();a("#lightbox-nav-btnPrev,#lightbox-nav-btnNext").css({background:"transparent url("+p.imageBlank+") no-repeat"});if(p.activeImage!=0){if(p.fixedNavigation){a("#lightbox-nav-btnPrev").css({background:"url("+p.imageBtnPrev+") left 15% no-repeat"}).unbind().bind("click",function(){p.activeImage=p.activeImage-1;l();return false})}else{a("#lightbox-nav-btnPrev").unbind().hover(function(){a(this).css({background:"url("+p.imageBtnPrev+") left 15% no-repeat"})},function(){a(this).css({background:"transparent url("+p.imageBlank+") no-repeat"})}).show().bind("click",function(){p.activeImage=p.activeImage-1;l();return false})}}if(p.activeImage!=(p.imageArray.length-1)){if(p.fixedNavigation){a("#lightbox-nav-btnNext").css({background:"url("+p.imageBtnNext+") right 15% no-repeat"}).unbind().bind("click",function(){p.activeImage=p.activeImage+1;l();return false})}else{a("#lightbox-nav-btnNext").unbind().hover(function(){a(this).css({background:"url("+p.imageBtnNext+") right 15% no-repeat"})},function(){a(this).css({background:"transparent url("+p.imageBlank+") no-repeat"})}).show().bind("click",function(){p.activeImage=p.activeImage+1;l();return false})}}m()}function m(){a(document).keydown(function(t){d(t)})}function e(){a(document).unbind()}function d(t){if(t==null){keycode=event.keyCode;escapeKey=27}else{keycode=t.keyCode;escapeKey=t.DOM_VK_ESCAPE}key=String.fromCharCode(keycode).toLowerCase();if((key==p.keyToClose)||(key=="x")||(keycode==escapeKey)){b()}if((key==p.keyToPrev)||(keycode==37)){if(p.activeImage!=0){p.activeImage=p.activeImage-1;l();e()}}if((key==p.keyToNext)||(keycode==39)){if(p.activeImage!=(p.imageArray.length-1)){p.activeImage=p.activeImage+1;l();e()}}}function q(){if((p.imageArray.length-1)>p.activeImage){objNext=new Image();objNext.src=p.imageArray[p.activeImage+1][0]}if(p.activeImage>0){objPrev=new Image();objPrev.src=p.imageArray[p.activeImage-1][0]}}function b(){a("#jquery-lightbox").remove();a("#jquery-overlay").fadeOut(function(){a("#jquery-overlay").remove()});a("embed, object, select").css({visibility:"visible"})}function f(){var v,t;if(window.innerHeight&&window.scrollMaxY){v=window.innerWidth+window.scrollMaxX;t=window.innerHeight+window.scrollMaxY}else{if(document.body.scrollHeight>document.body.offsetHeight){v=document.body.scrollWidth;t=document.body.scrollHeight}else{v=document.body.offsetWidth;t=document.body.offsetHeight}}var u,w;if(self.innerHeight){if(document.documentElement.clientWidth){u=document.documentElement.clientWidth}else{u=self.innerWidth}w=self.innerHeight}else{if(document.documentElement&&document.documentElement.clientHeight){u=document.documentElement.clientWidth;w=document.documentElement.clientHeight}else{if(document.body){u=document.body.clientWidth;w=document.body.clientHeight}}}if(t<w){pageHeight=w}else{pageHeight=t}if(v<u){pageWidth=v}else{pageWidth=u}arrayPageSize=new Array(pageWidth,pageHeight,u,w);return arrayPageSize}function h(){var u,t;if(self.pageYOffset){t=self.pageYOffset;u=self.pageXOffset}else{if(document.documentElement&&document.documentElement.scrollTop){t=document.documentElement.scrollTop;u=document.documentElement.scrollLeft}else{if(document.body){t=document.body.scrollTop;u=document.body.scrollLeft}}}arrayPageScroll=new Array(u,t);return arrayPageScroll}function n(v){var u=new Date();t=null;do{var t=new Date()}while(t-u<v)}return this.unbind("click").click(r)}})(jQuery);