// Drop Down Navigation 

$(document).ready(function(){
	$("#globalNav").superfish({
		delay		: 50,
		animation	: {opacity:"show", height:"show"},
		speed		: "normal"
	});
});



// Sliding Iframe

$(document).ready( function() {    
	
	$(".projectList a").click(function() {
		showOverlay();
		setTimeout(function(){ $("#projectDetails").slideDown("slow"); }, 1000);
	});

	$("#projectDetails .closeButton a").click(function() {
		$("#projectDetails").slideUp("slow");           
		setTimeout(function(){ hideOverlay(); }, 1000);
	});

});


// sIFR
/*
if(typeof sIFR == "function"){
	sIFR.replaceElement(named({
		sSelector:".headings h2",
		sFlashSrc:"/includes/helvetica.swf", 
		sColor:"#B1B1B1", 
		sBgColor:"#424242",
		nPaddingRight: 20,
		sWmode: "opaque"
	}));

	sIFR.replaceElement(named({
		sSelector:".headings h3",
		sFlashSrc:"/includes/helvetica.swf", 
		sColor:"#B1B1B1", 
		sBgColor:"#424242",
		sWmode: "opaque"
	}));

	sIFR.replaceElement(named({
		sSelector:".s-projectdetails h2",
		sFlashSrc:"/includes/helvetica.swf", 
		sColor:"#FEFEFE", 
		sBgColor:"#63686a",
		sWmode: "opaque"
	}));
};
*/

// Targeting Safari 3
/*
$(document).ready( function() {
	if(window.devicePixelRatio) {
		$(".headings h3").addClass("pushUpSafari");
	}
});
*/

// Sliding Stuff
$(document).ready( function() {
	var isSliding = false;
	$(".toggle").click(function() {
		if (isSliding == false) {
			isSliding = true;
			$(".slide").slideToggle("fast", function() {
				isSliding = false;
			});
		}
	});
});



// 2 Column List

function twoCols(src, type) {
	var origList = src;


	var leftList = document.createElement(type);
	var rightList = document.createElement(type);
	var container = document.createElement('div');

	var items = origList.getElementsByTagName('LI');

	
	if (items.length >= 7)
	{
		//alert("more than 7");	
		var itemsLength = items.length/2;
		for (i = 0; i < 7; i++) { // Make i < itemsLength to divide in half.
			leftList.appendChild(items[0]);
		}
		itemsLength = items.length;
		for (i = 0; i < itemsLength; i++) {
			rightList.appendChild(items[0]);
		}
	}
	else { 
		//alert("less than 7");
		for (i = 0; i = items.length; i++) {
			leftList.appendChild(items[0]);
		}
	}
	


	
	container.appendChild(leftList);
	container.appendChild(rightList);

	leftList.setAttribute('class', 'projectList column');
	rightList.setAttribute('class', 'projectList column last');
	container.setAttribute('id','twoCols');
	if (document.all) {
		leftList.setAttribute('className', 'projectList column');
		rightList.setAttribute('className', 'projectList column last');
		container.setAttribute('id','twoCols');
	}
	if (type == 'ol') {
		rightList.setAttribute('start', leftList.getElementsByTagName('LI').length + 1 );
	}
	origList.parentNode.replaceChild(container, origList);

	
}

function allTwoCols (whichclass, type) {
	var uls = document.getElementsByTagName(type);
	for (var i=0; i< uls.length; i++) {
		if (uls[i].getAttribute('class') == whichclass || uls[i].getAttribute('className') == whichclass) {
			twoCols(uls[i], type.toLowerCase());
		}
	}
}


// Text Popups
$(document).ready(function(){
	$(".popupList a").click(function(){
		// Close all divs
		$(".textPopup div").hide();
		// Get class from clicked link
		div = $(this).attr("class");
		// Show Overlay
		showOverlay();
		// Reveal popup window
		$(".textPopup").slideDown();
		// Show corresponding div
		$(".textPopup div." + div).customFadeIn(1000);
	});


	// Close button
	$(".textPopup .closeButton a").click(function(){
		$(".textPopup div").customFadeOut();
		$(".textPopup").slideUp();
		hideOverlay();
	});
});

