//mosne fecit
//www.mosne.it

/* init */

$(document).ready(function(){


     var img0 = new Image();
     var img1 = new Image();
     var img2 = new Image();
     var img3 = new Image();
     var img4 = new Image();
     var img5 = new Image();
     var img6 = new Image();
     var img7 = new Image();
     var img8 = new Image();
     var img9 = new Image();
     var img10 = new Image();
     var img11 = new Image();
     	
	
	 $(img0).attr("src", "http://www.dw9.it/themes/dw9/images/bprev.png").load();
	 $(img1).attr("src", "http://www.dw9.it/themes/dw9/images/bnext.png").load();
	 $(img2).attr("src", "http://www.dw9.it/themes/dw9/images/bplus.png").load();
	 $(img3).attr("src", "http://www.dw9.it/themes/dw9/images/b3d.png").load();
	 $(img4).attr("src", "http://www.dw9.it/themes/dw9/images/dw9-hd.png").load();
	 $(img5).attr("src", "http://www.dw9.it/themes/dw9/images/3da.png").load();
	 $(img6).attr("src", "http://www.dw9.it/themes/dw9/images/anim.gif").load();
	 $(img7).attr("src", "http://www.dw9.it/themes/dw9/images/3dbd.png").load();
	 $(img9).attr("src", "http://www.dw9.it/themes/dw9/images/3db.png").load();
	 $(img10).attr("src","http://www.dw9.it/themes/dw9/images/3dad.png").load();
	 $(img11).attr("src","http://www.dw9.it/themes/dw9/images/b3dd.png").load();

						   
/* fit screen */
/*
   if (top.frames.length!=0)
   top.location=self.document.location;
   //self.moveTo(0,0)
   var thex= ((screen.availWidth - 996)/2);
   var they= ((screen.availHeight - 700)/2);
   self.moveTo(thex,they)
   self.resizeTo(1200,700);
	
	*/
	
	if (location.hash){
		
			var hs = location.hash;
			var who = "a[@href='"+hs+"']"
	       	var go4it = $(who);
		 
		 
			$("#albumsubnav a.selected").removeClass("selected");
		   
		    $(go4it).addClass("selected");
			expander($(go4it));
		
		}
	
	var options = {
        resizeLgImages:     false,
		displayNav:         true,
		assetURL:			"/dw9/themes/dw9/",
		handleLgImages:		"drag",
		overlayColor:		"#000",
		width:				1200,
		overlayOpacity:		0.85,
        handleUnsupported:  'remove',
	    skipSetup: true,
		keysClose:          ['c', 27] // c or esc
    };
	
   Shadowbox.init(options);
	
   function onBefore() { 
   
   		var total =  +$(this).parent().find("img").length;
   		var  idx =  (1+$("a.hide").index(this));
   
   		$('#dida').html(this.title + " | <b> " + idx +"/"+total+"</b>");
   } 

	
	function expander(avalue){
		
		
		var dove = $("#output");
		var cosa = $(avalue).attr("rel");
		
		$('#status').css({display:"block"});
	    $(dove).hide();
		
		$(dove).load(cosa,function (){  
				
					$(".pics").cycle({ 
    				fx:     'fade', 
    				speed:  550, 
    				timeout: 0, 
    				next:   '#next', 
    				prev:   '#prev' ,
					before:  onBefore 
					
				});
				
				$('#zoom').click(function(){
	
					$('a.hide:visible').trigger('click');

				});

					
					if (window.XMLHttpRequest) {}else{
   						
						$(dove).pngFix();
						
						
				}
					
					Shadowbox.setup($('a.hide'),{
									
									skipSetup: true, 
									resizeLgImages:     false,
									displayNav:         true,
									assetURL:			"/themes/dw9/",
									handleLgImages:		"drag"
									  
									  });
					    
					setTimeout(
					function () {
				
					$('#status').css({display:"none"});
					$(dove).show();
					$('#corpo').jScrollPane();
			    	
					}, 500);
				
				}
			);
		
	};
	
	
/* buttons */	
	
	$("#albumsubnav a").click(
		function () {
	       	
		    $("#albumsubnav a.selected").removeClass("selected");
		   
		    $(this).addClass("selected");
			expander($(this));
		
		 });
		 
		 
	$(".pics").cycle({ 
    				fx:     'fade', 
    				speed:  550, 
    				timeout: 0, 
    				next:   '#next', 
    				prev:   '#prev' ,
					before:  onBefore 
					
				});
					
				$('#zoom').click(function(){
	
					$('a.hide:visible').trigger('click');

				});
			
			
			
			if (window.XMLHttpRequest) {}else{
   						
						$(document).pngFix();
						
						
				}
			
			
 }); // end of global scope
