var isIE6=false;
var mhover = false;
var maxHeight = 608; /* altezza massima layout */
$(window).load(function(){
	if($('#layout').is('div')){
        if(!$('#cform').length){
		setLayout();
		menu.init();
         }
		if((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)){
				isIE6=true;
			}
	}

	$('p.image>img').animate({ opacity: 1 }, 'slow');

	$('#scrlDwn')
		.bind('mouseover', function() {
			mhover = true;
			x = window.setInterval("scrollText('down', 2)", 40);
			})
		.bind('mousedown', function() {
			window.clearInterval(x);
			x = window.setInterval("scrollText('down', 12)", 40);
			})
		.bind('mouseup', function() {
			window.clearInterval(x);
			if (mhover==true) {
				x = window.setInterval("scrollText('down', 2)", 40);
				}
			})
		.bind('mouseout', function() {
			window.clearInterval(x);
			mhover = false;
			});

	$('#scrlUp')
		.bind('mouseover', function() {
			mhover = true;
			x = window.setInterval("scrollText('up', 4)", 40);
			})
		.bind('mousedown', function() {
			window.clearInterval(x);
			x = window.setInterval("scrollText('up', 12)", 40);
			})
		.bind('mouseup', function() {
			window.clearInterval(x);
			if (mhover==true) {
				x = window.setInterval("scrollText('up', 4)", 40);
				}
			})
		.bind('mouseout', function() {
			window.clearInterval(x);
			mhover = false;
			});
	$('#scrlDwnPress')
		.bind('mouseover', function() {
			mhover = true;
                      //  alert("aa");
			x = window.setInterval("scrollTextPress('Dwn', 2)", 40);
			})
		.bind('mousedown', function() {
			window.clearInterval(x);
			x = window.setInterval("scrollTextPress('Dwn', 12)", 40);
			})
		.bind('mouseup', function() {
			window.clearInterval(x);
			if (mhover==true) {
				x = window.setInterval("scrollTextPress('Dwn', 2)", 40);
				}
			})
		.bind('mouseout', function() {
			window.clearInterval(x);
			mhover = false;
			});
/*DOMINO Aggiunta per implementazione dimnamica sezione press*/
	$('#scrlUpPress')
		.bind('mouseover', function() {
			mhover = true;
			x = window.setInterval("scrollTextPress('Up', 4)", 40);
			})
		.bind('mousedown', function() {
			window.clearInterval(x);
			x = window.setInterval("scrollTextPress('Up', 12)", 40);
			})
		.bind('mouseup', function() {
			window.clearInterval(x);
			if (mhover==true) {
				x = window.setInterval("scrollTextPress('Up', 4)", 40);
				}
			})
		.bind('mouseout', function() {
			window.clearInterval(x);
			mhover = false;
			});
/*DOMINO Fine Aggiunta per implementazione dimnamica sezione press*/
	if($('.body_tour').is('div')) {
		gallery.init();
		}

	if($('.body_history').is('div')) {
		$('ul.history').width( $('ul.history li').length * 390 + parseInt($('ul.history').css('paddingLeft')) + + parseInt($('ul.history').css('paddingRight')) );
		$('#histContainer').jScrollPane_hor();
		}
    if($('#view_reserved_code').length){
        codice_reserved.init();
    }

});


