$(document).ready(function() {
		
	// fix for target='_blank'
	$('a[href^="http://"], a[href^="https://"], .external').attr({
		target: "_blank", 
		title: "Opens in a new window"
	});	
	
	//nav effect
	$(".mainNav").find("ul li ul li a").mouseover(function(){
		$(this).find("span").stop().animate({width:"40"},"slow");
	});
	$(".mainNav").find("ul li ul li a").mouseout(function(){
		$(this).find("span").stop().animate({width:"10"},"slow");
		//$(this).find("span").animate({width:"10"},"slow");
	});
	$(".mainNav").mouseleave(function(){
		$(this).find("span").stop().animate({width:"10"},"slow");
	});
	
	//cycle testimonials
	$(".testimonials").cycle({
        fx:     'fade',
        speed:  1000,
        timeout: 5000,
        pause: 1,
        next: ".testItem"
    });
	
	//handle scroller
	$(".text").jScrollPane({
		dragMaxHeight:40
	});
	
	//add salesPoints
	$(".salesPoint").popup();
	
	//login popup
	login();
	
	//feature
	$(".feature").feature(); 
	
	//tabs
	tabs();
	
	//validation
	$(".validate").validate();

});

function login() {
	
	var isLogin = $(".loginPopup").length;
	
	if(isLogin > 0){
		var height = $(document).height();
		var width = $(document).width();
		var loginLeft = (width/2) - ($(".loginPopup").width()/2);
		var overlayCss = {
				"height": height,
				"width": width,
				"position":"absolute",
				"display":"none",
				"top":"0",
				"left":"0",
				"z-index":"100",
				"background":"#000"
		}
	}	
	$(".loginPopup").css("left",loginLeft);
	$(".overlay").css(overlayCss);
		
	$(".overlay").show("");	
	$(".overlay").css("opacity","0.8");
	$(".loginPopup").fadeIn("slow");
	
}

function tabs() {
	
//hides all tabAreas except first and add class to first tab
	$(".tabArea").find(".tabContent").hide("").end("").find(".tabContent:first").show("");
	$(".tabNav").find("ul li:first").addClass("selected");
			
	//gives all items with class tab an id
	$(".tab").attr("id", function (number) {
		  return "tab" + number;
	})
	
	//gives all items with class tabContent an id
	$(".tabContent").attr("id", function (number) {
			  return "tabContent" + number;		  
	});
	
	//adds surrounding color
	$("#clientArea .text").wrap("<div class='colorBorder'></div>");
	var colorBorderCss = {
		"width":"658px",
		"height":"336px",
		"border":"2px solid #999b9d"
	};
	$(".colorBorder").css(colorBorderCss);
	
	$(".welcomeTab").click(function(){
		$(".colorBorder").css("border","2px solid #999b9d");
		$(".jScrollPaneTrack").css("background","#999b9d");
	});
	
	$(".salesTab.clickable").click(function(){
		$(".colorBorder").css("border","2px solid #d9852f");
		$(".jScrollPaneTrack").css("background","#d9852f");
	});
	
	$(".marketingTab.clickable").click(function(){
		$(".colorBorder").css("border","2px solid #a3b023");
		$(".jScrollPaneTrack").css("background","#a3b023");
	});
	
	$(".commTab.clickable").click(function(){
		$(".colorBorder").css("border","2px solid #8c8fbf");
		$(".jScrollPaneTrack").css("background","#8c8fbf");
	});
	
	$(".systemsTab.clickable").click(function(){
		$(".colorBorder").css("border","2px solid #7cc1b5");
		$(".jScrollPaneTrack").css("background","#7cc1b5");
	});
	
	$(".planningTab.clickable").click(function(){
		$(".colorBorder").css("border","2px solid #1689be");
		$(".jScrollPaneTrack").css("background","#1689be");
	});
	
	$(".timeTab.clickable").click(function(){
		$(".colorBorder").css("border","2px solid #89b7d9");
		$(".jScrollPaneTrack").css("background","#89b7d9");
	});
	
	$(".teamTab.clickable").click(function(){
		$(".colorBorder").css("border","2px solid #74a492");
		$(".jScrollPaneTrack").css("background","#74a492");
	});
					
	$(".leadTab.clickable").click(function(){
		$(".colorBorder").css("border","2px solid #698bb3");
		$(".jScrollPaneTrack").css("background","#698bb3");
	});
	
	$(".coachTab.clickable").click(function(){
		$(".colorBorder").css("border","2px solid #929d92");
		$(".jScrollPaneTrack").css("background","#929d92");
	});
	
	//disables not signed up for
	var disabledCss = {
		"opacity":"0.3",
		"cursor":"default"
	};
	$(".tab").not(".welcomeTab, .clickable").css(disabledCss);
	
	//on click of tab hides all tabContents then shows one with same id
	$(".welcomeTab, .clickable").click(function(event){
								
		var id = this.id.replace("tab" , 'tabContent');
		$(".tabContent").css({"display" : "none"});
		$("#" + id).css({"display" : "block"});
		$(".tab").removeClass("selected");
		$(this).addClass("selected");
	
		return false;  			
	});
	
}	
