
// Fade image loader
$(function () {
	$('.fadeload').hide();//hide all the images on the page
});

var i = 0;//initialize
var int=0;//Internet Explorer Fix
$(function() {//The load event will only fire if the entire page or document is fully loaded
	var int = setInterval("doThis(i)",150);//500 is the fade in speed in milliseconds
});

function doThis() {
		var images = $('img.fadeload').length;//count the number of images on the page
		if (i >= images) {// Loop the images
			clearInterval(int);//When it reaches the last image the loop ends
		}
		$('img:hidden.fadeload').eq(0).fadeIn(350);//fades in the hidden images one by one
		i++;//add 1 to the count
}

// Smooth Scroll
$(function(){
 
    $('a[href*=#]').click(function() {
 
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
        && location.hostname == this.hostname) {
 
            var $target = $(this.hash);
 
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
 
            if ($target.length) {
 
                var targetOffset = $target.offset().top;
 
                $('html,body').animate({scrollTop: targetOffset}, 600);
 
                return false;
 
            }
 
        }
 
    });
 
});

/*
    // FOOTER COOKIE
   $(function() {
        $(".small_footer_active").click(function() {
			$('.footer_dynamic').css("display","none");
			$.cookie('footer_dynamic', 'hidden');
			});
        $(".big_footer_active").click(function() {
			$('.footer_dynamic').css("display","block");
			$.cookie('footer_dynamic', 'showed');
			});
		// COOKIES
		var foot = $.cookie('footer_dynamic');
	
		if (foot == 'hidden') {
			$('.footer_dynamic').css("display","none");
		};
		if (foot == 'showed') {
			$('.footer_dynamic').css("display","block");
		};
    });

    // BACKGROUND COOKIE
   $(function() {
        $(".light_active").click(function() {
			$("body").removeClass("dark");
			$("body").addClass("light");
			$("#wrap").removeClass("office");
			$("#wrap").removeClass("grunge");
			$("#wrap").removeClass("paper");
			$("#wrap").removeClass("wood");
			$.cookie('background_dynamic', 'light');
			$.cookie('texture_dynamic', 'none');
			});
        $(".dark_active").click(function() {
			$("body").removeClass("light");
			$("body").addClass("dark");
			$("#wrap").removeClass("office");
			$("#wrap").removeClass("grunge");
			$("#wrap").removeClass("paper");
			$("#wrap").removeClass("wood");
			$.cookie('background_dynamic', 'dark');
			$.cookie('texture_dynamic', 'none');
			});
		// COOKIES
		var bg = $.cookie('background_dynamic');
	
		if (bg == 'dark') {
			$("body").removeClass("light");
			$("body").addClass("dark");
			$("#wrap").removeClass("office");
			$("#wrap").removeClass("grunge");
			$("#wrap").removeClass("paper");
			$("#wrap").removeClass("wood");
		};
		if (bg == 'light') {
			$("body").removeClass("dark");
			$("body").addClass("light");
			$("#wrap").removeClass("office");
			$("#wrap").removeClass("grunge");
			$("#wrap").removeClass("paper");
			$("#wrap").removeClass("wood");
		};
    });

    // TEXTURES COOKIE
   $(function() {
        $(".office_active").click(function() {
			$("#wrap").addClass("office");
			$("#wrap").removeClass("grunge");
			$("#wrap").removeClass("paper");
			$("#wrap").removeClass("wood");
			$.cookie('texture_dynamic', 'office');
			});
        $(".paper_active").click(function() {
			$("#wrap").addClass("paper");
			$("#wrap").removeClass("grunge");
			$("#wrap").removeClass("wood");
			$("#wrap").removeClass("office");
			$.cookie('texture_dynamic', 'paper');
			});
        $(".grunge_active").click(function() {
			$("#wrap").addClass("grunge");
			$("#wrap").removeClass("wood");
			$("#wrap").removeClass("paper");
			$("#wrap").removeClass("office");
			$.cookie('texture_dynamic', 'grunge');
			});
        $(".wood_active").click(function() {
			$("#wrap").addClass("wood");
			$("#wrap").removeClass("grunge");
			$("#wrap").removeClass("paper");
			$("#wrap").removeClass("office");
			$.cookie('texture_dynamic', 'wood');
			});
		// COOKIES
		var texture = $.cookie('texture_dynamic');
	
		if (texture == 'office') {
			$("#wrap").addClass("office");
			$("#wrap").removeClass("grunge");
			$("#wrap").removeClass("paper");
			$("#wrap").removeClass("wood");
		};
		if (texture == 'paper') {
			$("#wrap").addClass("paper");
			$("#wrap").removeClass("grunge");
			$("#wrap").removeClass("wood");
			$("#wrap").removeClass("office");
		};
		if (texture == 'grunge') {
			$("#wrap").addClass("grunge");
			$("#wrap").removeClass("wood");
			$("#wrap").removeClass("paper");
			$("#wrap").removeClass("office");
		};
		if (texture == 'wood') {
			$("#wrap").addClass("wood");
			$("#wrap").removeClass("grunge");
			$("#wrap").removeClass("paper");
			$("#wrap").removeClass("office");
		};
		if (texture == 'none') {
			$("#wrap").removeClass("wood");
			$("#wrap").removeClass("grunge");
			$("#wrap").removeClass("paper");
			$("#wrap").removeClass("office");
		};
    });

*/
// Images fade animation
$(function(){
	$(".fadeload").hover(function(){
		$(this).stop().animate({opacity: "0.5"}, 350);
	},
	function(){
		$(this).stop().animate({opacity: "1"}, 125);
	});
});

