
(function($) {
	
    var imgList = [];
    $.extend({
        preload: function(imgArr, option) {
            var setting = $.extend({
                init: function(loaded, total) {},
                loaded: function(img, loaded, total) {},
                loaded_all: function(loaded, total) {}
            }, option);
            var total = imgArr.length;
            var loaded = 0;
            
            setting.init(0, total);
            for(var i in imgArr) {
                imgList.push($("<img />")
                    .attr("src", imgArr[i])
                    .load(function() {
                        loaded++;
                        setting.loaded(this, loaded, total);
                        if(loaded == total) {
                            setting.loaded_all(loaded, total);
                        }
                    })
                );
            }
            
        }
    });
})(jQuery);






//doc ready
$(window).load(function(){ 
//$("button[rel]"). overlay({mask: '#000', effect: 'apple'});
	isIE7 = /msie|MSIE 7/.test(navigator.userAgent);
	isIE8 = /msie|MSIE 8/.test(navigator.userAgent);
	isIE9 = /msie|MSIE 9/.test(navigator.userAgent);
	if(isIE7 || isIE8 || isIE9){
		imagesLoaded();				
	}else{
	
		//	var preloadArr = new Array();
		//  $(".door").each(function() {
		    //s = $(this).css('background-image').replace(/\.(.+)$/i, "_on.$1"); 
		    //preloadArr.push(s)
		//});
			//ie only 9 images possible!
		 $.preload([
		    "wp-content/themes/custom/images/door1_opt.png",
		    "wp-content/themes/custom/images/door2_png8.png",
		    "wp-content/themes/custom/images/door3_png8.png",
		    "wp-content/themes/custom/images/door4_png8.png",
		    "wp-content/themes/custom/images/door5_png8.png",
		    "wp-content/themes/custom/images/door6_png8.png",
		    "wp-content/themes/custom/images/door7_png8.png",
		    "wp-content/themes/custom/images/door8_png8.png",
		    "wp-content/themes/custom/images/door9_png8.png",
		    "wp-content/themes/custom/images/door10_sliced.png",
		    "wp-content/themes/custom/images/leinwand_0.png",
				     "wp-content/themes/custom/images/leinwand_0a.png"
		], {
		    init: function(loaded, total) {
		        //alert("Loaded: "+loaded+"/"+total);
		    },
		    loaded: function(img, loaded, total) {
		      // alert("Loaded: "+loaded+"/"+total);
		       // $("#full-screen").append(img);
		    },
		    loaded_all: function(loaded, total) {
		      // alert("Loaded: "+loaded+"/"+total+". Done!");
		      
		   
		        imagesLoaded();
		
				$.preload([
				    
				    "wp-content/themes/custom/images/leinwand_1.png",
				    "wp-content/themes/custom/images/leinwand_2.png",
				    "wp-content/themes/custom/images/leinwand_3.png",
				    "wp-content/themes/custom/images/leinwand_4.png",
				    "wp-content/themes/custom/images/leinwand_5.png",
				    "wp-content/themes/custom/images/leinwand_6.png",
				    "wp-content/themes/custom/images/leinwand_7.png",
				    "wp-content/themes/custom/images/leinwand_8.png"
				], {
				    init: function(loaded, total) {
				        //alert("Loaded: "+loaded+"/"+total);
				    },
				    loaded: function(img, loaded, total) {
				      // alert("Loaded: "+loaded+"/"+total);
				       // $("#full-screen").append(img);
				    },
				    loaded_all: function(loaded, total) {
				      // alert("Loaded: "+loaded+"/"+total+". Done!");
				      
				           
				    }
				});
		    }
		});
	}
	
function imagesLoaded(){
		
		 var img = new Image();
  		img.src = "wp-content/themes/custom/images/down_hover.png"
  		
  		 var img = new Image();
  		img.src = "wp-content/themes/custom/images/btn_up.png"
		
		 var img = new Image();
  		img.src = "wp-content/themes/custom/images/btn_up_hover.png"
  		
  		 var img = new Image();
  		img.src = "wp-content/themes/custom/images/pause_btn_hover.png"
		
		var img = new Image();
  		img.src = "wp-content/themes/custom/images/play_btn_hover.png"
        
        var img1 = new Image();
  		img1.src = "wp-content/themes/custom/images/up_hover.png"


		$('#wrapper').css("display", "block");
	    $('#container').css({
	      position:'absolute',
	      overflow: 'hidden',
		  top: '50%'
	    });
	    $('#container').css("height", " -710px");
		$('#container').css("margin-top", " -370px");
		var scrollHeight = $(".scroll-pane-inside").height();
		
	 //	alert(scrollHeight);
	 	
	 	
	 	$(".scroll-pane").css('height', '476px');
		if(scrollHeight > 480){
			
			$(".scroll-pane").css('overflow', 'auto');
			$('.scroll-pane').jScrollPane({showArrows: true, animateScroll: true});
			var pane = $('.scroll-pane');
		
			
		}
		
	$('.doorToClick').click(function() {
			
    
	
	
		
	
		$('#door1').css("display", "none"); 
		$('#door2').css("display", "block"); 
		counter = 2;
		function animateDoor(counter){	
		  $('#door'+counter+'').animate({
		  fontSize: "24px"
		  //  width: 'toggle',
		  //  height: 'toggle'
		  }, {
		    duration: 20,
		    complete: function() {
		   		$('#door'+counter+'').css("display", "none"); 
		   		counter++;	
				$('#door'+counter+'').css("display", "block"); 
		    	
		    	if(counter < 10){
		    		animateDoor(counter);
		    	}else{
		    		$('#door1').removeClass('doorToClick');
		    		$('#door1').unbind();
		    	}
		  
		    // alert('Handler');
		    }
		  });
		}
		animateDoor(counter);
			
	});	
	
	
	
	
	
	
	
}

function canvasDown() {
	if($('#canvas0a').css("display") != "none"){
		$('#canvas0a').css("display", "none"); 
		$('#canvas1').css("display", "none"); 
		$('#canvas2').css("display", "block"); 
		counter = 2;
		function animateCanvas(counter){	
		  $('#canvas'+counter+'').animate({
		  fontSize: "24px"
		  //  width: 'toggle',
		  //  height: 'toggle'
		  }, {
		    duration: 20,
		    complete: function() {
		   		$('#canvas'+counter+'').css("display", "none"); 
		   		counter++;	
				$('#canvas'+counter+'').css("display", "block"); 
		    	
		    	if(counter < 8){
		    		animateCanvas(counter);
		    	}else{
		    		$('#canvas0').removeClass('doorToClick');
		    		$('#canvas0').unbind();
		    		$('#btn_up').fadeIn();
		    		
		    	}
		  
		    // alert('Handler');
		    }
		  });
		}
		animateCanvas(counter);
			
	}	
}


	
//testing
/*
	$('#door1').css("display", "none"); 
		$('#door2').css("display", "block"); 
		counter = 2;
		function animateDoor(counter){	
		  $('#door'+counter+'').animate({
		  fontSize: "24px"
		  //  width: 'toggle',
		  //  height: 'toggle'
		  }, {
		    duration: 20,
		    complete: function() {
		   		$('#door'+counter+'').css("display", "none"); 
		   		counter++;	
				$('#door'+counter+'').css("display", "block"); 
		    	
		    	if(counter < 10){
		    		animateDoor(counter);
		    	}else{
		    		$('#door1').removeClass('doorToClick');
		    		$('#door1').unbind();
		    	}
		  
		    // alert('Handler');
		    }
		  });
		}
		animateDoor(counter);
		
	$('#canvas0a').css("display", "none"); 
		$('#canvas1').css("display", "none"); 
		$('#canvas2').css("display", "block"); 
		counter1 = 2;
		function animateCanvas(counter1){	
		  $('#canvas'+counter1+'').animate({
		  fontSize: "24px"
		  //  width: 'toggle',
		  //  height: 'toggle'
		  }, {
		    duration: 40,
		    complete: function() {
		   		$('#canvas'+counter1+'').css("display", "none"); 
		   		counter1++;	
				$('#canvas'+counter1+'').css("display", "block"); 
		    	
		    	if(counter1 < 8){
		    		animateCanvas(counter1);
		    	}else{
		    		$('#canvas0').removeClass('doorToClick');
		    		$('#canvas0').unbind();
		    		$('#btn_up').fadeIn();
		    	}
		  
		    // alert('Handler');
		    }
		  });
		}
		animateCanvas(counter);

		*/
		

//end testing
	
	$(".mainNaviItem").live("mouseenter", function(e) {
		if(!$(this).hasClass("active")){
			$(this).attr("heightToSave", $(this).find(".custom").css('height'));
			$(this).css("width", $(this).find(".custom").css('width'));
			var moveLeft = (parseInt($(this).find(".custom").css('width'))-parseInt($(this).find(".custom").css('width'))*0.95)/2;
			$(this).find(".custom").animate({
	    		height: "80px",
	    		width: "95%",
	    		marginTop: "18px",
	    		marginLeft: moveLeft
	   		}, 100 );
	   	}
	});
	
	
	$(".mainNaviItem").live("mouseleave", function(e) {
		if(!$(this).hasClass("active")){
			$(this).find(".custom").animate({
	    		width: $(this).css("width"),
	    		height: $(this).attr("heightToSave"),
	    		marginTop: "15px",
	   			marginLeft: "0px"
	  		}, 100 );
		}
	});
	
	
	
	
		
	$(".mainNaviItem").live("click", function(e) {
		
		e.preventDefault();
	//	$(this).find(".custom").stop().animate({marginTop: '6px'},{queue:false, duration:500, easing: 'easeInBack'}) 
		$("#subNavi").empty();
		$("#subNavi").show();
		
		
		//alert();
		if($(this).attr('ajaxlink1')){
			$("#navItem1_loadContainer").empty();
			$("#navItem1_loadContainer").load($(this).attr('ajaxlink1'),  function(e){
				
				$("#navItem1").hide();
				$("#subNavi").append($("#navItem1_loadContainer").html());
				
			
				$("#subNavi").find("#navItem1").fadeIn();
				
				//$("#subNavi").find("#navItem1").addClass("activeSub");
				//
				//PintoMark
				//$("#navItem1_Pin").fadeIn();
			});
		
			//$("#canvasContent").load($(this).attr('ajaxlink1')+"&content=1",  function(e){
				
			//	$("#canvasContent").hide();				
			//	$("#canvasContent").fadeIn();
			//});
			
			if($(this).attr('ajaxlink2')){
				$("#navItem2_loadContainer").empty();
			$("#navItem2_loadContainer").load($(this).attr('ajaxlink2'),  function(e){
				
				$("#navItem2").hide();
				$("#subNavi").append($("#navItem2_loadContainer").html());
				
				$("#subNavi").find("#navItem2").fadeIn();
				
			});
			
			}	
			if($(this).attr('ajaxlink3')){
				$("#navItem3_loadContainer").empty();
				$("#navItem3_loadContainer").load($(this).attr('ajaxlink3'),  function(e){
					
					$("#navItem3").hide();
					$("#subNavi").append($("#navItem3_loadContainer").html());
					
					$("#subNavi").find("#navItem3").fadeIn();
					
				});
			}
			if($(this).attr('ajaxlink4')){
				$("#navItem4_loadContainer").empty();
				$("#navItem4_loadContainer").load($(this).attr('ajaxlink4'),  function(e){
					
					$("#navItem4").hide();
					$("#subNavi").append($("#navItem4_loadContainer").html());
					
					$("#subNavi").find("#navItem4").fadeIn();
					
				});
			}	
			
			
		}	
		
		
		
		
			
		
		/*if($(this).attr('ajaxlink2')){
			$("#subNavi").load($(this).attr('ajaxlink2'),  function(e){
				
				$("#navItem2").hide();
				$("#navItem2").fadeIn();
			});
		}	
		if($(this).attr('ajaxlink3')){
			$("#subNavi").load($(this).attr('ajaxlink3'),  function(e){
				
				$("#navItem3").hide();
				$("#navItem3").fadeIn();
			});
		}	
		if($(this).attr('ajaxlink4')){
			$("#subNavi").load($(this).attr('ajaxlink4'),  function(e){
				
				$("#navItem4").hide();
				$("#navItem4").fadeIn();
			});
		}	
		mainNavSaveContainer
		*/
		
		
		if($("#mainNavSaveContainer").html()){
			//$(".active").empty();
			$(".active").replaceWith($("#mainNavSaveContainer").html());
			
			//$(".active").append($("#mainNavSaveContainer").html());
			$(".active").removeClass("active");
			$("#mainNavSaveContainer").empty();
		}
		
		$(this).addClass("active");
		//animation		
	
		
		$(this).find(".custom").stop().animate({
		  marginTop: '6px'  
		}, 500, 'easeInBack', function() {
			//
     		$(this).animate({
	    		width: $(this).parent().css("width"),
	    		height: $(this).parent().attr("heightToSave"),
	    		marginTop: "15px",
	   			marginLeft: "0px"
	   			
	  		}, 100 , function() {
	  			$("#mainNavSaveContainer").append(	$(".active").clone());
	  			$("#mainNavSaveContainer").hide();
	  			$(this).parent().fadeTo("fast",0.4);
	  		});
	  		
	  		//divToSave = ;
	  		
	  	//	$(".active").clone().prepend($("#mainNavSaveContainer"));
	  		//$("#mainNavSaveContainer").append(divToSave);
	  		//alert(divToSave.html());
	  		//$("#mainNavSaveContainer").append($(".active").html());
	  		//alert($(".active").html());
	  		
	  		
			//canvasDown();
    	});
  		
  		
  			
  	});
  	
  	
  	$("#btn_up").live("mouseenter", function(e) {
  		if(!$(this).hasClass("active")){
			//alert();
			$(this).parent().find("#canvas8 img").animate({
	    		height: "512px",
	    		width: "371px"
	   		}, 100 );
	   		
	   		$(this).animate({
	    		top: "554px"
	   		}, 100 );
	   	}
	});
		
		
	$("#btn_up").live("mouseleave", function(e) {
			//alert();
			$(this).parent().find("#canvas8 img").animate({
	    		height: "508px",
	    		width: "371px"
	   		}, 100 );
	   		
	   		$(this).animate({
	    		top: "550px"
	   		}, 100 );
	   	
	});
	
	$("#btn_up").live("click", function(e) {
		
			var activeSub = $(".activeSub").attr("id");
			$(".activeSub").remove();
			
			$("#subNavi").append($("#"+activeSub+"_loadContainer").html());
			$("#subNavi").find("#"+activeSub).show();

		
		$(this).addClass("active");
		
		$(this).fadeOut();
		cleanUp();
		$("#canvasContent").fadeOut();
		$(this).parent().find("#canvas8 img").stop().animate({
		  height: "520px",
	      width: "371px" 
		}, 200, 'linear', function() {
				// $("#subNavi").empty();
				//$('#canvas1').css("display", "none"); 
				//$('#canvas2').css("display", "block"); 
				counter = 8;
				function animateCanvas(counter){	
				  $('#canvas'+counter+'').animate({
				  fontSize: "24px"
				  //  width: 'toggle',
				  //  height: 'toggle'
				  }, {
				    duration: 20,
				    complete: function() {
				   		$('#canvas'+counter+'').css("display", "none"); 
				   		counter--;	
						$('#canvas'+counter+'').css("display", "block"); 
				    	
				    	if(counter > 0){
				    		animateCanvas(counter);
				    	}else{
				    		$('#canvas0a').css("display", "block");
				    		$('#canvas0').removeClass('doorToClick');
				    		$('#canvas0').unbind();
				    		$('#btn_up').removeClass("active");
				    	}
				  
				    // alert('Handler');
				    }
				  });
				}
				animateCanvas(counter);				
				
				
									
		    	
    	});

	
	});
	
	
	function cleanUp(){
		
			while($('#exposeMask').next().length){
		  			$('#exposeMask').next().remove();
		  			
		  		}
				$('#btnText_up').fadeOut();
			
		    $('#btnText_down').fadeOut();
		  		$("#canvasContent").fadeOut('fast', function() {
  				  $('#overlays').empty();
		  		$('#canvasContent').empty();
  			});
		  		
			$('#btnImg_next').fadeOut();
			
		    $('#btnImg_prev').fadeOut();
		    
		    cleanUpRemote();
	}
	
	function cleanUpRemote(){
			$("#play_btn").fadeOut();
		  		$("#play_btn").unbind('click');
		  		$("#pause_btn").fadeOut();
		  		$("#pause_btn").unbind('click');
		  		
		  		$('.imageGalleryThumb').unbind('click');
			
			$('#remote_next').fadeOut();
			$('#remote_next').unbind('click');
		    $('#remote_prev').fadeOut();
		    $('#remote_prev').unbind('click');
		    		      $('#remote_play').fadeOut();
		      $('#remote_play').unbind('click');
		    $('#remote_stop').fadeOut();
		     $('#remote_stop').unbind('click');
		    $('#OverlayGalleryBigRemote').fadeOut();
		    $('#OverlayGalleryBig').fadeOut();
		     $('#imageGalleryThumbBig').fadeOut();

	}
	
	
	$(".subNaviItem").live("click", function(e) {
	
		e.preventDefault();
		clearInterval(timer);
		if(!$(this).hasClass("activeSub")){
			canvasDown();
			//$(".activeSub").attr("style", "");
			//$(".activeSub").find("img").attr("style", "");
			//$(".activeSub").fadeIn();
			
			var activeSub = $(".activeSub").attr("id");
			$(".activeSub").remove();
			
			$("#subNavi").append($("#"+activeSub+"_loadContainer").html());
			$("#subNavi").find("#"+activeSub).show();
			
			//$(".activeSub").removeClass("activeSub");
			
				$("#play_btn").fadeOut();
  		$("#pause_btn").fadeOut();
  		$('#btnImg_next').fadeOut();
			
		    $('#btnImg_prev').fadeOut();
			
			
			
			$(this).addClass("activeSub");
			//$(this).fadeTo("fast",0.4);
			//$(".navItemPin").fadeOut();
			var hrefToload= $(this).attr('href')
			
			$("#canvasContent").fadeOut('fast', function() {
  				  $('#overlays').empty();
		  		$('#canvasContent').empty();

		  		cleanUpRemote();
		  		while($('#exposeMask').next().length){
		  			$('#exposeMask').next().remove();
		  			
		  		}
		  		
			  $("#canvasContent").load(hrefToload+"&content=1",  function(e){
					
					
					$("#canvasContent").show();
					
					if($(".imageGalleryThumb").length){
						mangeGallery();
					}else{
						mangeConent($(".post").height());
					}
					$("#canvasContent").hide();				
					$("#canvasContent").fadeIn();
				});
  			});


			
			$(this).find(".custom").stop().animate({
			  marginTop: '10px'  
			}, 500, 'easeInBack', function() {
				//$("#"+$(this).parent().attr("id")+"_Pin").fadeIn();
		 		$(this).animate({
		    		width: $(this).parent().attr("widthToSave"),
		    		height: $(this).parent().attr("heightToSave"),
		    		marginTop: "0px",
		   			marginLeft: "0px"
		   			
		  		}, 100 , function() {
		  				$(this).parent().fadeTo("fast",0.4);
		  			}
		  		);
				
			});
	
		}
	

  	});

	var timer; 
	var src_to_save;
function mangeGallery(){
	
  	//$(".imageGalleryThumb").hide();
	
  	var counter =0;
  	$(".imageGalleryThumb").each(function() {
  		$(this).find("img").css("left", (310 - $(this).find("img").width())/2);
  		$(this).find("img").css("top", (233 - $(this).find("img").height())/2);
  		$(this).hide();
  		$('#overlays').append('<div class="overlay" id="custom'+counter+'">'+
  			'<div class="remote_naviBar">'+ 
				'<div class="btnImg_nextBig"></div>'+
				'<div class="btnImg_prevBig"></div>'+
				'<div class="play_btnBig"></div>'+
				'<div class="pause_btnBig"></div>'+
				'<div class="close"></div>'+	 
			'</div>'+
  		'</div>');
  
  		//alert($(this).find("img").attr("heightCalc") );
  		if($(this).find("img").attr("heightCalc") > $(this).find("img").attr("widthCalc") ){
			var calcHight = $(this).find("img").attr("widthCalc") * (700 / $(this).find("img").attr("heightCalc"));
			$("#custom"+counter).css("width", calcHight);
			//alert();
			
		}else{
			$("#custom"+counter).css("width", 800);
		
		}
		
		$("#custom"+counter).css("background-image", "url("+$(this).find("img").attr("large_src")+")");
  		counter++;
  		
  	});
  	
  	//$('#overlays').append();

  	
  	$(".imageGalleryThumb:first").fadeIn();

  	
  	$(".imageGalleryThumb:first").addClass("first_imageGalleryThumb");
  	$(".imageGalleryThumb:first").addClass("active_imageGalleryThumb");


	$('#ImagesGalleryThumbDescription').hide();	
	
 	$('#ImagesGalleryThumbDescription').html($(".active_imageGalleryThumb").find("img").attr("description"));
  	$('#ImagesGalleryThumbDescription').fadeIn();	
  	
  	//$(".imageGalleryThumb:last").fadeIn();
  	$(".imageGalleryThumb:last").addClass("last_imageGalleryThumb");
  	
  	
  	if($(".imageGalleryThumb").length > 1){
  		$("#play_btn").fadeIn();
  	}
  
  	$('#play_btn').click(function() {
  		playSlide();
  	});
  	
  //	
  	
  	$('.play_btnBig').click(function() {
  		
  		playSlide();
  	
  	});
  	
  	
  	
  	function playSlide(){
  		$(".play_btnBig").fadeOut();
  		$(".pause_btnBig").fadeIn();
  		$("#play_btn").hide();
  		$("#pause_btn").fadeIn();
  	//	alert();
  		slideSwitchNext();
  		clearInterval(timer);
		timer = setInterval(function() {
			if($("#play_btn").css("display")== "none"){
     			slideSwitchNext(); 
     		}
     		
		}, 2000);
  	}
  	
	$('#pause_btn').click(function() {
		pauseSlide();
	});
	
	$('.pause_btnBig').click(function() {
		pauseSlide();
		
	});
	
	function pauseSlide(){
		clearInterval(timer);
		if($(".imageGalleryThumb").length > 1){
  			$("#play_btn").show();
  		}
		
  		$("#pause_btn").hide();
  		//alert();
  		$(".play_btnBig").show();
  		$(".pause_btnBig").hide();
	
	}

  	$("img[rel]").overlay({onBeforeLoad: function() { beforeLoadOverlay(); }, onLoad: function() { openOverlay(); }, onBeforeClose: function() { onBeforeCloseOverlay(); },  onClose: function() { closeOverlay(); }, mask: '#000', effect: 'apple'}); 
  	function slideSwitchNext() {
 			var $active = $('.active_imageGalleryThumb');
 			
     		$active.removeClass('active_imageGalleryThumb');
   
     		if($active.hasClass('last_imageGalleryThumb')){
     			$next= $('.first_imageGalleryThumb');
     			
     		}else{
     			var $next =  $active.next();

     		}
     		
     		$next.addClass('active_imageGalleryThumb');

			$active.fadeOut();
		
     		
     		$next.fadeIn();
     		$('#ImagesGalleryThumbDescription').hide();	
	
 			$('#ImagesGalleryThumbDescription').html($(".active_imageGalleryThumb").find("img").attr("description"));
 			
 			
 			
 			
 			
 			
 			//$("#custom").attr("style", "");
 			
 			//$("#exposeMask").next().attr("src", $(".active_imageGalleryThumb").find("img").attr("large_src"));
 			//$("#exposeMask").next().attr("style", "");
 			
 			
 			//$("#exposeMask").next().remove();
 			//$("#custom0").css("background-image", "url("+$(".active_imageGalleryThumb").find("img").attr("large_src")+")");
  			$('#ImagesGalleryThumbDescription').fadeIn();	
			slideSwitchBig();
     		
     		//alert((310 - $next.find("img").width())/2);
     		//
     		
     		
	}	
	
	
  	function slideSwitchPrev() {
 			var $active = $('.active_imageGalleryThumb');
 			
     		$active.removeClass('active_imageGalleryThumb');
   
     		if($active.hasClass('first_imageGalleryThumb')){
     			$next= $('.last_imageGalleryThumb');
     			
     		}else{
     			var $next =  $active.prev();

     		}
     		
     		$next.addClass('active_imageGalleryThumb');

			$active.hide();
		
     		
     		$next.fadeIn();
     		$('#ImagesGalleryThumbDescription').hide();	
	
 			$('#ImagesGalleryThumbDescription').html($(".active_imageGalleryThumb").find("img").attr("description"));
 			$("#custom").css("background-image", "url("+$(".active_imageGalleryThumb").find("img").attr("large_src")+")");
  			$('#ImagesGalleryThumbDescription').fadeIn();	

     		
     		slideSwitchBig();
     		
     		
	}	
	
	
  	function slideSwitchBig() {	

		if($('#exposeMask').css("display") == "block"){
			$('#OverlayGalleryBigContainer').empty();
			//$('#exposeMask').next().hide();
			elementToCheck = $('#exposeMask').next();
			while(elementToCheck.length){
				elementToCheck.hide();
				if(elementToCheck.next().length){
					
					elementToCheck=elementToCheck.next();
				}else{
					break;
				}
			}
			
			$('#exposeMask').next().clone().appendTo('#OverlayGalleryBigContainer');
 			
			
	var targetImage = $('#OverlayGalleryBigContainer').find('img');


 				
 				
 				originalImage = $(".active_imageGalleryThumb").find("img");
		  		targetImage.attr("src", originalImage.attr("large_src") );
		  		
		  		var offsetTop =setOffset();
		  		var naviBarTop = offsetTop-30-parseInt($(".remote_naviBar").parent().css("top"));
		  		$(".remote_naviBar").css("top", naviBarTop);
		  		targetImage.css("top", offsetTop);
		  		targetImage.css("left", "50%");
		  		targetImage.css("position", "fixed");
		  		
		  		var calcHight = originalImage.attr("widthCalc") * (700 / originalImage.attr("heightCalc"));
		  		
		  		
				if(originalImage.attr("heightCalc") > originalImage.attr("widthCalc") ){
		  			targetImage.css("width", calcHight);
		  			targetImage.css("margin-left", (-(calcHight)/2));
		  			//targetImage.css("margin-left", ((800-calcHight)/2));
		  		}else{
					targetImage.css("width", 800);
					//targetImage.css("margin-left", 0);
					targetImage.css("margin-left", -400);
				}		  			
				
				targetImage.fadeIn();	

		  	}else{
		  		//$('#exposeMask').next().hide();
		  		//while($('#exposeMask').next().length){
		  		//	$('#exposeMask').next().remove();
		  			
		  		//}
		  	
		  	}
				
	}	
			
			if($(".imageGalleryThumb").length > 1){
  				$('#btnImg_next').fadeIn();
			
		    	$('#btnImg_prev').fadeIn();
  			}
				
			
		   // $('#btnImg_prev').addClass("notClickable");
		    //$('#btnImg_next').removeClass("notClickable");
		    
		    
		    
		    $('#btnImg_next').click(function() {
				nextSlide();
		    });
		    
		     $('.btnImg_nextBig').click(function() {
		     	
				nextSlide();
				
		    });
		    
		    function nextSlide(){
		    	//clearSlideShow
		    	clearInterval(timer);
				$("#play_btn").fadeIn();
  				$("#pause_btn").fadeOut();
  				$(".play_btnBig").fadeIn();
  				$(".pause_btnBig").fadeOut();
		    	//end clearSlideShow
		    	slideSwitchNext();		    
		    }
		    
		    $('#btnImg_prev').click(function() {
				prevSlide();
				
		    });
		    
		      $('.btnImg_prevBig').click(function() {
				prevSlide();
			
		    });
		    
		    function prevSlide(){
		    	//clearSlideShow
		    	clearInterval(timer);
				$("#play_btn").fadeIn();
  				$("#pause_btn").fadeOut();
  				$(".play_btnBig").fadeIn();
  				$(".pause_btnBig").fadeOut();

		    	//end clearSlideShow
		    	slideSwitchPrev();		    	
		    }
		    
		    $('#remote_next').fadeIn();
		    $('#remote_prev').fadeIn();
		     $('#remote_play').fadeIn();
		    $('#remote_stop').fadeIn();
		    
		    if($(".imageGalleryThumb").length > 1){
  			 	$('#OverlayGalleryBigRemote').fadeIn();
  			}
		   
	 	    
		  
 		$('.imageGalleryThumb').click(function() {
		    src_to_save= $(this).find("img").attr('src');
		 	 src_to_save= $(this).find("img").attr('src_to_save', src_to_save);

		   // $('#OverlayGalleryBigRemote').css("z-index", "99999999999999");
		 	pauseSlide(); 
	    });

		    
		      $('#remote_play').click(function() {
		 	 playSlide();
		   
		    });	
		    
		  $('#remote_stop').click(function() {
		  	pauseSlide();
		   
		    });	
		    
		     $('#remote_next').click(function() {
		   		nextSlide();	
		   		

		    });
		    
		  $('#remote_prev').click(function() {
		   					prevSlide();
		   	

		    });		  
		    
		    function closeOverlay(){
		      	$('#OverlayGalleryBigContainer').empty();
		   // 	$('#exposeMask').next().hide();
			//	while($('#exposeMask').next().next().length){
					
		  	//		$('#exposeMask').next().remove();
		  			
		  	//	}
				 var elementToCheck = $('#exposeMask').next();
				 while(elementToCheck.length){
					elementToCheck.css("opacity", "1");
					elementToCheck.css("-ms-filter:", "'progid:DXImageTransform.Microsoft.Alpha(opacity=100)'");
					elementToCheck.css("filter", "alpha(opacity=100)");
					if(elementToCheck.next().length){
						
						elementToCheck=elementToCheck.next();
					}else{
						break;
					}
				}

			};  
		
			
			
			
			 function onBeforeCloseOverlay(){
			 if($('#OverlayGalleryBigContainer').find("img").length){
			 	$('#OverlayGalleryBigContainer').find("img").fadeOut();
			 	var elementToCheck = $('#exposeMask').next();
				 while(elementToCheck.length){
					elementToCheck.css("opacity", "0");
					elementToCheck.css("-ms-filter:", "'progid:DXImageTransform.Microsoft.Alpha(opacity=0)'");
					elementToCheck.css("filter", "alpha(opacity=0)");
					   
					
					if(elementToCheck.next().length){
						
						elementToCheck=elementToCheck.next();
					}else{
						break;
					}
				}
			 }
			
			 
			 
		      	
		   // 	$('#exposeMask').next().hide();
			//	while($('#exposeMask').next().next().length){
					
		  	//		$('#exposeMask').next().remove();
		  			
		  	//	}
				pauseSlide(); 
			};  

			function  beforeLoadOverlay(){
				$(".remote_naviBar").hide();				
							}
			
			function setOffset(){
				var offset = $('#wrapper').offset();
				var offsetTop=50;
				if(offset.top > 50){
					offsetTop=offset.top;
				} 
				return offsetTop;

			}
			
			function openOverlay(){
				var offsetTop =setOffset();
				
				
				
				
				var elementToCheck = $('#exposeMask').next();
				while(elementToCheck.length){
					//elementToCheck.css("top", );	
					
					elementToCheck.animate({"top": offsetTop}, "fast");				
					if(elementToCheck.next().length){
						
						elementToCheck=elementToCheck.next();
					}else{
						break;
					}
				}
				var naviBarTop = offsetTop-30-parseInt($(".remote_naviBar").parent().css("top"));
				//alert(naviBarTop);
				$(".remote_naviBar").css("top", naviBarTop);
				//$(".remote_naviBar").animate({"top": naviBarTop}, "fast");
				$(".remote_naviBar").fadeIn();
				
				if($(".imageGalleryThumb").length < 2){
					
					$('.btnImg_prevBig').hide();
					$('.btnImg_nextBig').hide(); 
					$('.play_btnBig').hide();
				}
				
				
				//alert (naviBarTop);
				//$(".remote_naviBar").css("top", naviBarTop);
				//$(".remote_naviBar").hide();
				
				//$(".remote_naviBar").fadeIn();
				//$(".remote_naviBar").animate({"top": naviBarTop}, "fast");	
				//alert($('#exposeMask').next().css("display"));
				//$('#exposeMask').next().css("display", "block");
				//alert($('#exposeMask').next().attr("style", ""));
				//alert($('#exposeMask').next().css("display"));
			}
}
  	
   	
 			

  	
  	
  	function mangeConent(scrollHeight){
  		//toDo);
  	
  		
  		
		
		if(scrollHeight > 420){
		//alert(scrollHeight%420);
			var totalScrollSteps  = (scrollHeight-scrollHeight%420)/420+1;
			$(".post").attr("scrollSteps", 0);
			$(".post").attr("totalScrollSteps", totalScrollSteps);
			$(".post").css('height', '420px');
			
			
			$('#btnText_up').fadeIn();
			
		    $('#btnText_down').fadeIn();
		    $('#btnText_down').addClass("notClickable");
		    $('#btnText_up').removeClass("notClickable");
		}
	 	
	 	//height: 420px;
	 	//
		//if(scrollHeight > 480){
  	
  	}
  	
  	$('#btnText_up').live("click", function(e) {
  		if(!$(this).hasClass("notClickable")){
  		
	  		var actualScrollStep=parseInt($(".post").attr("scrollSteps"));
	  		var actualScrollPosition=(actualScrollStep+1)*-420;
	  		actualScrollStep++;
	  		$(".post").attr("scrollSteps", actualScrollStep);
	  		$('#btnText_down').removeClass("notClickable");
	  		if(actualScrollStep == parseInt($(".post").attr("totalScrollSteps"))-1){
	  			  	$(this).addClass("notClickable");
	  			  
	  		}
	  		
	  		$(".post").stop().animate({
				  top: actualScrollPosition+'px'  
				}, 500, 'easeInBack', function() {
									
				}
			);
		}
  	});
  	
  	$('#btnText_down').live("click", function(e) {
  		if(!$(this).hasClass("notClickable")){
  		
	  		var actualScrollStep=parseInt($(".post").attr("scrollSteps"));
	  		var actualScrollPosition=actualScrollStep*-420+420;
	  		$('#btnText_up').removeClass("notClickable");
	  		if(actualScrollStep == 1){
	  			  	$(this).addClass("notClickable");
	  			  	
	  		}
	  		actualScrollStep--;
	  		$(".post").attr("scrollSteps", actualScrollStep);
	  		$(".post").stop().animate({
				  top: actualScrollPosition+'px'  
				}, 500, 'easeInBack', function() {
									
				}
			);
		}
  	});
  	
  	$(".subNaviItem").live("mouseenter", function(e) {
		if(!$(this).hasClass("activeSub")){
			var heightToSave = parseInt($(this).find(".custom").css('height'));
			var widthToSave = parseInt($(this).find(".custom").css('width'));
			$(this).attr("heightToSave", heightToSave);
			$(this).attr("widthToSave", widthToSave);
			var heigthNew = heightToSave*0.95+"px"
				var widthNew = widthToSave*0.95+"px"
			
			//$(this).css("width", $(this).find(".custom").css('width'));
			var moveLeft = (widthToSave-widthToSave*0.95)/2+"px";
			var moveTop = (heightToSave-heightToSave*0.95)/2+"px";
			$(this).find(".custom").animate({
	    		height: heigthNew,
	    		width: widthNew,
	    		marginTop: moveTop,
	    		marginLeft: moveLeft
	   		}, 100 );
	   	}
	});
	
	
	$(".subNaviItem").live("mouseleave", function(e) {
		if(!$(this).hasClass("activeSub")){
			$(this).find(".custom").animate({
	    		width: $(this).attr("widthToSave"),
	    		height: $(this).attr("heightToSave"),
	    		marginTop: "0px",
	   			marginLeft: "0px"
	  		}, 100 );
		}
	});
  	
  	
});





