//SUBVERSION:
//1line instal script to oLayer. Not works on safari without allert.

//function makeLibrary(jsname,pos) {
//	var th = document.getElementsByTagName(pos)[0];
//	var s = document.createElement('script');
//	s.setAttribute('type','text/javascript');
//	s.setAttribute('src',jsname);
//	th.appendChild(s);
//	return true;
//}
//
//makeLibrary("../oLayer/Resources/jquery.livequery.min.js","head");
//makeLibrary("../oLayer/Resources/jquery.mousewheel.js","head");
//makeLibrary("../oLayer/Resources/jScrollPane.min.js","head");

var BoxOriginHeight;
var BoxOriginWidht;
var TopPosition;
var LeftPosition;
var SizeBox;

var scStatus = 0;

function LoadoLayer() {	
	$('body').append($("<div id='BG'></div><div id='LoaderContainer'><div id='Loading'><div id='iL'><div class='bar1'></div><div class='bar2'></div><div class='bar3'></div><div class='bar4'></div><div class='bar5'></div><div class='bar6'></div><div class='bar7'></div><div class='bar8'></div></div></div></div>"));
	
	$('#BG').fadeIn("fast");
	
	Size = 0.5;
	
	$('body').append($('<div id="OverlayContainer" class="Loading"><div class="Shadow" id="ShadowUp"></div><div id="ScrollContainer"><div class="oLayerClose Close"></div><div id="oInner" class="scroll-pane">Loading</div></div><div class="Shadow" id="ShadowDown"></div></div>'));
	
	
	
	$("#OverlayContainer").fadeOut("slow");
	
	
	PositionOverlay('LoaderContainer');
	rotate();
	
	PositionOverlay('OverlayContainer');
	
	$('.Shadow').hide();
	$("#oInner").addClass("Closed");	
	
		
	$('a.oLayerIMG').append("<div class='Zoom'></div>");
	
	
	$('a.oLayerIMG').livequery(function(){ 
	    // use the helper function hover to bind a mouseover and mouseout event 
	        $(this).append("<div class='Zoom'></div>");
	    }, function() {
	    }); 
	
		
	oLayerIMG();
	oLayerTEXT();
	oLayerSITE();
	oLayerFRAME();
};

function PositionOverlay(elem) {
	$("#LoaderContainer ").addClass("Fix");
	OverlayContainer = document.getElementById(elem);
	
	BoxOriginHeight = OverlayContainer.offsetHeight;
	BoxOriginWidht = OverlayContainer.offsetWidth;
	
	TopPosition = (window.innerHeight-BoxOriginHeight)/2;
	OverlayContainer.style.top = TopPosition + "px";
	
	LeftPosition = (window.innerWidth-BoxOriginWidht)/2;
    OverlayContainer.style.left = LeftPosition + "px";
    
    window.addEventListener('resize',PositionOverlay,false);
    
    resizeScrollPane();
};

var count = 0;
var Size;
function rotate() {
  //var Elem = 'iL';
  //var t = document.getElementById(Elem);
  var c = document.getElementById('iL');
  c.style.MozTransform = 'scale('+Size+') rotate('+count+'deg)';
  c.style.WebkitTransform = 'scale('+Size+') rotate('+count+'deg)';
  
  var b = document.getElementById('LoaderContainer');
  b.style.MozTransform = 'scale('+Size+')';
  b.style.WebkitTransform = 'scale('+Size+')';
  
  
  if (count==360) { count = 0 }
  count+=45;
  window.setTimeout(rotate, 100);
};
	

function ResizeOverlay() {
	$("#OverlayContainer").fadeIn("fast");
	$('#OverlayContainer').animate({
		    width: window.innerWidth + "px",
		    height: window.innerHeight + "px",
		    top: 0,
		    left: 0
		  }, 500, function() {
		    	$("#OverlayContainer").addClass("Expand");
		    	$('#oInner').show();
		    	$('.Shadow').show();
		  });
	 scStatus = 1;
	
};

function CloseOverlay() {
	$("#OverlayContainer").removeClass("Expand");
	$('.Shadow').hide();	
	$('#OverlayContainer').animate({
	    height: BoxOriginHeight + "px",
	    width: BoxOriginWidht + "px",
	    top: TopPosition + "px",
	    left: LeftPosition + "px"
	  }, 300, function() {
	    $("#OverlayContainer").fadeOut("slow");
	  });
	  
	 $('#oInner').empty();
	 
	 scStatus = 0;
};

