// nav
$(window).bind("load", function() {
    var $el, leftPos, newWidth,
        $mainNav = $("#nav-bar > ul");
        
    $mainNav.append("<li id='nav-hover'></li>");
    
    var $navHover = $("#nav-hover");
    
      $navHover
	        .width(0)
	        .height($mainNav.height())  
	        .css("left", 0)
	        .data("origLeft", 0)
	        .data("origWidth", $navHover.width());   
        
    if ($("#nav-bar > ul > li").hasClass("current_page_item")) {
	    $navHover
	        .width($(".current_page_item").width())
	        .height($mainNav.height())
	        .css("left", $(".current_page_item a").position().left)
	        .data("origLeft", $(".current_page_item a").position().left)
	        .data("origWidth", $navHover.width());         
    }
        
    if ($("#nav-bar > ul > li").hasClass("current_page_parent")) {
	    $navHover
	        .width($(".current_page_parent").width())
	        .height($mainNav.height())
	        .css("left", $(".current_page_parent a").position().left)
	        .data("origLeft", $(".current_page_parent a").position().left)
	        .data("origWidth", $navHover.width());         
    }
        
    if ($("#nav-bar > ul > li").hasClass("current_page_ancestor")) {
	    $navHover
	        .width($(".current_page_ancestor").width())
	        .height($mainNav.height())
	        .css("left", $(".current_page_ancestor a").position().left)
	        .data("origLeft", $(".current_page_ancestor a").position().left)
	        .data("origWidth", $navHover.width());         
    }  
        
    $("#nav-bar > ul > li").hover(function() {
        $el = $(this);
        leftPos = $el.position().left;
        newWidth = $el.width();        
        $navHover.stop().animate({
            left: leftPos,
            width: newWidth
        });
    }, function() {
        $navHover.stop().animate({
            left: $navHover.data("origLeft"),
            width: $navHover.data("origWidth")
        });    
    });
    
    $(".current_page_item a").mouseenter();   
    
});

// connect with us
$(function() {
	$("#socials li.desc").css("background-position","0 0");
	$("#socials li").hover(function(e) {
		var $selected = $(this).attr("class");
		if ($selected == "rss") {
			$("#socials li.desc").css("background-position","0 -33px");
		}
		if ($selected == "facebook") {
			$("#socials li.desc").css("background-position","0 -66px");
		}	
		if ($selected == "twitter") {
			$("#socials li.desc").css("background-position","0 -99px");
		}
		}, function(e) {
			$("#socials li.desc").css("background-position","0 0");
		});
});

// home page slider
$(function() {
    $('#slider').cycle({
		fx: 'scrollUp',
		pause: 1,
		speed: 750,
		timeout: 4000, 
	    pager:  '#slider-pagination' 
	});
});
$(function() {
	$(".single-our_work #img-slider").cycle({
		fx: 'fade',
		pause: 1,
		speed: 750,
		timeout: 4000, 
	    pager:  '#slider-pagination' 
	});
});

// check for sidebar
$(function() {
	if ($("#sidebar").length) {
		$("#content").addClass("two-col-right");	
	}
});

// scroll to anchor
$(function() {
	$("a.top").anchorAnimate();
	$("#ipixels a").anchorAnimate();
	$("a.check-out-process").anchorAnimate();
});

jQuery.fn.anchorAnimate = function(settings) {

 	settings = jQuery.extend({
		speed : 400
	}, settings);	
	
	return this.each(function(){
		var caller = this
		jQuery(caller).click(function (event) {	
			event.preventDefault()
			var locationHref = window.location.href
			var elementClick = jQuery(caller).attr("href")
			
			var destination = jQuery(elementClick).offset().top;
			jQuery("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
				window.location.hash = elementClick
			});
		  	return false;
		})
	})
}

