$(function()
	{
		// this initialises the demo scollpanes on the page.
		$('#BlogFull').jScrollPane();

		reinitialiseScrollPane = function()
		{
			$('#BlogFull').jScrollPane();
  		}
	});

function loadContent(elementSelector, sourceURL) {
	$(""+elementSelector+"").load("Blog/"+sourceURL+"", reinitialiseScrollPane)
}

function loadService(elementSelector, sourceURL) {
	$(""+elementSelector+"").load("Files/"+sourceURL+"", reinitialiseScrollPane);
	
	$("#readerContainer").fadeIn("slow");
}

function fitToText()
	{
		if (this.scrollHeight>this.clientHeight)
			{
				this.style.height=(this.scrollHeight+20)+"px";
			}
		else
			{
				this.style.height="10px";
				this.style.height=(this.scrollHeight+20)+"px";
			}
	}

			
			
//CONTROLLER BUTTONS
$(document).ready(function(){

		$(".Play").hover(function(){
			$(this).fadeTo("fast", 1.0); // This should set the opacity to 100% on hover
		},function(){
				$(this).fadeTo("fast", 0.5); // This should set the opacity back to 60% on mouseout
		});	
		
		$('#readerContainer').hide();
		$("#LoaderContainer").fadeOut("slow");	
				
		
		$("div.MP3Controler").toggle(
		  function () {
		    $("section#MP3").fadeIn("slow");
		  },
		  function () {
		    $("section#MP3").fadeOut("slow");
		  }
		);
		
		$(".ShowAbout").click(function(){
			loadService('#BlogFull', 'AboutMe.php');
		}); 
		
		$(".More").click(function(){
				$("#readerContainer").fadeIn("slow");
		});
		
		$(".CloseBlog").click(function(){
				$("#readerContainer").fadeOut("slow");
		});
		
		$("a.Summary.All").click(function () {
		    $("article#BlogSummary").show();
		    $("article#article3").hide();
		    $("a.Scroll").show();
		    $("a.All").hide();
		});

		$("a.Summary.Scroll").click(function () {
			$("article#BlogSummary").hide();
			  $("article#article3").show();
			  $("a.Scroll").hide();
			  $("a.All").show();
		});
		
		$("div.SecondNav li").hover(function(){
			$(this).animate({
				borderWidth: 20	  //CHANGE BORDER
			}, 200);
		},function(){
			$(this).animate({
				borderWidth: 0   //CHANGE BORDER
			}, 200);
			});
			
		$("div.Thrd.AR").hover(function(){
			$(this).fadeTo("fast", 1.0); // This should set the opacity to 100% on hover
		},function(){
				$(this).fadeTo("fast", 0.5); // This should set the opacity back to 60% on mouseout
		});
		
}); 




$(document).ready(function(){
	$('.Clients.SlideDown').hover(function(){
		$(".Cover", this).stop().animate({top:'136px'},{queue:false,duration:200});
	}, function() {
		$(".Cover", this).stop().animate({top:'190px'},{queue:false,duration:200});
	});
});


$(document).ready(function(){
	/* This code is executed after the DOM has been completely loaded */

	$('nav a, a.up, div.GoUP').click(function(e){

		// If a link has been clicked, scroll the page to the link's hash target:

		$.scrollTo( this.hash || 0, 700);
		e.preventDefault();
	});

});

// execute your scripts when the DOM is ready. this is mostly a good habit
$(function() {

	// initialize scrollable
	$(".scrollable").scrollable();
});

	//Load URL
	var isPlaying;   
	function openURL(urlString)
	{
	   $("#LoaderContainer").fadeIn("slow");
	   $('body').append("<div id='Video'><div class='CloseVideo'>Bezárás</div><div>");
	   $('#Video').prepend("<iframe src='http://"+urlString+"' id='VideoFrame'/>");
	   
	   $('#Video').fadeIn(300);
	   
	   $("div.CloseVideo").hover(function(){
	   	 $(this).animate({ 
	   	     right: "5px"
	   	   }, 500 );
	   },function(){
	   	$(this).animate({ 
	   	    right: "-105px"
	   	  }, 500 );
	   });

	   
	   
	   $("div.CloseVideo").click(function(){
	   		$('#Video, #VideoFrame').fadeOut('slow',function ()
	   		      {
	   		        $('#VideoFrame').remove();
	   		      });
	   		
	   		if (isPlaying == true) {
	   		  playAudio();
	   		};      
	   		$("#LoaderContainer").fadeOut("slow");
	   });
	   
	   pauseAudio();
	 }
	 
	 //MP3 PLAYER
	var audio;
	var play;
	var pause;
	var VolN;
	var VolClass;
	var volume;
	var volumeDisplay;  
	
	var bodyLoaded = function(){ 
	
		audio = document.getElementById("audio");
		Play = document.getElementById("Play");
		Pause = document.getElementById("Pause");
		volumeDisplay = document.getElementById("volume_display");
		
		playAudio();
		setVolume('0.4', '3');
		
		Play.addEventListener("click", function(){
		  if (audio.paused) {
		    playAudio();
		  } else {
		    pauseAudio();
		    isPlaying = false;
		  }
		}, true);
		
		$("#controlers").hover(function(){
			 $(this).animate({ 
			     width: "400px"
			   }, 500 );
		},function(){
			$(this).animate({ 
			    width: "50px"
			  }, 500 );
		});			
	}
	
	function playAudio(){
	      audio.play();
	      $('#Play').addClass('play');
	      $('#Play').removeClass('pause');
	      $('#MPLoad').fadeIn('slow');
	      isPlaying = true;
	    }
	
	function pauseAudio(){
	  audio.pause();
	  $('#Play').addClass('pause');
	  $('#Play').removeClass('play');
	  $('#MPLoad').fadeOut('slow');
	}
	
	function setVolume(VolN, VolClass) {
		audio.volume = (VolN);
		
		var volNum = (VolClass);
		for(var i=0; i<6; i++) {
		  if (i < volNum) {
		    volumeDisplay.children[i].style.borderColor = "#fff";
		  } else {
		    volumeDisplay.children[i].style.borderColor = "#555";
		  }
		}
	}
	
	function updateVolumeDisplay(){
	  var volNum = VolClass;
	  for(var i=0; i<6; i++) {
	    if (i < volNum) {
	      volumeDisplay.children[i].style.borderColor = "#fff";
	    } else {
	      volumeDisplay.children[i].style.borderColor = "#555";
	    }
	  }
	}
	
		
	function openMatyas()
	{
		window.open('http://www.matyaspribojszki.com/'); 
		return false;
	}