this.oLayerTEXT = function(){
	$('a.oLayerTEXT')
		.livequery('click', function(event) {
			if (scStatus=="0") {
					var TEXThref =  this.href;
					$("#ScrollContainer").css({'margin-top' : '100%'}).show();
					$("#LoaderContainer ").fadeIn("slow");
					
					PositionOverlay('LoaderContainer');
					$('#oInner').hide();
					$("#OverlayContainer").fadeIn("slow");
					
					$("#oInner").load(TEXThref + ' #InnerContent', function(response, status, xhr) {
					  if (status == "success") {
					    reinitialiseScrollPane();
					    $("#LoaderContainer ").fadeOut("slow");
					    $("#oInner").removeClass("Closed");
					    ResizeOverlay();
					    setTimeout('ScrollUp("#ScrollContainer");',500);
					  }
					  
					  if (status == "error") {
					    fileNotFound(TEXThref);	
					  }
					});
				}
				else {
					var TEXThref =  this.href;
					ScrollClose("#ScrollContainer");
					$("#LoaderContainer ").fadeIn("slow");
					setTimeout( function()
					      {
					      	 $("#ScrollContainer").css({"margin-top" : "100%"}).show();
					      	 
					      	 
					      	 $("#oInner").load(TEXThref + ' #InnerContent', function(response, status, xhr) {
					      	   if (status == "success") {
									reinitialiseScrollPane();
									$("#LoaderContainer ").fadeOut("slow");
					      	   }
					      	   
					      	   if (status == "error") {
					      	     fileNotFound(TEXThref);	
					      	   }
					      	 });
  					         ScrollUp("#ScrollContainer");
			 		      }, 1000);
			  	}; 
				return false; 
			});
	$('.oLayerClose').click(function() {
		  ScrollClose('#ScrollContainer');
		  setTimeout('CloseOverlay();',700);		  
	}); 	
};


function resizeScrollPane() {
	var oInnerWidth = window.innerWidth* 0.8 ;
	var oInnerHeight = window.innerHeight* 0.8 ;
	
	$("#oInner")
	  			.css("width", oInnerWidth + "px")
	  			.css("height", oInnerHeight + "px")
};

function ScrollUp(Selector) {
	 $(Selector).animate({
	     marginTop: "6%"
	   }, 500);
	   
	 $(Selector).animate({
	     marginTop: "4%"
	   }, 200);
};

function ScrollClose(Selector) {
 $(Selector).animate({
     marginTop: "-100%"
   }, 900, function() {
   	   $(Selector).hide();
   });
};

var imgOWidth;
var imgOHeight;
var imgTop;
var IMGView;
var leftPositonIMG;
var rightPositionIMG;

var imgWidth;
var imgHeight;
var img;
var position;
var IMGhref;
var IMGcapt;
var Current;
var That;

this.oLayerIMG = function(){
   		 $('a.oLayerIMG') 
   		     .livequery('click', function(event) { 
   		         Current = $(this);
   		         //IMAGE PREOADING
   		         IMGhref =  this.href;
   		         IMGcapt =  this.title;
   		         
   		         That = $(this);
   		         
   		         imgWidth = $(this).width();
   		         imgHeight = $(this).height();
   		         
   		         img = $(this);
   		         position = img.offset();
   		    
   		        $("#LoaderContainer ").removeClass("Fix");
   		        $('#LoaderContainer')
   		        			.css("top", position.top + ((imgHeight/2)-60) + "px")
   		          			.css("left", position.left + ((imgWidth/2)-60) + "px")
   		          
   		           
   		        $(".Zoom", this).fadeOut("fast",function(){
   		       		$(this).addClass("Loading");
   		       		
   		       	});
   		       	
   		       	$(".Zoom", this).fadeIn("fast");
   		       	$("#LoaderContainer").fadeIn("slow");
   		        
   		        PreloadIMG();
   		        return false;
   		     });
   		     
   		 
   		 $("a.oLayerIMG") 
   		     .livequery(function(){ 
   		     // use the helper function hover to bind a mouseover and mouseout event 
   		         $(this) 
   		             .hover(function() { 
   		                 	imgWidth = $(this).width();
   		                 	imgHeight = $(this).height();
   		                 	$(".Zoom")
   		                 	  			.css("width", imgWidth + "px")
   		                 	  			.css("height", imgHeight + "px");
   		                 	$(".Zoom", this).fadeIn("fast");
   		             }, function() { 
   		                 $(".Zoom:not(.Loading)", this).fadeOut("fast");
   		             });
   		     }, function() { 
   		         // unbind the mouseover and mouseout events 
   		         $(this) 
   		             .unbind('mouseover') 
   		             .unbind('mouseout'); 
   		     }); 
};

