
// 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($){
	$(".fadeout").hover(function(){
		$(this).stop().animate({opacity: "0.4"}, 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"});
	});
});

// 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($){	
	$(".menu ul").css("display","none");
	$(".menu li").hover(function(){
		$(this).find('ul:first').slideDown(50).parent().find("a").addClass("hover");
		$(this).find('ul ul:first').parent().find('a').removeClass("hover").addClass("subber");
		$(this).find('ul ul a').removeClass("subber");
		$(this).find('ul > a').removeClass("hover");
	}, 
	function () {
		$(this).find('ul:first').fadeToggle(50);
		$(this).find('ul:first').parent().find("a").removeClass("hover");
	});
	$("#top-menu ul ul a").wrapInner("<span></span>");
	$("#top-menu ul ul li").hover(function(){
		$(this).find("span:first").stop().animate({marginLeft:'10px'},{queue:false, duration:100, easing: 'easeInSine'});
	},
	function(){
		$(this).find("span").stop().animate({marginLeft:'0px'},{queue:false, duration:100, easing: 'easeOutSine'});
	});
});
(function($){
	$(".menu ul li").hover(function(){
		$(this).find("a").addClass("active");
		$(this).find("ul li a").removeClass("active");
	}, 
	function () {
		$(this).find("a").removeClass("active");
	});
});



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

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

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

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



// Animation of tweets
(function($){			
	var tweets_move = function()
	{
		setTimeout(function(){
			$('#deadTweets li:first').animate({opacity: '0'},{ duration:200, easing: 'easeOutCubic', complete: function()
				{
					
					$(this).detach().appendTo('#deadTweets ul').removeAttr('style');
					var li_height = $('#deadTweets li:first').height(); 
					$("#deadTweets ul").animate({height: li_height});	
				}
			});
			tweets_move();
		}, 5000);
	};
	tweets_move();
});

// Blog Home Slider
 (function($){
        
        var auto_slide = 1;
        var hover_pause = 1;
        var key_slide = 1;
	
        var auto_slide_seconds = 5000;
		
        $('.carousel_dcb li:first').before($('.carousel_dcb li:last')); 
        
        if(auto_slide == 1){
            var timer = setInterval('slide("right")', auto_slide_seconds); 
        }
  
        if(hover_pause == 1){
            $('.carousel_dcb').hover(function(){
                clearInterval(timer)
            },function(){
                timer = setInterval('slide("right")', auto_slide_seconds); 
            });
  
        }
  
        if(key_slide == 1){
        	$(document).bind('keypress', function(e) {
                if(e.keyCode==37){
                        slide('left');
                }else if(e.keyCode==39){
                        slide('right');
                }
            });

        }
        
        
  });

function slide(where){
    
	var item_width = $('.carousel_dcb li').outerWidth();
	
	if(where == 'left'){
		var left_indent = parseInt($('.carousel_dcb').css('left')) + item_width;
	}else{
		var left_indent = parseInt($('.carousel_dcb').css('left')) - item_width;
	
	}
	
	$('.carousel_dcb:not(:animated)').animate({opacity:'0.7'},250).animate({'left' : left_indent},400, 'easeInOutExpo', function(){    
		
		if(where == 'left'){
			$('.carousel_dcb li:first').before($('.carousel_dcb li:last'));
		}else{
			$('.carousel_dcb li:last').after($('.carousel_dcb li:first')); 
		}
		
		$('.carousel_dcb').css({'left' : '-240px'});
	}).animate({opacity:'1'});
       
}

// Portfolio Home Slider
 (function($){
        
        var auto_slide = 1;
        var hover_pause = 1;
        var key_slide = 1;
	
        var auto_slide_seconds = 5000;
		
        $('.carousel2_dcb li:first').before($('.carousel2_dcb li:last')); 
        
        if(auto_slide == 1){
            var timer = setInterval('slide2("right")', auto_slide_seconds); 
        }
  
        if(hover_pause == 1){
            $('.carousel_dcb').hover(function(){
                clearInterval(timer)
            },function(){
                timer = setInterval('slide2("right")', auto_slide_seconds); 
            });
  
        }
  
        if(key_slide == 1){
        	$(document).bind('keypress', function(e) {
                if(e.keyCode==37){
                        slide2('left');
                }else if(e.keyCode==39){
                        slide2('right');
                }
            });

        }
        
        
  });

function slide2(where){
    
	var item_width = $('.carousel2_dcb li').outerWidth();
	
	if(where == 'left'){
		var left_indent = parseInt($('.carousel2_dcb').css('left')) + item_width;
	}else{
		var left_indent = parseInt($('.carousel2_dcb').css('left')) - item_width;
	
	}
	
	$('.carousel2_dcb:not(:animated)').animate({opacity:'0.7'},250).animate({'left' : left_indent},400, 'easeInOutExpo', function(){    
		
		if(where == 'left'){
			$('.carousel2_dcb li:first').before($('.carousel2_dcb li:last'));
		}else{
			$('.carousel2_dcb li:last').after($('.carousel2_dcb li:first')); 
		}
		
		$('.carousel2_dcb').css({'left' : '-240px'});
	}).animate({opacity:'1'});
       
}


////////////////////////////////////////////////////////////////////////////////////////////////////////
// PORTFOLIO ANIMATIONS --------------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////////////////////////////