var codice_reserved={
            url : null,
            init : function(){
                    var container='<div id="container_cer" class="jqmWindow"><iframe id="jqmContent_cer" src="" allowtransparency="yes" frameborder="0"  scrolling="auto"></iframe><div id="jqmTitle_cer" style="height:50px;"><a href="#" class="jqmClose">CLOSE</a></div></div>';
                    $('body').append(container);
                    $('#container_cer').css({display:'none'}).jqm({target: '#jqmContent_cer',onShow:codice_reserved.loadPage});
                    $('#view_reserved_code a').click(function(e){codice_reserved.showModal($(this).attr('href'));e.preventDefault()});

                },
            showModal : function(url){
                    $lt_pos=$('#layout').position();
                    w_win=$(window).width();
                    el_left=Math.round((w_win-330)/2);
                    $('#container_cer').css({left:$lt_pos.left+435,top:$lt_pos.top+120});
                    codice_reserved.url=url;
                    $(window).resize(function(){
                        $lt_pos=$('#layout').position();
                        w_win=$(window).width();
                        el_left=Math.round((w_win-330)/2);
                        $('#container_cer').css({left:$lt_pos.left+435,top:$lt_pos.top+120});
                    });
                    $('#container_cer').jqmShow();
                },
            loadPage : function(hash){
                    var $trigger = $(hash.t);
                    var $modal = $(hash.w);
                    var $modalContent = $("iframe", $modal);
                    $modalContent.html('').attr('src', codice_reserved.url);
                    $('#container_cer').show();
                }
            }



function scrollText(direction, speed) {
	var mt = parseInt($('#text').css("marginTop"));
	if(direction=='down') {
		mt -= speed;
		if($('#textWrapper').height() + -parseInt($('#text').css("marginTop")) < $('#text').outerHeight()) {
			$('#text').css({marginTop : mt});
		}
	} else if (direction=='up') {
		mt += speed;
		if(mt<0) {
			$('#text').css({marginTop : mt});
		}
	}
}
/*DOMINO Aggiunta per implementazione dimnamica sezione press*/
function scrollTextPress(direction, speed) {

        var text=$('#scrl'+direction+'Press').attr('class');
	var mt = parseInt($('#'+text+' .content').css("marginTop"));

	if(direction=='Dwn') {

		mt -= speed;
		if($('#'+text+' .textWrapperPress').height() + -parseInt($('#'+text+' .content').css("marginTop")) < $('#'+text+' .content').outerHeight()) {
			$('#'+text+' .content').css({marginTop : mt});

		}

	} else if (direction=='Up') {
		mt += speed;
		if(mt<0) {
			$('#'+text+' .content').css({marginTop : mt});
		}
	}
}
/*DOMINO Fine Aggiunta per implementazione dimnamica sezione press*/
function scrollUp(speed) {
	var mt = parseInt($('#text').css("marginTop"));
	mt += speed;
	if(mt<0) {
		$('#text').css({marginTop : mt});
		}
	}


function setLayout(){
	var user_sh=$(window).height();
	var user_sw=$('body').innerWidth();
	var hFt = $('#footer').height();
	var wLt=$('#layout').width();
	var hLt=$('#layout').height();

	var newtop=(user_sh-608-hFt)/2 + (608-hLt);
	var newleft=(user_sw-wLt)/2;
	if(newtop<0){
		newtop=0;
	}
	$('#layout').css({left:newleft,top:newtop});
		if(user_sh<=hLt){
			$('#footer').css({top:hLt-26});
		}
		else{
			$('#footer').css({top:user_sh-26});
		}
	$('#layout').css({visibility:'visible'});
	$('#footer').css({visibility:'visible'});
	$(window).resize(function(){
		var user_sh=$(window).height();
		var user_sw=$('body').innerWidth();
		var wLt=$('#layout').width();
		var hLt=$('#layout').height();
		var newtop=(user_sh-hLt-hFt)/2;
		var newleft=(user_sw-wLt)/2;
		if(newtop<0){
			newtop=0;
		}
		$('#layout').css({left:newleft,top:newtop});
		if(user_sh<=hLt){
			$('#footer').css({top:hLt-26});
		}
		else{
			$('#footer').css({top:user_sh-26});
		}
	});
};

var gallery = {
	overlay : '<div class="th_overlay"></div>',
	init : function() {
		$('.thumbnails li a').each(function(){
			$(this).append(gallery.overlay);
		});
		$('.th_overlay').css({opacity:0.5});
		gallery.listenEvs();
	},

	listenEvs : function() {
		var thumbs = $('.thumbnails li a');
		thumbs.not( $('.active') ).hover(function() {
			$(this).addClass('hover');
			},
			function() {
				$(this).removeClass('hover');
				if(!$(this).hasClass('active')) {
					$(this).find('.th_overlay').show();
					}
			});

		thumbs.click(function() {
			thumbs.removeClass('active');
			$(this).addClass('active');
			});
	}

}