function PreloadIMG(){
	var img = new Image();
	 $(img)
	    .load(function () {	    		
	    	$("body").append("<div id='IMGC'></div><div id='CloseIMG' class='Close' onclick='CloseIMG();'></div><div id='IMGView'><img onclick='CloseIMG();' class='Previes' src='"+ IMGhref +"' alt='Image preview' /><span id='TitleIMG'>"+ IMGcapt +"</span></div>");
	    	$("#IMGView").hide();
	    	
	    	
	    	$("#IMGC").fadeIn("slow");
	    	//$("#IMGView").fadeIn("slow");
	    	
	    	$("#IMGView").fadeIn("slow",function(){
	    	   $(Current).addClass("Hided");
	    	});
	    	
	    	
	    	$("#IMGView")
	    				.css("top", position.top + "px")
	    	  			.css("left", position.left + "px")
	    	  			.css("width", imgWidth + "px")
	    	  			.css("height", imgHeight + "px")
	    	
	    	IMGView = document.getElementById("IMGView");
	    	
	    	imgOHeight = IMGView.offsetHeight;
	    	imgOWidth = IMGView.offsetWidth;
	    	
	    	imgTop = (window.innerHeight-imgOHeight)/8;
	    	imgLeft = (window.innerWidth-imgOWidth)/8;
	    	
	    	var CurrentScrollPosition = document.body.scrollTop;
	    	
	    	
	    	
	    	
	    		
	    	$(this).removeClass("Loading");
	    				$("#LoaderContainer").hide();
	    				
	    		    	$('#IMGView').animate({
	    		    		  width: "100%",
	    		    		  height: window.innerHeight*0.8 + "px",
	    		    		  left: 0,
	    		    		  top: CurrentScrollPosition+((window.innerHeight*0.2)/2) + "px"
	    		    		}, 500, function() {
	    		    			var imgB = $('#IMGView img');
	    		    			var imgBposition = imgB.offset();
	    		    			var imBw = $("#CloseIMG").width();
	    		    		
	    		    			$("#CloseIMG").fadeIn("slow");
	    		    			$("#TitleIMG").fadeIn("slow");
	    	
	    		    			$("#CloseIMG").css("top", imgBposition.top-imBw/2 + "px").css("left", imgBposition.left-imBw/2 + "px")
	    		    		});
	    	
	    		    	
	    })
	    
	    .error(function () {
	      setTimeout('$("#LoaderContainer").hide();',200);
	      $(".Zoom", That).append($("<h1 class='Error'><strong>oLayer</strong> got an error: File not found.<span>X</span></h1>"));
	    })
	    
	    .attr('src', IMGhref);
};
 
 function CloseIMG(){
 		$("#CloseIMG").hide();
 		$("#TitleIMG").hide("slow");
 		
 		$("#IMGC").fadeOut(400, function(){
 		   $("#IMGC").remove();
 		 });
 		 
 	   	$('#IMGView').animate({
 	   		  width: imgWidth + "px",
 	   		  height: imgHeight + "px",
 	   		  left: position.left + "px",
 	   		  top: position.top + 5 + "px"
 	   		}, 500, function() {
 	   			$("#IMGView").remove();
 	   		  	$(Current).removeClass("Hided");
 	   		});	
 	   		
 	   		$(".Zoom").removeClass("Loading");
 	   		$(".Zoom").hide();
  };

var FRAMEhref;
this.oLayerFRAME = function(){
				
			$("a.oLayerFRAME").livequery('click', function(event) {
				
					$("#OverlayContainer").append("<div id='FrameContainer'></div>");
					
										
					FRAMEhref =  this.href;
					$('#FrameContainer').prepend("<div onclick='closeFRAME();' class='Close Frame'></div><iframe src='"+FRAMEhref+"?id=Embed' id='VideoFrame'/>");
					
					$("#LoaderContainer ").fadeOut("slow");
					
					
					
					ResizeOverlay(); 
					setTimeout('ScrollUp("#FrameContainer");',500);
					
				 
					return false; 
				});

			
//			$("a.oLayerFRAME").click(function(){	
//				$("#OverlayContainer").append("<div onclick='closeFRAME();' id='FrameContainer'></div>");
//				
//				
//				FRAMEhref =  this.href;
//				$('#FrameContainer').prepend("<iframe src='"+FRAMEhref+"?id=Embed' id='VideoFrame'/>");
//				
//				$("#LoaderContainer ").fadeOut("slow");
//				
//				
//				
//				ResizeOverlay(); 
//				setTimeout('ScrollUp("#FrameContainer");',500);
//				  
//				
//			});
			
};

function closeFRAME() {
	ScrollClose('#FrameContainer');
	setTimeout('$("#FrameContainer").remove(); CloseOverlay();',1000);
	
};

