$(document).ready(function()
{
	$('img').imagemonitor(
	{
		'init' : function()
		{
		},
		'onLoad' : function(loadedImage, totalImage)
		{
			var barwidth = (loadedImage/totalImage)*400;
			var loadedpercent = Math.floor(((loadedImage/totalImage)*100))+'%';
			$('.bar_text').html('Loading '+loadedpercent);
			$('.loading_bar').css('width', barwidth);
		},
		'onComplete' : function(loadedImage)
		{			
			setTimeout( function() {
				$('#preloader').fadeOut(500);				
			}, 1000 );
			
			setTimeout( function() {
				$('.hidden_content').fadeIn(1000, function() {
				
					// Initialize the scrollbar
					mCustomScrollbars();
				
				});
			}, 2000 );
		}
	});
	
	/*
	// Initialised above
	$(window).load(function() {
		mCustomScrollbars();
	});
	*/

	function mCustomScrollbars(){
		$("#scroll-bar").mCustomScrollbar("horizontal",500,"easeOutCirc",1,"fixed","yes","yes",60); 
	}

	/* function to fix the -10000 pixel limit of jquery.animate */
	$.fx.prototype.cur = function(){
		if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) {
		  return this.elem[ this.prop ];
		}
		var r = parseFloat( jQuery.css( this.elem, this.prop ) );
		return typeof r == 'undefined' ? 0 : r;
	}

	/* function to load new content dynamically */
	function LoadNewContent(id,file){
		$("#"+id+" #scroller .content").load(file,function(){
			mCustomScrollbars();
		});
	}
	
});

$(document).ready(function() {

	// FancyBox
	$("a[rel=fancybox-gallery]").fancybox({
		'padding': 0,
		'overlayColor' : '#000',
		'overlayOpacity' : 0.6
	});
	$("#btn-portfolio").fancybox({
		'padding': 50,
		'overlayColor' : '#000',
		'overlayOpacity' : 0.6
	});
	$("#btn-video").fancybox({
		'padding': 50,
		'overlayColor' : '#000',
		'overlayOpacity' : 0.6,
		'transitionIn' : 'none',
		'transitionOut' : 'none'
	});
		
	//IMAGE/THUMB SLIDER

	$(".thumb-hover").hide();
	$(".thumb-overlay").hide();
	$("#logo-large").delay(1000).animate({left: -220}, 150);
				
	$(".thumb-bottom").hover(function() {
		$(this).children(".thumb-hover").stop().show().css({ "bottom" : "-70px" }).animate({bottom : 0}, 150);
		$(this).children(".thumb-image").stop().show().css({ "top" : "0" }).animate({height : 120, top: 0, width: 330}, 150);
		$(this).children(".thumb-overlay").stop().fadeTo(150, 0.6);
		$(this).children(".thumb-link").show();
	}
	,function() {
		$(this).children(".thumb-hover").stop().animate({bottom : -70}, 150);
		$(this).children(".thumb-image").stop().show().animate({height : 190, top: 0, width: 330}, 150);
		$(this).children(".thumb-overlay").stop().fadeTo(400, 0);
		$(this).children(".thumb-link").hide();
	});
	
	$(".thumb-main").hover(function() {
		$(this).children(".thumb-overlay").stop().fadeTo(150, 0.6);
		$(this).children(".thumb-view").show();
		$(this).children(".thumb-play").show();
		$(this).children(".thumb-enlarge").show();
	}
	,function() {
		$(this).children(".thumb-overlay").stop().fadeTo(400, 0);
		$(this).children(".thumb-view").hide();
		$(this).children(".thumb-play").hide();
		$(this).children(".thumb-enlarge").hide();
	});
	
	$("#logo-small").hover(function() {
		$("#logo-large").stop().show().animate({left: 40}, 150);

	}
	,function() {
		$("#logo-large").stop().show().animate({left: -220}, 150);
	});
					
});

//NAV / SLIDING PANEL
$(document).ready(function(){

	$(".close").click(function(){
		$("#panel-about, #panel-journal, #panel-contact, #panel-portfolio").slideUp(200);
		$("#nav-about, #nav-journal, #nav-contact").removeClass("active");
	});	

	$("#nav-portfolio, #nav-portfolio-on").click(function(){
		$("#panel-about, #panel-journal, #panel-contact").slideUp(200);
		$("#nav-about, #nav-journal, #nav-contact").removeClass("active");
		$("#panel-portfolio").delay(250).slideToggle(150);
		$(this).toggleClass("active"); return false;		
	});
	
	$("#nav-journal, #nav-journal-on").click(function(){
		$("#panel-portfolio, #panel-about, #panel-contact").slideUp(200);
		$("#nav-portfolio, #nav-about, #nav-contact").removeClass("active");
		$("#panel-journal").delay(250).slideToggle(150);
		$(this).toggleClass("active"); return false;		
	});
	
	$("#nav-about, #nav-about-on").click(function(){
		$("#panel-portfolio, #panel-journal, #panel-contact").slideUp(200);
		$("#nav-portfolio, #nav-journal, #nav-contact").removeClass("active");
		$("#panel-about").delay(250).slideToggle(150);
		$(this).toggleClass("active"); return false;		
	});
	
	$("#nav-contact, #nav-contact-on").click(function(){
		$("#panel-portfolio, #panel-journal, #panel-about").slideUp(200);
		$("#nav-portfolio, #nav-journal, #nav-about").removeClass("active");
		$("#panel-contact").delay(250).slideToggle(150);
		$(this).toggleClass("active"); return false;		
	});
	 
});