$(document).ready(function(){
	$(".staffList a").click(function(){
		// Close all divs
		$(".staffPopup div").hide();
		// Get class from clicked link
		div = $(this).attr("class");
		// Reveal popup window
		$(".staffPopup").slideDown();
		// Show corresponding div
		$(".staffPopup div." + div).customFadeIn(1000);
	});


	// Close button
	$(".staffPopup .closeButton a").click(function(){
		$(".staffPopup div").customFadeOut();
		$(".staffPopup").slideUp();
	});
});



/* Project paging
$(document).ready(function(){
	$(".projectPaging .more").click(function(){

		var totalimages = $(".projectPhoto img").length;
		// Check if 'current' class is on the last image
		if($(".projectPhoto img:eq(" + (totalimages - 1) + ")").hasClass("current"))
		{
			// Remove 'current' class from image and place on FIRST image
			$(".projectPhoto img.current").hide().removeClass("current");
			$(".projectPhoto img:eq(0)").fadeIn("slow").addClass("current");
		}
		else { 
			// Remove 'current' class from image and place on next
			$(".projectPhoto img.current").hide().removeClass("current").next().fadeIn("slow").addClass("current");
		}
		if ($("body").hasClass("s-projectdetails") == true)
		{
			return false;
		}
	});

	$(".projectPaging .previous").click(function(){

		var totalimages = $(".projectPhoto img").length;
		// Check if 'current' class is on the first image
		if($(".projectPhoto img:eq(0)").hasClass("current"))
		{
			// Remove 'current' class from image and place on LAST image
			$(".projectPhoto img.current").hide().removeClass("current");
			$(".projectPhoto img:eq(" + (totalimages - 1) + ")").fadeIn("slow").addClass("current");
		}
		else { 
			// Remove 'current' class from image and place on previous
			$(".projectPhoto img.current").hide().removeClass("current").prev().fadeIn("slow").addClass("current");
		}
		if ($("body").hasClass("s-projectdetails") == true)
		{
			return false;
		}
	});
});*/



// Better Project paging 

$(document).ready(function(){
	$('#divProjectPhotos').cycle({
		prev: '#lnkPrevPhoto',
		next: '#lnkNextPhoto'
	});
});


// Error class for Area Code in phone number
$(document).ready(function(){
	if( $("#txtPhone").hasClass("errorInput") ) {
		$("#txtAreaCode").addClass("errorInput");
	}
});



// Overlay

function showOverlay() {
	$("#overlay").css("opacity","0").hide();
	$("#overlay").show().animate({
			opacity: "0.5"
	},500);
	$("body").css("background", "#212121");
}

function hideOverlay() {
	$("#overlay").customFadeOut();
	$("body").css("background", "#63686A");
}	



// Homepage strip animation
$(document).ready(function(){
	$("#stripeani").animate({
		height: 0
	}, 2000);
});


// Page Fade out
$(document).ready(function(){
	//if(!$.browser.msie) {
		$(".mainPad, .projImage").hide().customFadeIn(2000);
	//}
});


// Homepage Animation

$(document).ready(function(){
	if ($("body").hasClass("s-home"))
	{
		if ($.cookie("visited") == null)
		{
			// Draw Flash div
			$("#container").prepend("<div id='homepage-construct'></div>");
			// SWFObject Code
			var so = new SWFObject("/images/flash/homepage-construct.swf", "homepage-construct", "974", "550", "6", "#fff");
			so.addParam("wmode","transparent");
			so.write("homepage-construct");
			setTimeout(function(){
				$("#main").show();
			}, 1000);
		} else {
			$("#main").show();
		}
		$.cookie("visited","visited");
	}
});

function hideflash() {
	$("#homepage-construct").hide();
}