var menu = {
	status : null,
	inmenu : false,
	mpreviouslink: null,
	mlink : null,
	liv3on : null,
	init: function(){
		var lev1=$('#mcrpt>li>a');
		lev1.click(function(){
						menu.mlink=this;
						menu.show();
						menu.mpreviouslink=this;
					//	$(this).css({backgroundColor:'#000',color:'#fff'});
							});
		lev1.mouseover(function(){
						menu.inmenu=false;
						window.setTimeout("menu.check('l1')",1000);
						});

		var lev2=$('#mcrpt').find('li');
		lev2.hover(function(){
						menu.inmenu=true;
							},
					function(){
						menu.inmenu=false;
						window.setTimeout("menu.check('l2')",1000);
						});

		var lev3=lev2.find('li');
		lev3.mouseover(function(){
						menu.inmenu=true;
							});

		$('#mcrpt').find('li>ul>li>a').click(function(){
						if($(this).parent().find('ul').length>0){
							if(menu.liv3on!=null) {
								menu.liv3on.hide('fast');
								}
							$(this).parent().find('ul').show('slow');
							menu.liv3on=$(this).parent().find('ul');
							}
					});
		},
	check : function(el){
			if(menu.inmenu) return;
			if(!menu.inmenu) menu.hide();

		},
	show :  function(){
		// if statement reset level on click other 1 level link
		if(menu.mpreviouslink!=null){
				$(menu.mpreviouslink).parent().find('ul:eq(0)').hide();
				if(menu.liv3on!=null){
					menu.liv3on.hide();
					}
				}
			$(menu.mlink).parent().find('ul:eq(0)').show();
			menu.status='visible';
			},
	hide :  function(){
			$(menu.mlink).parent().find('ul:eq(0)').hide();
			menu.status='hidden';
			}

	}


$(document).ready(function() {

	if($('.scrollable').is('div')) {
		$('.scrollable').jScrollPane_vert({showArrows:true, scrollbarWidth: 13, arrowSize:13});
		}

	if($('#text').height() < $('#textWrapper').height() && $('#text').height()>0 ) {
		$('#scrollers').css({display:"none"});
//		alert("hide");
		}else{
		$('#scrollers').css({display:"block"});
//		alert("show");
		}
	$('p.image>img').css({ opacity: 0 });
	$('#language, #lingue>span').bind('mouseover', function() {
                MM_showHideLayers('lingue','','show');
                });     
        $('#lingue').bind('mouseout', function() {
                MM_showHideLayers('lingue','','hide');
                });             
        $('#storelink, #store3link>span').bind('mouseover', function() {
                MM_showHideLayers('store3link','','show');
                });     
        $('#store3link').bind('mouseout', function() {
                MM_showHideLayers('store3link','','hide');
                });

});

function MM_showHideLayers() { //v9.0
 var i,p,v,obj,args=MM_showHideLayers.arguments;
 for (i=0; i<(args.length-2); i+=3)
 with (document) if (getElementById &&
((obj=getElementById(args[i]))!=null)) { v=args[i+2];
   if (obj.style) { obj=obj.style;
v=(v=='show')?'block':(v=='hide')?'none':v; }
   obj.display=v; }
}


/********************** UTILS ************************/
//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,{}));
/*
 * jqModal - Minimalist Modaling with jQuery
 *   (http://dev.iceburg.net/jquery/jqModal/)
 *
 * Copyright (c) 2007,2008 Brice Burgess <bhb@iceburg.net>
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 * $Version: 03/01/2009 +r14
 */
