/*
 *
 *	jQuery Site-Wide Functions
 *	Copyright (c) 2010 Layered Pixels <themeforest@layeredpixels.com>
 *
*/

/* Fade out all sections */
function SectionFadeOut() {
    $("#home, #about, #expertise, #works, #contacts, #jobs, .socialnetwork").fadeOut(); // If you add, modify or delete sections, you have to modify this function to fit your changes.
}

/* Fade IN the default navigation area */
function DefaultNavIn() { 
    $("#nav-default").fadeIn();
    $("#nav-default").animate({
		right: 675
    });
}

/* Fade OUT the default navigation area */
function DefaultNavOut() {
    $("#nav-default").fadeOut();
}

/* Resize the default navigation to a smaller one */
function DefaultNavResizeSmall() {
    $("#nav-default").animate({
		width: 170,
		fontSize: 10,
		left:780
    });
}

/* Resize the default navigation to the original size */
function DefaultNavResizeLarge() { 
    $("#nav-default").animate({
		left:675,
		width: 275,
		fontSize: "1em"
    });
}

/* Pop-in the gallery and give a new class to the #main-content div */ 
function GalleryIn() {
    $(".main-content").addClass("gallery");
}

/* Pop-out the gallery and remove it's new class */
function GalleryOut() {
	$(".main-content").removeClass("gallery");
}

/* Pop-out the gallery fullscreen wrapper */
function GalleryWrapperOut() {
	$(".fullsize-wrapper").fadeOut();
}

/* Pop-in the Social Network area */
function SocialNetworkIn() {
	$(".socialnetwork").fadeIn();
	$(".socialnetwork").animate({
		bottom:80
    });
}

/* Pop-out the Social Network area */
function SocialNetworkOut() {
	$(".socialnetwork").animate({
		bottom:0
    });
	$(".socialnetwork").fadeOut();
}

/* Load the jScrollPane Plugin with a little hack to make it work properly on this template */
function LoadScrollPanel() {
	var $scrollsection = $("#about, #works, #expertise, #jobs"); // Add sections here that use the jScrollPane Plugin
	$scrollsection.show(); 
	$('.scroll').jScrollPane(); 
	$scrollsection.hide(); 
}

/* Load the Fullsize Plugin */
function LoadFullSize() {
	$("#list img").fullsize();
}

/* Load a bunch of site-wide various effects */
function LoadVariousEffects() {
	
	/* Social Network Icons Hover Effect */
	$(".socialnetwork ul li img").hover(
		function(){
			$(this).animate({ marginTop: -5, easing: "swing"}, 200 );
		},
		function(){
			$(this).animate({ marginTop: 0, easing: "swing"}, 200 );
		}
	);
}

/* Image Loading Effect */

/* Var */
var i = 0; 
var int=0; 

function ImageLoading() {
	var images = $('.load').length;
	if (i >= images) {
		clearInterval(int);
		delete int;
	}
	$('.load:hidden').eq(0).fadeIn(200);
	i++;
}

function LoadImageLoading() {
	$('.load').hide()
	setInterval("ImageLoading(i)",500);
}

/* When we refresh the page, load the section we are already in or called via URL */
function LocationHash() {
	var hash = window.location.hash;
	hash = hash.replace(/^#/, '');
	switch (hash) {
	    case 'about':
	        $("." + hash + "-link:first").trigger("click");
	        break;
	    case 'expertise':
	        $("." + hash + "-link:first").trigger("click");
	        break;
	    case 'works':
	        $("." + hash + "-link:first").trigger("click");
	        break;
	    case 'contacts':
	        $("." + hash + "-link:first").trigger("click");
	        break;
	}
}

/* Each times we clic on a link in the nav, this function is executed */
$.fn.defaultEvent = function(callback, target) {	
	var stringTarget = target,

	$target = target ? $(target) : null;
    return this.click(function(e) {
		if (!$(this).hasClass("current")) { // Are we on the current section ?
        	
			$("#nav-header a").removeClass("current");
			$("#nav-default a").removeClass("current");
        	$(this).addClass("current");

			GalleryWrapperOut(); // We hide the fullscreen wrapper area
			GalleryOut(); // We hide the gallery area
			SocialNetworkOut(); // We hide the social network area
            SectionFadeOut(); // We hide all other sections area
            callback(); // Callback
      
		if ($target) $target.fadeIn();
       		window.location.hash = stringTarget;
        }
        return false;
	});
}
