// 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;
 
            }
 
        }
 
    });
 
});



// Images fade animation
$(function(){
	$(".fadeload").hover(function(){
		$(this).stop().animate({opacity: "0.2"}, 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"});
	});
});



// VIDEOLINE JS

// Remove line on First and Last li
$(function() {	
		$("#sidebar ul").find("li:first").css("border-top", "none");
		$("#sidebar ul").find("li:last").css("border-bottom", "none");
		
		$(".footer_cols ul").find("li:first").css("border-top", "none");
		$(".footer_cols ul").find("li:last").css("border-bottom", "none");
		
});

// DROPDOWN MENU
$(function(){						   
	$("#top-menu ul ul").css({display: "none"});
	$('#top-menu ul li').hover(function(){
		$('ul', this).slideDown(80);
		$(".subline", this).addClass("current");
	},
	function(){
		$('ul', this).fadeOut(105).show();
		$(".subline", this).removeClass("current");
	});	
	
	$("#top-menu ul ul a").wrapInner("<span></span>");
	$("#top-menu ul ul li").hover(function(){
		$(this).find("span").stop().animate({marginLeft:'10px'},{queue:false, duration:250, easing: 'easeOutSine'});
	},
	function(){
		$(this).find("span").stop().animate({marginLeft:'0px'},{queue:false, duration:250, easing: 'easeOutSine'});
	});
	
	$("#top-menu ul ul").hover(function(){
		$(this).parent('li').find(".subline").addClass("current");
	},
	function(){
		$(this).parent('li').find(".subline").removeClass("current");
	});
});

// ZOOMS
$(function() {	
	$("#bottom_slideshow a span").css("opacity","0");
	$("#bottom_slideshow a").hover(function(){
		$(this).find('span').stop().animate({opacity: 1},{queue:false, duration:180, easing: 'easeOutSine'});
		},
		function(){
		$(this).find("span").stop().animate({opacity: 0},{queue:false, duration:180, easing: 'easeOutSine'});
	});
});

$(function() {	
	$("#nivo_slider a span").css("opacity","0");
	$("#nivo_slider a").hover(function(){
		$(this).find('span').stop().animate({opacity: 1},{queue:false, duration:180, easing: 'easeOutSine'});
		},
		function(){
		$(this).find("span").stop().animate({opacity: 0},{queue:false, duration:180, easing: 'easeOutSine'});
	});
});

$(function() {	
	$(".folio_item span").css("opacity","0");
	$(".folio_item a").hover(function(){
		$(this).find('span').stop().animate({opacity: 1},{queue:false, duration:180, easing: 'easeOutSine'});
		},
		function(){
		$(this).find("span").stop().animate({opacity: 0},{queue:false, duration:180, easing: 'easeOutSine'});
	});
});

// Hover state depending the target format.
$(function() {
	// Image
	$("a[href$='.png'], a[href$='.jpg'], a[href$='.jpeg'], a[href$='.pdf']").addClass("zoom_image");
	// Video
	$("a[href$='.swf'], a[href$='.mov'], a[href$='.rft']").addClass("zoom_video");
	//All other links are like videos...
	$('a').filter(function() {
		return this.hostname && this.hostname !== location.hostname;
	}).addClass("external");
	
	$("a[href*='http://']:not([href*='"+location.hostname+"'])").click( function() {
		window.open(this.href);
		return false;
	});
});




// GALLERY FILTER

$(function(){

	$("#the_gallery a").css("opacity","0");
	
	
	$(".filter .all").click(function(){
		
		// Reinitialization of all elements
		$("#the_gallery li").stop().animate({opacity: '1'});
		$("#the_gallery li").find("a").css("top","0px");
		
		
	});
	
	if((document.all)&&(navigator.appVersion.indexOf("MSIE 7.")!=-1)){
		
		$(".filter a").click(function(){
		
		$(".filter a").removeClass("current");
		$(this).addClass("current");

		// Get the title attribut
		thisItem = $(this).attr('rel');
		
			if(thisItem == "all") {
					
					// Reset settings on all elements
					$("#the_gallery li").stop().animate({width: '160px'});
					$("#the_gallery li").find("a").css("top","0px");
					
					// Reset settings on all elements with li parent has attribut of the filter in class
					$('#the_gallery li.'+thisItem).stop().animate({width: '160px'});
					$('#the_gallery li.'+thisItem).find("a").css("top","0px");
					
					} else {
		
					// Reset settings on all elements
					$("#the_gallery li").stop().animate({width: '0px'});
					$("#the_gallery li").find("a").css("top","160px");
					
					// Settings on all elements with li parent has attribut of the filter in class
					$('#the_gallery li.'+thisItem).stop().animate({width: '160px'});
					$('#the_gallery li.'+thisItem).find("a").css("top","0px");
			}
		
		
	});
		
	} else {
	
	$(".filter a").click(function(){
		
		$(".filter a").removeClass("current");
		$(this).addClass("current");

		// Get the title attribut
		thisItem = $(this).attr('rel');
		
			if(thisItem == "all") {
					
					// 
					$("#the_gallery li").stop().animate({opacity: '1'});
					$("#the_gallery li").find("a").css("top","0px" , "visibility","visible");
					
					// 
					$('#the_gallery li.'+thisItem).stop().animate({opacity: '1'});
					$('#the_gallery li.'+thisItem).find("a").css("top","0px" , "visibility","visible");
					
					} else {
		
					//
					$("#the_gallery li").stop().animate({opacity: '0.3'});
					$("#the_gallery li").find("a").css("top","160px");
					
					// 
					$('#the_gallery li.'+thisItem).stop().animate({opacity: '1'});
					$('#the_gallery li.'+thisItem).find("a").css("top","0px");
			}
		
		
	});
	}
	
	
	
		$("#the_gallery li").hover(function(){
				$(this).find("a").stop().animate({opacity: '0.8'});
		},function(){
				$(this).find("a").stop().animate({opacity: '0'});
		});

});


// GALLERY SLIDESHOW
$(function()
{
	var slideshow = function()
	{
		setTimeout(function(){
			$('#bottom_slideshow li:first').animate({marginLeft: '-153px'},{ duration:500, easing: 'easeOutCubic', complete: function()
				{
					$(this).detach().appendTo('#bottom_slideshow ul').removeAttr('style');	
				}
			});
			slideshow();
		}, 4000);
	};
	slideshow();
});

// CONTACT FORM
$(function() {
		$("#contact_part .content div").animate({opacity:0}).show();
		$("#contact_opener").click(function () {
			if ($("#contact_part").is(":hidden")) {
				$("#contact_part").slideDown({
					duration: 400,
					easing: 'easeOutBack',
					complete:function(){
						$("#contact_part .content div").animate({opacity:1},400);
					}
					}
				);
			} else {
				$("#contact_part .content div").animate({opacity:0},400,
					function(){
						$("#contact_part").slideUp(700,"easeOutExpo");
					});
			}
		});
});



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

// 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();
		}
    });
});

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

// PrettyPhoto Setting
$(function() {	
	$("a[rel^='prettyPhoto']").prettyPhoto({animationSpeed:'slow',theme:'dark_rounded'}); 
});

// Forms Validator
$(function() {
	$("#contact-form").validate();
	$("#reply-form").validate();
});