(function($) {
$.fn.jqm=function(o){
var p={
overlay: 50,
overlayClass: 'jqmOverlay',
closeClass: 'jqmClose',
trigger: '.jqModal',
ajax: F,
ajaxText: '',
target: F,
modal: F,
toTop: F,
onShow: F,
onHide: F,
onLoad: F
};
return this.each(function(){if(this._jqm)return H[this._jqm].c=$.extend({},H[this._jqm].c,o);s++;this._jqm=s;
H[s]={c:$.extend(p,$.jqm.params,o),a:F,w:$(this).addClass('jqmID'+s),s:s};
if(p.trigger)$(this).jqmAddTrigger(p.trigger);
});};

$.fn.jqmAddClose=function(e){return hs(this,e,'jqmHide');};
$.fn.jqmAddTrigger=function(e){return hs(this,e,'jqmShow');};
$.fn.jqmShow=function(t){return this.each(function(){t=t||window.event;$.jqm.open(this._jqm,t);});};
$.fn.jqmHide=function(t){return this.each(function(){t=t||window.event;$.jqm.close(this._jqm,t)});};

$.jqm = {
hash:{},
open:function(s,t){var h=H[s],c=h.c,cc='.'+c.closeClass,z=(parseInt(h.w.css('z-index'))),z=(z>0)?z:3000,o=$('<div></div>').css({height:'100%',width:'100%',position:'fixed',left:0,top:0,'z-index':z-1,opacity:c.overlay/100});if(h.a)return F;h.t=t;h.a=true;h.w.css('z-index',z);
 if(c.modal) {if(!A[0])L('bind');A.push(s);}
 else if(c.overlay > 0)h.w.jqmAddClose(o);
 else o=F;

 h.o=(o)?o.addClass(c.overlayClass).prependTo('body'):F;
 if(ie6){$('html,body').css({height:'100%',width:'100%'});if(o){o=o.css({position:'absolute'})[0];for(var y in {Top:1,Left:1})o.style.setExpression(y.toLowerCase(),"(_=(document.documentElement.scroll"+y+" || document.body.scroll"+y+"))+'px'");}}

 if(c.ajax) {var r=c.target||h.w,u=c.ajax,r=(typeof r == 'string')?$(r,h.w):$(r),u=(u.substr(0,1) == '@')?$(t).attr(u.substring(1)):u;
  r.html(c.ajaxText).load(u,function(){if(c.onLoad)c.onLoad.call(this,h);if(cc)h.w.jqmAddClose($(cc,h.w));e(h);});}
 else if(cc)h.w.jqmAddClose($(cc,h.w));

 if(c.toTop&&h.o)h.w.before('<span id="jqmP'+h.w[0]._jqm+'"></span>').insertAfter(h.o);
 (c.onShow)?c.onShow(h):h.w.show();e(h);return F;
},
close:function(s){var h=H[s];if(!h.a)return F;h.a=F;
 if(A[0]){A.pop();if(!A[0])L('unbind');}
 if(h.c.toTop&&h.o)$('#jqmP'+h.w[0]._jqm).after(h.w).remove();
 if(h.c.onHide)h.c.onHide(h);else{h.w.hide();if(h.o)h.o.remove();} return F;
},
params:{}};
var s=0,H=$.jqm.hash,A=[],ie6=$.browser.msie&&($.browser.version == "6.0"),F=false,
i=$('<iframe src="javascript:false;document.write(\'\');" class="jqm"></iframe>').css({opacity:0}),
e=function(h){if(ie6)if(h.o)h.o.html('<p style="width:100%;height:100%"/>').prepend(i);else if(!$('iframe.jqm',h.w)[0])h.w.prepend(i); f(h);},
f=function(h){try{$(':input:visible',h.w)[0].focus();}catch(_){}},
L=function(t){$()[t]("keypress",m)[t]("keydown",m)[t]("mousedown",m);},
m=function(e){var h=H[A[A.length-1]],r=(!$(e.target).parents('.jqmID'+h.s)[0]);if(r)f(h);return !r;},
hs=function(w,t,c){return w.each(function(){var s=this._jqm;$(t).each(function() {
 if(!this[c]){this[c]=[];$(this).click(function(){for(var i in {jqmShow:1,jqmHide:1})for(var s in this[i])if(H[this[i][s]])H[this[i][s]].w[i](this);return F;});}this[c].push(s);});});};
})(jQuery);
