var Zydo = {
    collectionDetail : function(name) {
        Zydo.overlayPos(true);
		Zydo.dialogDisplayed = true;
		
		window.setTimeout(function() {
		    $('#collections-page').hide();
            $('#detail-area').load('/Collections.aspx/Detail/' + name + '?v=' + Math.random(), function(data){
	            $("#collection-detail").css("opacity", 0).show().fadeTo(500, 1);
                window.setTimeout(function() {
	                $(".collection-detail-gallery").css("opacity", 0).show().fadeTo(200, 1);
                    $('ul.collection-detail-gallery').galleria({
		                history   : false, 
		                clickNext : true, 
		                insert    : '#main_image',
		                onImage   : function(image, caption, thumb) { 
			                // fade in the image & caption
			                image.css('display','none').fadeIn(1000);
			                caption.css('display','none').fadeIn(1000);
            				
			                // fetch the thumbnail container
			                var _li = thumb.parents('li');
            				
			                // fade out inactive thumbnail
			                _li.siblings().children('img.selected').fadeTo(500,0.3);
            				
			                // fade in active thumbnail
			                thumb.fadeTo('fast',1).addClass('selected');
            				
			                // add a title for the clickable image
			                image.attr('title', '>>');
		                },
		                onThumb : function(thumb) { // thumbnail effects goes here
            				
			                // fetch the thumbnail container
			                var _li = thumb.parents('li');
            				
			                // if thumbnail is active, fade all the way.
			                var _fadeTo = _li.is('.active') ? '1' : '0.3';
            				
			                // fade in the thumbnail when finnished loading
			                thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
            				
			                // hover effects
			                thumb.hover(
				                function() { thumb.fadeTo('fast',1); },
				                function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
			                )
		                }
	                });
	            }, 500);
            });
        }, 300);
    },
    closePressDetail : function() {
        $('#press-overlay, #press-detail, #press-detail-close').hide();
    },
    overlayPos : function(init){
		var left = 0;
		var top = 0;
		var overlayWidth = $(window).width();
		var overlayHeight = $(document).height();
		var winHeight =  $(window).height();
	
		if ($.browser.msie && parseInt($.browser.version) < 7) { //if IE6
			$("#overlay,#press-overlay").css(
			{
			    position: "absolute",
			    width: overlayWidth, 
			    height: overlayHeight - 116, 
			    zIndex: 10
			}).show();
		}
		else { //other browsers
			$("#overlay,#press-overlay").css(
			{
			    position: "absolute",
			    width: overlayWidth, 
			    height: winHeight - 116, 
			    zIndex: 10
			}).show();
		}
		if (init) {
			$("#overlay,#press-overlay").css("opacity", 0);
			$("#overlay,#press-overlay").fadeTo(500, 0.7);
		}
	},
	reposition : function(){ //calculate the position
		var left = 0;
		var top = 0;
		var winWidth = $(window).width();
		var winHeight =  $(window).height();
		var dialogHeight = $("#jDialogContainer").children().height();
		var dialogWidth = $("#jDialogContainer").children().width();
	
		if ($.browser.msie) {
			left = document.body.scrollLeft || document.documentElement.scrollLeft;
			top = document.body.scrollTop || document.documentElement.scrollTop;
		}
		else {
			left = window.pageXOffset;
			top = window.pageYOffset;
		}
	
		var topOff = top + winHeight/2 - dialogHeight/2; //offset for IE6
		var	leftOff = left + winWidth/2 - dialogWidth/2; //offset for IE6
		var topFixed = topOff - top;
		var	leftFixed = leftOff - left;
		
		if ($.browser.msie && parseInt($.browser.version) < 7) { // IE6
			//IE 6 fix
			$("select").hide();
			//IE 6 fix
			$("#jDialogContainer select").show(); 
			//IE6 doesn't support fixed position
			$("#jDialogContainer").children().css({
													  top: topOff,
													  left: leftOff,
													  position: "absolute",
													  zIndex: (opts.index+1)
												  }).show(); 
		}
		else{	// firefox and IE7
			$("#jDialogContainer").children().css({
													  top: topFixed, 
													  left: leftFixed, 
													  position: "fixed", 
													  zIndex: (opts.index+1)
												  }).show();
		}
	},
	closeDetail:function() {
	    Zydo.dialogDisplayed=false;
	    $("#overlay, #collection-detail").fadeTo(200, 0).hide();
		    $('#collections-page').show();
	    
	},
	moveLeft : function() {
	    var left = $('.galleria').position().left;
	    $('.galleria').animate({left: (left - 96) + 'px'}); 
	},
	moveRight : function() {
	    var left = $('.galleria').position().left;
	    $('.galleria').animate({left: (left + 96) + 'px'}); 
	},
    init : function() {
        $('.overtop').fadeTo(0, 0.5);
        $('#boutiques-page li img').hover(
            function(){$(this).fadeTo(400, 1);},
            function(){$(this).fadeTo(400, 0.5);}
        ).fadeTo(0, 0.5);
        
        if ($('#boutiques-family').length > 0) {  
            $('#boutiques-family').hover(
                function() {
                    $('#boutiques-page').css('background-position', '50% -1089px');
                },
                function() {
                    $('#boutiques-page').css('background-position', '50% -20px');
                }
            );
            
            $('#boutiques-family').click(function() {
                GB_showCenter('Zydo', '/Boutiques.aspx/Zydo', 470, 900);
            });
        }
        if ($('#design-page').length > 0) {  
            swfobject.embedSWF("/design.swf?v=2.7", "design-movie", "650", "500", "9.0.0", true,
                {
                    wmode: "transparent", 
                    allowScriptAccess:'always'
                }
            ); 
        }
        
        if ($('#collections-page').length > 0) {    
		    $(window).scroll(function(){
			    if(Zydo.dialogDisplayed) {
				    Zydo.overlayPos();
				    if (Zydo.currentPos)
					    Zydo.reposition();
			    }
		    });
		     
		    $(window).resize(function(){
			    if (Zydo.dialogDisplayed) {
				    Zydo.overlayPos();
				    if (Zydo.currentPos)
					    Zydo.reposition();
			    }
		    });
            swfobject.embedSWF("/carousel.swf?v=2.6", "collections", "1100", "500", "9.0.0", true,
                {
                    xmlfile:"default.xml?v=2.9", 
                    loaderColor:"#dce0df"
                },
                {
                    wmode: "transparent", 
                    allowScriptAccess:'always'
                }
            ); 
        }
        
    }
};
$(Zydo.init);