//PORTFOLIO 1
(function($){
		   
	if((document.all)&&(navigator.appVersion.indexOf("MSIE 7.")!=-1)){
	
		$(".filter_list a").click(function(){
		filteris = $(this).attr("title");
		
		$(".filter_list a").removeClass("current");
		$(this).addClass("current");
		
		
		if(filteris == "all") {
			$(".portfolio1 .portfolio_item").show();
		}
		else {
			  $(".portfolio1 .portfolio_item").hide();
			  $('.portfolio1 #portfolio .'+filteris).show();
		}
		
	});
		
	} else {
		
	$(".filter_list a").click(function(){
		filteris = $(this).attr("title");
		
		$(".filter_list a").removeClass("current");
			$(this).addClass("current");
		
		
		if(filteris == "all") {
			$(".portfolio1 .portfolio_item").slideDown().animate({ opacity : 1 });
		}
		else {
			$(".portfolio1 .portfolio_item").not('.'+filteris).animate({ opacity : 0 }).slideUp();
			$('.portfolio1 #portfolio .'+filteris).animate({ opacity : 1 }).slideDown();
		}
		
	});
	
	}
});

//PORTFOLIO 2
(function($){
		   
	if((document.all)&&(navigator.appVersion.indexOf("MSIE 7.")!=-1)){
	
		$(".portfolio2 .filter_list li a").click(function(){
		filteris = $(this).attr("title");
		
		$(".portfolio2 .filter_list li a").removeClass("current");
		$(this).addClass("current");
		
		
		if(filteris == "all") {
			$(".portfolio2 .portfolio_item").show();
		}
		else {
			  $(".portfolio2 .portfolio_item").hide();
			  $('.portfolio2 #portfolio .'+filteris).show();
		}
		
	});
		
	} else {
		
	$(".portfolio2 .filter_list li a").click(function(){
		filteris = $(this).attr("title");
		
		$(".portfolio2 .filter_list li a").removeClass("current");
		$(this).addClass("current");
		
		
		if(filteris == "all") {
			$(".portfolio2 .portfolio_item").animate({ opacity: '0' }, {
			queue:false,
			duration: 200,
			complete: function() {
			  $(".portfolio2 .portfolio_item").animate({ opacity: '1' },{queue:false, duration:450}).show();
			}
		});
		}
		else {
		$(".portfolio2 .portfolio_item").animate({ opacity: '0' }, {
			queue:false,
			duration: 200,
			complete: function() {
			  $(".portfolio2 .portfolio_item").css("display","none");
			  $('.portfolio2 #portfolio .'+filteris).animate({ opacity: '1' },{queue:false, duration:450}).show();
			}
		});
		}
		
	});
	
	}
});

// JQUERY SHORTCODES ANIMATIONS
// Tabs
(function($){
		$(".tabs a:first").addClass("selected");
		
		$(".tabs a").click(function () {
			
			if ($(this).hasClass("selected")){ }
			else {
			// switch all tabs off
			$(".selected").removeClass("selected");
			
			// switch this tab on
			$(this).addClass("selected");
			
			// slide all content up
			$(".tab-content").slideUp(50);
			
			// slide this content up
			var content_show = $(this).attr("rel");
			$("#"+content_show).slideDown(100);
			}
		});;
 
});

// Slider
(function($){

	//Set Default State of each portfolio piece
	$(".paging").show();
	$(".paging a:first").addClass("active");
		
	//Get size of images, how many there are, then determin the size of the image reel.
	var imageWidth = $(".window").width();
	var imageSum = $(".image_reel img").size();
	var imageReelWidth = imageWidth * imageSum;
	
	//Adjust the image reel to its new size
	$(".image_reel").css({'width' : imageReelWidth});
	
	//Paging + Slider Function
	rotate = function(){	
		var triggerID = $active.attr("rel") - 1; //Get number of times to slide
		var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

		$(".paging a").removeClass('active'); //Remove all active class
		$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
		
		//Slider Animation
		$(".image_reel").animate({ 
			left: -image_reelPosition
		}, 500 );
		
	}; 
	
	//Rotation + Timing Event
	rotateSwitch = function(){		
		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
			$active = $('.paging a.active').next();
			if ( $active.length === 0) { //If paging reaches the end...
				$active = $('.paging a:first'); //go back to first
			}
			rotate(); //Trigger the paging and slider function
		}, 7000); //Timer speed in milliseconds (3 seconds)
	};
	
	rotateSwitch(); //Run function on launch
	
	//On Hover
	$(".image_reel a").hover(function() {
		clearInterval(play); //Stop the rotation
	}, function() {
		rotateSwitch(); //Resume rotation
	});	
	
	//On Click
	$(".paging a").click(function() {	
		$active = $(this); //Activate the clicked paging
		//Reset Timer
		clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		rotateSwitch(); // Resume rotation
		return false; //Prevent browser jump to link anchor
	});	
	
});

//Accordion
(function($){
	
	$('.accordionButton').click(function() {

		$('.accordionButton').removeClass('on');
		  
	 	$('.accordionContent').slideUp(200);
   
		if($(this).next().is(':hidden') == true) {
			
			$(this).addClass('on');
			  
			$(this).next().slideDown(200);
		 } 
		  
	 });
	
	$('.accordionButton').mouseover(function() {
		$(this).addClass('over');
		
	}).mouseout(function() {
		$(this).removeClass('over');										
	});
	$('.accordionContent').hide();

});

//Toggle
(function($){
	$('.hidden').css("display", "none");
	$(".toggler h4").hover(function() {
		$(this).css("cursor","pointer");
	});
	$(".toggler h4").click(function() {
		$(this).parent().children('.hidden').slideToggle(200);
	});
});

(function($){
	$("#contact-form").validate();
});