function fileNotFound(File) {
	$('#oInner').html('<div class="NotFound"><h1><span>Ooops! </span>Valami nagyon rosszra fordult...</h1><span class="ICO"></span><p><span><strong>oLayer got Error 404: </strong>' + File +'</span>A keresett fÃ¡jl nem talÃ¡lhatÃ³ szerverÃ¼nkÃ¶n. </p></div>');
	
	reinitialiseScrollPane();
	$("#LoaderContainer ").fadeOut("slow");
	$("#oInner").removeClass("Closed");
	ResizeOverlay();
	setTimeout('ScrollUp("#ScrollContainer");',500);
};

function fileNotFound(File) {
	$('#oInner').html('<div class="NotFound"><h1><span>Ooops! </span>Valami nagyon rosszra fordult...</h1><span class="ICO"></span><p><span><strong>oLayer got Error 404: </strong>' + File +'</span>A keresett fÃ¡jl nem talÃ¡lhatÃ³ szerverÃ¼nkÃ¶n. </p></div>');
	
	reinitialiseScrollPane();
	$("#LoaderContainer ").fadeOut("slow");
	$("#oInner").removeClass("Closed");
	ResizeOverlay();
	setTimeout('ScrollUp("#ScrollContainer");',500);
};

var SITEhref;
this.oLayerSITE = function(){
			$("a.oLayerSITE").livequery('click', function(event) {
				SITEhref =  this.href;
				$("#LoaderContainer ").fadeIn("slow");
				PositionOverlay('LoaderContainer');
				
				
				//mÃ¡rcsak hozzÃ¡ kell adnia a css-t, Ã©s a monitort felbontÃ¡st beÃ¡llÃ­tani marginnak... kÃ©sz. :D
				//Ez az animÃ¡ciÃ³ oldalra vÃ¡ltja a tartalmat....
				
				$("body").addClass("UnderAnim");
				//$("body.UnderAnim").css("width", window.innerWidth + "px")
				
				$('#InnerContent').animate({
				  	     marginLeft: '-' + window.innerWidth*2 + 'px'
				  	  }, 500, function() {
				  	  	$('#Content').load(SITEhref + ' #InnerContent', function(response, status, xhr) {
				  	    						  if (status == "success") {
				  	    						  	$("#InnerContent").css("margin-left", window.innerWidth*2 + 'px')
				  	    						   	$("#LoaderContainer").fadeOut("slow");
//				  	    						   	$('#InnerContent').animate({
//				  	    						   	    marginLeft: '0'
//				  	    						   	    }, 500);
//				  	    						   	    
				  	    						   	    
				  	    						   	    $('#InnerContent').animate({
				  	    						   	      	     marginLeft: '0'
				  	    						   	      	  }, 500, function() {
				  	    						   	      	  $("body").removeClass("UnderAnim");
				  	    						   	    });
				  	    						   	    
				  	    						   	    
				  	    						   	$('#OverlayContainer').fadeOut("slow");
				  	    						  }
				  	    						  
				  	    						  if (status == "error") {
				  	    						    fileNotFound(TEXThref);	
				  	    						  }
				  	    						 });
				  	   
				  	    	
  				  	  });
  				  	 
  				  	 
  				  	 $('#InnerContent').fadeOut(500);
				  	  
				  	  
					  
//				$("#Content").slideUp("slow",function(){
//					$('#Content').load(SITEhref + ' #InnerContent', function(response, status, xhr) {
//					  if (status == "success") {
//					   	$("#LoaderContainer").fadeOut("slow");
//					   	$("#Content").slideDown("slow");
//					   	$('#OverlayContainer').fadeOut("slow");
//					  }
//					  
//					  if (status == "error") {
//					    fileNotFound(TEXThref);	
//					  }
//					 });
//					
//				});
				return false;
			});
			
};

$(function()
	{
		$('#oInner').jScrollPane();

		reinitialiseScrollPane = function()
		{
			$('#oInner').jScrollPane();
  		}
  		
	});
	
	
$(window).load(function(){
	
	$('#BG').fadeOut("slow");
	$("#LoaderContainer").fadeOut("slow",function(){
	   Size = 0.5;
  	 });
  	
  	// setTimeout("JustShow('Sign.php');",1000);
  	
  	
});

function JustShow(File) {
	$("#ScrollContainer").css({'margin-top' : '100%'}).show();
	$("#LoaderContainer ").fadeIn("slow");
	
	PositionOverlay('LoaderContainer');
	$('#oInner').hide();
	$("#OverlayContainer").fadeIn("slow");
	
	$("#oInner").load(File + ' #InnerContent', function(response, status, xhr) {
	  if (status == "success") {
	    reinitialiseScrollPane();
	    $("#LoaderContainer ").fadeOut("slow");
	    $("#oInner").removeClass("Closed");
	    ResizeOverlay();
	    setTimeout('ScrollUp("#ScrollContainer");',500);
	  }
	  
	  if (status == "error") {
	    fileNotFound(TEXThref);	
	  }
	 });
};

