var socialIcons = new Array();
socialIcons = ["facebook", "linkedin", "twitter", "go"];
for (var i = 0; i < socialIcons.length; i++) { 
	eval("A" + i + "on = new Image();"); eval("A" + i + "off = new Image();");
	eval("A" + i + "on.src = \"" + folderLevel + "/images/interface/icon-" + socialIcons[i] + "-r.png\";");
	eval("A" + i + "off.src = \"" + folderLevel + "/images/interface/icon-" + socialIcons[i] + ".png\";");
}

var navigation = new Array();
navigation = ["about", "work", "careers", "blog", "contact"];
for (var i = 0; i < navigation.length; i++) { 
	eval("B" + i + "on = new Image();"); eval("B" + i + "off = new Image();");
	eval("B" + i + "on.src = \"" + folderLevel + "/images/interface/btn-" + navigation[i] + "-r.png\";");
	eval("B" + i + "off.src = \"" + folderLevel + "/images/interface/btn-" + navigation[i] + ".png\";");
}

function changeImages() 
{
  if (document.getElementById) {
    for (var i = 0; i < changeImages.arguments.length; i += 2) { 
  		document.getElementById(changeImages.arguments[i]).src = eval(changeImages.arguments[i + 1] + ".src"); 
	}
  }
}

function swapStory(whichStory)
{
	turnOffStories();
	theId = "clientStory" + whichStory;
	document.getElementById(theId).style.display = "block";
}

function turnOffStories()
{
	for (var i = 0; i < 7; i++)
	{
		theId = "clientStory" + i;
		document.getElementById(theId).style.display = "none";
	}
}

function jobFormSelect(interestArea,expertiseLevel)
{
	theOptions = document.getElementById("interest").getElementsByTagName("option");
	for (var i = 0; i < theOptions.length; i++)
	{
		if (theOptions[i].value == interestArea)
		{
			theOptions[i].selected = true;
		}
	}
	theOptions2 = document.getElementById("expertise").getElementsByTagName("option");
	for (var i = 0; i < theOptions2.length; i++)
	{
		if (theOptions2[i].value == expertiseLevel)
		{
			theOptions2[i].selected = true;
		}
	}
}

function storyBackgroundOn(theDiv)
{
	theDiv.style.backgroundImage = "url(/wp-content/themes/smallarmy/images/content-design/bg-story-overview-r.gif)";
}

function storyBackgroundOff(theDiv)
{
	theDiv.style.backgroundImage = "url(/wp-content/themes/smallarmy/images/content-design/bg-story-overview-0.gif)";
}