// Go Top button animation
$(function(){
	$("#gotop a").hover(function(){
		$(this).stop().animate({top: "-20px" , height: "30px"}, {duration:125 , easing : "easeInCubic"});
	},
	function(){
		$(this).stop().animate({top: "-10px" , height: "20px"}, {duration:600 , easing : "easeOutBounce"});
	});
});



// Sidebar list animation
$(function(){
   if (typeof document.body.style.maxHeight != "undefined") {
	
	} else {
		
		$("#sidebar li").find("a").wrapInner("<span></span>");	   
		$("#sidebar li").hover(function(){
			$(this).find("span").stop().animate({marginLeft:'10px'},{queue:false, duration:250, easing: 'easeOutCubic'})
		},
		function(){
			$(this).find("span").stop().animate({marginLeft:'0px'},{queue:false, duration:100, easing: 'easeInCubic'})
		});
		
		$("#sidebar_left li").find("a").wrapInner("<span></span>");	   
		$("#sidebar_left li").hover(function(){
			$(this).find("span").stop().animate({marginLeft:'10px'},{queue:false, duration:250, easing: 'easeOutCubic'})
		},
		function(){
			$(this).find("span").stop().animate({marginLeft:'0px'},{queue:false, duration:100, easing: 'easeInCubic'})
		});
	}
});


// Themifier animation
$(function(){
	$("#custom_theme").css("display","none");	   
	$("#themifier").click(function(){
		$("#custom_theme").fadeToggle("fast", "linear");
		$(this).toggleClass("close_panel", 80);
	});
});

$(function(){
	$('.hidden').css("display", "none");
	$(".toggler a").click(function() {
		$(this).parent().children('.hidden').slideToggle("slow");
	});
});

$(function(){						   
	$("#top_menu ul ul").css({display: "none"});
	$("#top_menu ul ul ul").css({display: "none"});
	$('#top_menu ul li').hover(function(){
		$('ul:first', this).slideDown(140);
	},
	function(){
		$('ul:first', this).slideUp(125);
	});
});

// Flickr fade animation
$(function(){
	$(".flickr_gallery img").hover(function(){
		$(this).stop().animate({opacity: "0.5"});
	},function(){
		$(this).stop().animate({opacity: "1"});
	});
});

// Portfolio Grid
$(function(){
	$(".grid .infos").css("opacity","0");
	$(".grid li").hover(function(){
		$(this).find(".infos").stop().animate({opacity: "1", top: "0px"});
		$(this).find(".thumbnail_item").stop().animate({opacity: "0.5"}, 350);
	},function(){
		$(this).find(".infos").stop().animate({opacity: "0", top: "265px"});
		$(this).find(".thumbnail_item").stop().animate({opacity: "1"}, 350);
	});
	
});

// Portfolio LIST
$(function(){
	$(".list .zoom").css("opacity","0");
	$(".list .zoom").hover(function(){
		$(this).stop().animate({opacity: "1"});
	},function(){
		$(this).stop().animate({opacity: "0"});
	});
	
});

// Captcha system
$(function(){
$("#errorcaptcha").css({opacity: "0"});
$("#check").keyup(function () {
		var rep = $(this).val();
		var n1 = document.getElementById('num1').innerHTML;
		var n2 = document.getElementById('num2').innerHTML;
		var n3 = parseInt(n1) + parseInt(n2);
      		if( n3 == rep ){
			$("#submitter").prepend('<input type="submit" name="contact_submit" id="contact_submit" value="Send Now" />').animate({opacity: "1"},{duration:350});
			$("#errorcaptcha").text(" ").animate({opacity: "0"},{duration:150});
		}
		else {
			$("#errorcaptcha").text("Not good!").animate({opacity: "1"},{duration:350});
			$("#submitter").prepend('').animate({opacity: "0"},{duration:150}).empty();
		}
    });
});