// process
$(function() {
	var $height = $("#process-container").height();
	$("#process").height($height);

	$("#process-nav span").click(function(e) {
		var $selected = $(this).attr("class");
		var $position = $("#process #" + $selected).position().left;
		
		$("#process-nav li").removeClass("current");
		$(this).parent("li").addClass("current");	
			
		$("#process-container").stop().animate({
			left: -$position,
		},500, "swing");
		
		return false;
	});
	
	$("#process a.next").click(function(e) {
		var $position = $("#process-container").position().left;
		var $width = ($("#process .step").width()) + 50;
		var $current = $(this).parent().parent().parent().attr("id");

		$("#process-nav li").removeClass("current");
		$("#process-nav span." + $current).parent("li").next("li").addClass("current");
			
		$("#process-container").stop().animate({
			left: $position - $width,
		},500, "swing");
		
		return false;
	});
	
	$("#process a.prev").click(function(e) {
		var $position = $("#process-container").position().left;
		var $width = ($("#process .step").width()) + 50;
		var $current = $(this).parent().parent().parent().attr("id");

		$("#process-nav li").removeClass("current");
		$("#process-nav span." + $current).parent("li").prev("li").addClass("current");
			
		$("#process-container").stop().animate({
			left: $position + $width,
		},500, "swing");
		
		return false;
	});
	
});

// footer testimonials slider
$(function() {
    $('#footer #testimonials').cycle({
		fx: 'fade',
		pause: 1,
		speed: 750,
		timeout: 7000
	});
});

// footer remove last col margin-right
$(function() {
	$("#footer .col:last").css("margin-right",0);
});

// sub footer notice remove first left border
$(function() {
	$("#sub-footer #footer-notice ul li a:first").css("border-left","none");
});

// remove current page from blog and add to our work
$(function() {

	if ($("body").hasClass("post-type-archive-our_work")) {	// single-products is the name of my template page for the custom post type
		$("li.page-item-18").removeClass("current_page_parent");	// Removes the class current_page_parent from the <li> with the page-id of the Blog (News)
		$("li.page-item-12").addClass("current_page_parent");	// Adds the class current_page_parent to the <li> with the page-id of the Products page
	}

	if ($("body").hasClass("single-our_work")) {	// single-products is the name of my template page for the custom post type
		$("li.page-item-18").removeClass("current_page_parent");	// Removes the class current_page_parent from the <li> with the page-id of the Blog (News)
		$("li.page-item-12").addClass("current_page_parent");	// Adds the class current_page_parent to the <li> with the page-id of the Products page
	}

});

// our work overylay
$(function() {
	$(".thumb").children('.overlay').show().animate({
			opacity: 0,
		},0);
	$(".thumb").hover(function() {
		$(this).children('.overlay').stop().animate({
			opacity: 1.0,
		},300);
	}, function() {
		$(this).children('.overlay').stop().animate({
			opacity: 0,
		},400);
	});
});

// our work scroll down with page scroll
var scrollCount = 0;
			
$(function() {	
		
	$(window).scroll(
		function() {
			scrollCount++;
			setTimeout(moveImage, 250); //this tells it how long to delay it before moving it
		}		
	);
});
	
function moveImage() {
	scrollCount--;
	if(scrollCount > 0)
		return;
		
	var startPos = 304; //Starting point for the image
	var scrollPos = $(this).scrollTop();
	var containerHeight = $(".single-our_work #main-content").height();
	var imageHeight = $(".single-our_work #images").height();
	var scrollAmount = ((containerHeight) - imageHeight) + 304;
		
	if (scrollPos > startPos) {			
		if (scrollAmount > scrollPos) {
			var scrollTo = ((scrollPos) - startPos) + 10;
			$('.our_work #images').animate({'top': scrollTo + 'px'}, 100);			
		} else {
			var scrollTo = ((scrollAmount) - startPos);
			$('.our_work #images').animate({'top': scrollTo + 'px'}, 100);
		}		
	} else {	
		$('.our_work #images').animate({'top': '0px' }, 100);
	}
	 
};

// services remove last line
$(function() {
	$("#services .line:last").hide();
});
	
// buttons
$(function() {
	$(".word").prepend("<span class='doc'></span>");
});
	
	
	
	
	