$(document).ready(function() {
	
	// Tabs on homepage 
	function initalizeTabs() {
		
		var rotateSpeed = 5000; // Milliseconds to wait until switching tabs.
		var currentTab = 0; // Set to a different number to start on a different tab.
		var numTabs; // These two variables are set on document ready.
		var autoRotate;

		function openTab(clickedTab) {
			var thisTab = $(".tabbed-box .tabs a").index(clickedTab);
			$(".tabbed-box .tabs li a").removeClass("active");
			$(".tabbed-box .tabs li a:eq("+thisTab+")").addClass("active");
			$(".tabbed-box .tabbed-content").hide();
			$(".tabbed-box .tabbed-content:eq("+thisTab+")").show();
			currentTab = thisTab;
		}

		function rotateTabs() {
			var nextTab = (currentTab == (numTabs - 1)) ? 0 : currentTab + 1;
			openTab($(".tabbed-box .tabs li a:eq("+nextTab+")"));
		}

		numTabs = $(".tabbed-box .tabs li a").length;
		$(".tabbed-box .tabs li a").click(function() { 
			openTab($(this));
			// JScrollBar Callback Here
			initializeJScrollBar();return false; 
		});
		$(".tabbed-box").mouseover(function(){clearInterval(autoRotate)})
		//.mouseout(function(){autoRotate = setInterval("rotateTabs()", rotateSpeed)});
		
		$(".tabbed-box .tabs li a:eq("+currentTab+")").click()
		$(".tabbed-box").mouseout();
				
	}

	// Colorbox Popups
	function initalizeColorBoxes(){
		$(".contactUs").colorbox({width:"460px", inline:true, href:"#contactForm", opacity:0.85, speed:350, scrolling:false});
		
		// Bios
		$(".showJeffBio").colorbox({width:"460px", height:"635px", inline:true, href:"#jeffBio", opacity:0.85, speed:350, scrolling:false});
		$(".showSteveBio").colorbox({width:"460px", height:"555px", inline:true, href:"#steveBio", opacity:0.85, speed:350, scrolling:false});
		$(".showMikeBio").colorbox({width:"460px", height:"555px", inline:true, href:"#mikeBio", opacity:0.85, speed:350, scrolling:false});
		$(".showBenBio").colorbox({width:"460px", height:"555px", inline:true, href:"#benBio", opacity:0.85, speed:350, scrolling:false});
		$(".showMonicaBio").colorbox({width:"460px", height:"555px", inline:true, href:"#monicaBio", opacity:0.85, speed:350, scrolling:false});
		$(".showBrandonBio").colorbox({width:"460px", height:"635px", inline:true, href:"#brandonBio", opacity:0.85, speed:350, scrolling:false});
		$(".showMichaelBio").colorbox({width:"460px", height:"555px", inline:true, href:"#michaelBio", opacity:0.85, speed:350, scrolling:false});
		$(".showPaulBio").colorbox({width:"460px", height:"595px", inline:true, href:"#paulBio", opacity:0.85, speed:350, scrolling:true});
		$(".showGeorgeBio").colorbox({width:"460px", height:"575px", inline:true, href:"#georgeBio", opacity:0.85, speed:350, scrolling:true});
		$(".showClaireBio").colorbox({width:"460px", height:"595px", inline:true, href:"#claireBio", opacity:0.85, speed:350, scrolling:false});
		$(".showAllisonPBio").colorbox({width:"460px", height:"575px", inline:true, href:"#allisonPBio", opacity:0.85, speed:350, scrolling:false});
		$(".showSamBio").colorbox({width:"460px", height:"555px", inline:true, href:"#samBio", opacity:0.85, speed:350, scrolling:false});
		$(".showAllisonRBio").colorbox({width:"460px", height:"635px", inline:true, href:"#allisonRBio", opacity:0.85, speed:350, scrolling:true});
		$(".showChristianBio").colorbox({width:"460px", height:"595px", inline:true, href:"#christianBio", opacity:0.85, speed:350, scrolling:true});
		$(".showTriptiBio").colorbox({width:"460px", height:"595px", inline:true, href:"#triptiBio", opacity:0.85, speed:350, scrolling:true});
		$(".showRachelBio").colorbox({width:"460px", height:"595px", inline:true, href:"#rachelBio", opacity:0.85, speed:350, scrolling:true});
		$(".showAmyBio").colorbox({width:"460px", height:"595px", inline:true, href:"#amyBio", opacity:0.85, speed:350, scrolling:true});
		$(".showKaelanBio").colorbox({width:"460px", height:"595px", inline:true, href:"#kaelenBio", opacity:0.85, speed:350, scrolling:true});
		$(".showBriannaBio").colorbox({width:"460px", height:"595px", inline:true, href:"#briannaBio", opacity:0.85, speed:350, scrolling:true});
		$(".showDanielBio").colorbox({width:"460px", height:"595px", inline:true, href:"#danielBio", opacity:0.85, speed:350, scrolling:true});
		$(".showStephanieBio").colorbox({width:"460px", height:"595px", inline:true, href:"#stephanieBio", opacity:0.85, speed:350, scrolling:true});
				
		// Work Client Lightboxes
		$(".clientOne").colorbox({ width:"1024px", height:"750px", inline:true, href:"#clientOne", opacity:0.85, speed:350, scrolling:false, onComplete: function(){initalizeClientSlideShow('one');}, onClosed: function(){slider.destroyShow();}, preloading: true});
		$(".clientTwo").colorbox({ width:"1024px", height:"790px", inline:true, href:"#clientTwo", opacity:0.85, speed:350, scrolling:false, onComplete: function(){initalizeClientSlideShow('two');}, onClosed: function(){slider.destroyShow();}, preloading: true});
		$(".clientThree").colorbox({ width:"1024px", height:"720px", inline:true, href:"#clientThree", opacity:0.85, speed:350, scrolling:false, onComplete: function(){initalizeClientSlideShow('three');}, onClosed: function(){slider.destroyShow();}, preloading: true});
		$(".clientFour").colorbox({ width:"1024px", height:"770px", inline:true, href:"#clientFour", opacity:0.85, speed:350, scrolling:false, onComplete: function(){initalizeClientSlideShow('four');}, onClosed: function(){slider.destroyShow();}, preloading: true});
		$(".clientFive").colorbox({ width:"1024px", height:"750px", inline:true, href:"#clientFive", opacity:0.85, speed:350, scrolling:false, onComplete: function(){initalizeClientSlideShow('five');}, onClosed: function(){slider.destroyShow();}, preloading: true});
		$(".clientSix").colorbox({ width:"1024px", height:"740px", inline:true, href:"#clientSix", opacity:0.85, speed:350, scrolling:false, onComplete: function(){initalizeClientSlideShow('six');}, onClosed: function(){slider.destroyShow();}, preloading: true});
		$(".clientSeven").colorbox({ width:"1024px", height:"720px", inline:true, href:"#clientSeven", opacity:0.85, speed:350, scrolling:false, onComplete: function(){initalizeClientSlideShow('seven');}, onClosed: function(){slider.destroyShow();}, preloading: true});
		$(".clientEight").colorbox({ width:"1024px", height:"750px", inline:true, href:"#clientEight", opacity:0.85, speed:350, scrolling:false, onComplete: function(){initalizeClientSlideShow('eight');}, onClosed: function(){slider.destroyShow();}, preloading: true});
	}
	
	// Work Client Slideshows 
	function initalizeClientSlideShow(id){
		slider = $("."+id).bxSlider({controls: true});
		$('.thumbs a').click(function(){
			var thumbIndex = $('.thumbs a').index(this);
			slider.goToSlide(thumbIndex);
			$('.thumbs a').removeClass('pager-active');
			$(this).addClass('pager-active');
			return false;
		});
		$('.thumbs a:first').addClass('pager-active');		
		// Load first thumb alt to p
		var alt = $(".pager-active img").attr("alt");
		$(".thumbs p").text(alt);
		// On thumb hover load thumb alt to p
		$('.thumbs a img').hover(
			function(){
				var hoverThumb = $(this).attr("alt");
				$(".thumbs p").text(hoverThumb);
			},
			// On mouseout load pager-active thumb alt to p
			function(){
				var alt = $(".pager-active img").attr("alt");
				$(".thumbs p").text(alt);
			}
		);	
	}

	// JScroll Pane for Twitter Feed - Using callback from Tab function
	function initializeJScrollBar(){
		$('.scroll-pane').jScrollPane();	
	}
	
	// Cycle for the testimonials
	function initializeCycle(){
		$('#cycle').cycle({ 
			fx:     'fade', 
			speed:  600, 
			next:   '.arrow-down', 
			timeout: 0
		});
	}

	function initalizeContactFormScript(){
		
		// Hide warnings
		$('.error').hide();
			
		// Submit form on click
		$(".submit-contact").click(function() {
			// validate and process form
			// first hide any error messages
			$('.error').hide();
			
			var client_name = $("input#client_name").val();
			if (client_name == "") {
				$("label#client_name_error").show();
				$("input#client_name").focus();
				return false;
			}
			
			var client_email = $("input#client_email").val();
			if (client_email == "") {
				$("label#client_email_error").show();
				$("input#client_email").focus();
				return false;
			}
			
			var client_phone = $("input#client_phone").val();
			if (client_phone == "") {
				$("label#client_phone_error").show();
				$("input#client_phone").focus();
				return false;
			}
			
			var org = $("input#org").val();
			if (org == "") {
				$("label#org_error").show();
				$("input#org").focus();
				return false;
			}

			var client_msg = $("textarea#client_msg").val();
			if (client_msg == "") {
				$("label#client_msg_error").show();
				$("textarea#client_msg").focus();
				return false;
			}
			
			var dataString = 'client_name='+ client_name +'&client_email='+ client_email + '&client_phone=' + client_phone + '&org=' + org + '&client_msg=' + client_msg;
			//alert (dataString);return false;
				
			$.ajax({
				type: "POST",
				url: "/wp-content/themes/smallarmy/contact-form.php",
				data: dataString,
				success: function(data) {
					$('.message').html(data);
				}
			});
			return false;
		});	
	}
	
	// Run Functions
	initalizeColorBoxes();
	initalizeContactFormScript();
	initalizeTabs();
	initializeCycle();
});

