
/*******************************************************************************************************************
	COMMON JAVASCRIPT USED ON MULTIPLE OR ALL PAGE
********************************************************************************************************************/
var pageHeight = "";
var columnHeight = "";
var whichPage = "";
var randomBackground = "";
var threeThingsHeight = "";
function base(){	
	// set up transparent bg
	//$("body").prepend("<div class='bg-80'></div>");

	// fade in page (wrapper) content
	$("div.wrapper").fadeIn(500);
	//$("div.bg-80").height($("div.wrapper").height()+15);
	//$("div.bg-80").fadeIn(500);

	// set up random (of 1) background image load
	whichPage = $("body").attr("id");
	randomBackground = Math.floor(Math.random()*1)+1;
	$("body").addClass(whichPage+"-"+randomBackground);
		
	// if there are columns on the page, set them to equal height
	columnHeight = $("div.columns").height() - 60;
	$("div.column-left").css({height:columnHeight});
	$("div.column-right").css({height:columnHeight});

	// add any arrows and dividers appropriately
	$("div.header ul.nav li").after("<li class='divider'>|</li>");
	$("div.header ul.nav li.divider:last").remove();
	$(".arrow-11-orange").append("<span><img src='/images/arrow-11-orange.png' /></span>");
	$(".arrow-11-white").append("<span><img src='/images/arrow-11-white.png' /></span>");
	$(".arrow-8-white").append("<span><img src='/images/arrow-8-white.png' /></span>");
	
	// add empty HTML elements to "three things"
	$("div.three-things div.container").prepend("<a class='close'></a><div class='shadow'></div>");
	
	// set up "three things" height by finding height of tallest column, adding height for padding and height of headline
	$("div.three-things div.container div").each(function(){
		if ( $(this).innerHeight() > threeThingsHeight ){
			threeThingsHeight = $(this).height() + 100;
		}
	});
	
	// set up "three things" animation
	$("div.three-things h1").click(function(){
		$("div.three-things div.container").addClass("open")
		$("div.three-things div.container").animate({height:threeThingsHeight}, 400)
	});
	$("div.three-things a.close").click(function(){
		$("div.three-things div.container").removeClass("open")
		$("div.three-things div.container").animate({height:"42px"}, 400)
	});

}

/*******************************************************************************************************************
	HOMEPAGE ROTATION SPECIFIC JAVASCRIPT
********************************************************************************************************************/
var rotateCounter = "0";
var controlCounter = "0";
var keepRunning = true;
var rotatePosition = "0";
function homepage(){
	// activate entire homepage-left callout
	$("div.homepage-left").click(function () {
		var url = $(this).find("a").attr('href');
		window.location = url;
	}); 	
	
	// to handle intricate laying involved with homepage rotation, add white background for header
	$("div.header").css({background:"none"});
	$("div.wrapper").prepend("<div class='bg-header'></div>");
	
	//activate entire rotation area for link	
	$("div.homepage-flash ul.rotate li.click").css({cursor:"pointer"});
	$("div.homepage-flash ul.rotate li.click").click(function () {
		var url = $(this).find("a").attr('href');
		window.location = url;
	}); 	
	// add empty html elements to flash rotation
	$("div.header").prepend("<div class='shadow-left'></div><div class='shadow-right'></div>");
	$("div.homepage-flash").prepend("<div class='shadow'></div>");
	$("div.homepage-flash ul.control li").prepend("<div class='arrow'></div>");
	
	// find number of rotations, width of rotator
	$("div.homepage-flash ul.rotate li").each(function(){
		rotateCounter++;
		$("div.homepage-flash ul.rotate").css({width:rotateCounter*900});
	});
	$("div.homepage-flash ul.control li").each(function(){
		controlCounter++;
	});
	if (rotateCounter != controlCounter){
		alert("You need to have the same number of rotations as you have control items");
	}

}

/*******************************************************************************************************************
	HOMEPAGE ROTATION SPECIFIC JAVASCRIPT (continued)
********************************************************************************************************************/
function switchContent(){
	if (keepRunning){
		if ( rotatePosition < rotateCounter ){
			$("div.homepage-flash ul.rotate").animate({left:rotatePosition*-900},500);
			rotatePosition++;
			$("div.homepage-flash ul.control li."+rotatePosition).siblings("li").removeClass("active");
			$("div.homepage-flash ul.control li."+rotatePosition).addClass("active");
		}
		else{
			rotatePosition = "1";
			$("div.homepage-flash ul.rotate").animate({left:"0px"},500);
			$("div.homepage-flash ul.control li."+rotatePosition).siblings("li").removeClass("active");
			$("div.homepage-flash ul.control li."+rotatePosition).addClass("active");
		}
		setTimeout('switchContent()', 7500);
	}
	
	$("div.homepage-flash ul.control li").click(function(){
		keepRunning = false;
		rotatePosition = $(this).attr("class");
		if( $(this).hasClass("active") == false ){
			$("div.homepage-flash ul.control li."+rotatePosition).addClass("active");
			$("div.homepage-flash ul.control li."+rotatePosition).siblings("li").removeClass("active");
			$("div.homepage-flash ul.rotate").animate({left:(rotatePosition-1)*-900},500);
		}
	});
}

/*******************************************************************************************************************
	PORTFOLIO SPECIFIC JAVASCRIPT
********************************************************************************************************************/
var caseStudiesHeight = "";
var caseType = "";
function portfolio(){	

	// set height of pull down 
	caseStudiesHeight = $("div.studies div.container table").height() + 74;
	
	// set up "case studies selector" animation
	if ( $("body").hasClass("portfolio-home") == false ){
		$("div.studies h1.open").after("<h1 class='close'>Case Studies</h1>");
		$("div.studies h1.open").click(function(){
			$("div.studies div.container").animate({height:caseStudiesHeight}, 400);
			$(this).hide();
			$(this).siblings("h1.close").show();
		});
		$("div.studies h1.close").click(function(){
			$("div.studies div.container").animate({height:"24px"}, 400);
			$(this).hide();
			$(this).siblings("h1.open").show();
		});
	}
	
	// set up "case studies filter"
	$("div.studies ul li").click(function(){
		$(this).toggleClass("active");
		$(this).siblings("li").removeClass("active");
		caseType = this.id;
		$("div.studies table td").children("a").fadeTo(200, .2);
		$("div.studies table td."+caseType).children("a").fadeTo(200, 1);
	});
	
	// find number of rotations, width of rotator
	$("div.portfolio-flash ul.rotate li").each(function(){
		rotateCounter++;
		$("div.portfolio-flash ul.rotate").css({width:rotateCounter*880});
		rotatePosition = "1";
	});
	
	$("div.portfolio-flash ul.control li.next").click(function(){
		if (rotatePosition < rotateCounter){
			rotatePosition++;
			if(rotatePosition == 1){ $("div.portfolio-flash ul.control li.back").fadeOut(); }
			if(rotatePosition != 1){ $("div.portfolio-flash ul.control li.back").fadeIn(); }
			if(rotatePosition == rotateCounter){ $("div.portfolio-flash ul.control li.next").fadeOut(); }
			if(rotatePosition < rotateCounter){ $("div.portfolio-flash ul.control li.next").fadeIn(); }
			$("div.portfolio-flash ul.rotate").animate({left:(rotatePosition-1)*-880},500);
		}
	});
	$("div.portfolio-flash ul.control li.back").click(function(){
		if (rotatePosition > 1 ){
			rotatePosition--;
			if(rotatePosition == 1){ $("div.portfolio-flash ul.control li.back").fadeOut(); }
			if(rotatePosition != 1){ $("div.portfolio-flash ul.control li.back").fadeIn(); }
			if(rotatePosition == rotateCounter){ $("div.portfolio-flash ul.control li.next").fadeOut(); }
			if(rotatePosition < rotateCounter){ $("div.portfolio-flash ul.control li.next").fadeIn(); }
			$("div.portfolio-flash ul.rotate").animate({left:(rotatePosition-1)*-880},500);
		}
	});
}

/*******************************************************************************************************************
	GALLERY
********************************************************************************************************************/
var caseStudiesHeight = "";
var caseType = "";
function gallery(){	
	
	// set up "case studies filter"
	$("div.studies ul li").click(function(){
		$(this).toggleClass("active");
		$(this).siblings("li").removeClass("active");
		caseType = this.id;
		$("div.studies table td").children("a").fadeTo(200, .2);
		$("div.studies table td."+caseType).children("a").fadeTo(200, 1);
	});
	
	// find number of rotations, width of rotator
	$("div.gallery ul.rotate li").each(function(){
		rotateCounter++;
		$("div.gallery ul.rotate").css({width:rotateCounter*1000});
		rotatePosition = "1";
	});
	
	$("div.gallery ul.control li.next").click(function(){
		if (rotatePosition < rotateCounter){
			rotatePosition++;
			if(rotatePosition == 1){ $("div.gallery ul.control li.back").fadeOut(); }
			if(rotatePosition != 1){ $("div.gallery ul.control li.back").fadeIn(); }
			if(rotatePosition == rotateCounter){ $("div.gallery ul.control li.next").fadeOut(); }
			if(rotatePosition < rotateCounter){ $("div.gallery ul.control li.next").fadeIn(); }
			$("div.gallery ul.rotate").animate({left:(rotatePosition-1)*-1000},500);
		}
	});
	$("div.gallery ul.control li.back").click(function(){
		if (rotatePosition > 1 ){
			rotatePosition--;
			if(rotatePosition == 1){ $("div.gallery ul.control li.back").fadeOut(); }
			if(rotatePosition != 1){ $("div.gallery ul.control li.back").fadeIn(); }
			if(rotatePosition == rotateCounter){ $("div.gallery ul.control li.next").fadeOut(); }
			if(rotatePosition < rotateCounter){ $("div.gallery ul.control li.next").fadeIn(); }
			$("div.gallery ul.rotate").animate({left:(rotatePosition-1)*-1000},500);
		}
	});
}

/*******************************************************************************************************************
	NEWS SPECIFIC JAVASCRIPT
********************************************************************************************************************/
function news(){
	// left hand column modifications for first, even, and odd news items
	$("div.news td.highlights div:odd").addClass("highlight-2");
	$("div.news td.highlights div:even").addClass("highlight-3");
	$("div.news td.highlights div:first").removeClass("highlight-3");
	$("div.news td.highlights div:first").addClass("highlight-1");

// remove bottom stroke from last news item in right column
	$("div.news td.main div.highlight:last").addClass("last");
	
	// add close buttons on the fly to collapsable news items
	$("div.news td.main div.highlight div.content").append("<a class='close'>Close</a>");

// expand news items
	$("div.news div.highlight a.open").click(function(){
		// slide down content and adjust height of white background
		$(this).siblings("div.full").slideDown(300, function(){
			$("div.bg-80").height($("div.wrapper").height()+15);
		});
		$(this).parent("div.content").parent("div.highlight").siblings("div.highlight").children("div.content").children("div.full").slideUp(300);		// slide up all other content
		$("a.close").hide();																															// hide all close buttons
		$("a.open").show();																																// show all open buttons
		$(this).hide();																																	// hide the clicked "open" button
		$(this).siblings("a.close").show();																												// show the clicked buttons "close" counterpart

		
	});
	$("div.news div.highlight a.close").click(function(){
		$(this).siblings("div.full").slideUp(300);		// slide up content
		$(this).hide();									// hide the clicked "close" button
		$(this).siblings("a.open").show();				// show the clicked buttons "close" counterpart
	});
}



/*******************************************************************************************************************
	25 YEARS SPECIFIC JAVASCRIPT
********************************************************************************************************************/
function years_25(){
	// left hand column modifications for first, even, and odd news items
	$("div.years_25 td.highlights div:odd").addClass("highlight-2");
	$("div.years_25 td.highlights div:even").addClass("highlight-3");
	$("div.years_25 td.highlights div:first").removeClass("highlight-3");
	$("div.years_25 td.highlights div:first").addClass("highlight-1");

// remove bottom stroke from last news item in right column
	$("div.years_25 td.main div.highlight:last").addClass("last");
	
	// add close buttons on the fly to collapsable news items
	$("div.years_25 td.main div.highlight div.content").append("<a class='close'>Close</a>");

// expand news items
	$("div.years_25 div.highlight a.open").click(function(){
		// slide down content and adjust height of white background
		$(this).siblings("div.full").slideDown(300, function(){
			$("div.bg-80").height($("div.wrapper").height()+15);
		});
		$(this).parent("div.content").parent("div.highlight").siblings("div.highlight").children("div.content").children("div.full").slideUp(300);		// slide up all other content
		$("a.close").hide();																															// hide all close buttons
		$("a.open").show();																																// show all open buttons
		$(this).hide();																																	// hide the clicked "open" button
		$(this).siblings("a.close").show();																												// show the clicked buttons "close" counterpart

		
	});
	$("div.years_25 div.highlight a.close").click(function(){
		$(this).siblings("div.full").slideUp(300);		// slide up content
		$(this).hide();									// hide the clicked "close" button
		$(this).siblings("a.open").show();				// show the clicked buttons "close" counterpart
	});
}

/*******************************************************************************************************************
	ABOUT SPECIFIC JAVASCRIPT
********************************************************************************************************************/
var newsItem = "";
var aboutStrDelim = "#";
function getParm(aboutStrUrl){
  var vals = aboutStrUrl.split(aboutStrDelim);
  return vals[vals.length - 6];
}
function george(){
	newsItem = (getParm(""+window.location));
	if ( newsItem == 'george'){ 
		$("div#shade-4").addClass("active");
		$("div#shade-8 div.shade-content").hide();
		$("div#shade-8").removeClass('active');
		$("div#shade-4").children("div.shade-content").show();	
		$("div#shade-4 div.shade-content").load("/about/shades/shade-4.shtml", function(){
			$(this).children("div.hidden").fadeIn();
			$('#shade-4 .shade-content ul').css('margin-left','-1800px');	
		});
	}
}


var aboutWhichShade = "";
var aboutStrDelim = "#";
function getParm(aboutStrUrl){
  var vals = aboutStrUrl.split(aboutStrDelim);
  return vals[vals.length - 1];
}

function about(){
	aboutWhichShade = (getParm(""+window.location));
	// if # and the number is between 1 and 8, opent he appropriate shade
	if ( aboutWhichShade > 0 && aboutWhichShade <= 8 ) {
		$("div#shade-"+aboutWhichShade).addClass("active");	
		$("div#shade-"+aboutWhichShade).children("div.shade-content").show();	
		$("div#shade-"+aboutWhichShade+" div.shade-content").load("/about/shades/shade-"+aboutWhichShade+".shtml", function(){
			$(this).children("div.hidden").fadeIn();
		});
	}
	// set default if # and the number is not between 1 and 8 or no #
	else{
		$("div#shade-8").addClass("active");	
		$("div#shade-8").children("div.shade-content").show();	
		$("div#shade-8 div.shade-content").load("/about/shades/shade-8.shtml", function(){
			$(this).children("div.hidden").fadeIn();
		});
	};

	$("div.shade-content").append("<div class='loading'></div>")
	
	$("div.shade h2").hover(
		function () { $(this).addClass("hover"); }, 
		function () { $(this).removeClass("hover"); }
    );
	
	$("div.shade h2").click(function(){
		$(this).parent("div.shade").siblings("div.shade").removeClass("active");						// remove active state from all other shades
		$(this).parent("div.shade").addClass("active");													// add active state to this shade
		$(this).parent("div.shade").siblings("div.shade").children("div.shade-content").slideUp(200);	// slide up all other shades
		$(this).parent("div.shade").children("div.shade-content").slideDown(200);						// slide down this shade
		// load content into window shade
		$(this).siblings("div.shade-content").load("/about/shades/"+$(this).parent("div.shade").attr("id")+".shtml", function(){
			$(this).children("div.hidden").fadeIn();
		});
	});	
}

/*******************************************************************************************************************
	CONTACT SPECIFIC JAVASCRIPT
********************************************************************************************************************/
var contactWhichShade = "";
var contactStrDelim = "#";
function getParm(contactStrUrl){
  var vals = contactStrUrl.split(contactStrDelim);
  return vals[vals.length - 1];
}

function contact(){
	contactWhichShade = (getParm(""+window.location));
	// if # and the number is between 1 and 4, opent he appropriate shade
	if ( contactWhichShade > 0 && contactWhichShade <= 4 ) {
		$("div#shade-"+contactWhichShade).addClass("active");	
		$("div#shade-"+contactWhichShade).children("div.shade-content").show();	
		$("div#shade-"+contactWhichShade+" div.shade-content").load("/contact/shades/shade-"+contactWhichShade+".shtml", function(){
			$(this).children("div.hidden").fadeIn();
		});
	}
	// set default if # and the number is not between 1 and 4 or no #
	else{
		$("div#shade-1").addClass("active");	
		$("div#shade-1").children("div.shade-content").show();	
		$("div#shade-1 div.shade-content").load("/contact/shades/shade-1.shtml", function(){
			$(this).children("div.hidden").fadeIn();
		});
	};
	
	$("div.shade-content").append("<div class='loading'></div>")
	
	$("div.shade h2").hover(
		function () { $(this).addClass("hover"); }, 
		function () { $(this).removeClass("hover"); }
    );
	
	$("div.shade h2").click(function(){
		$(this).parent("div.shade").siblings("div.shade").removeClass("active");						// remove active state from all other shades
		$(this).parent("div.shade").addClass("active");													// add active state to this shade
		$(this).parent("div.shade").siblings("div.shade").children("div.shade-content").slideUp(200);	// slide up all other shades
		$(this).parent("div.shade").children("div.shade-content").slideDown(200);						// slide down this shade
		// load content into window shade
		$(this).siblings("div.shade-content").load("/contact/shades/"+$(this).parent("div.shade").attr("id")+".shtml", function(){
			$(this).children("div.hidden").fadeIn();
		});
	});	
}


/*******************************************************************************************************************
	HOMEPAGE TWITTER-FEED JAVASCRIPT
********************************************************************************************************************/
function expand(){
	$('a.expand').click(function() {
		if ( $(this).hasClass("close") == false ) {
			$('div.homepage-right').animate({ bottom: '+=0', height: '500px' }, 800, function() {} );
				$('a.expand').addClass('close');	
				$('a.expand').text('x');
		}
		else {
			$('div.homepage-right').animate({ bottom: '+=0', height: '157px' }, 800, function() {} );
				$('a.expand').removeClass('close');	
				$('a.expand').text('+');
		}
	});
}

function twitter() {
	// initialize twitter
	$("div.twitter").tweet({
		username: "worxbranding",
		join_text: "auto",
		avatar_size: 48,
		count: 8,
		auto_join_text_default: "",
		auto_join_text_ed: "",
		auto_join_text_ing: "",
		auto_join_text_reply: "",
		auto_join_text_url: "",
		loading_text: ""
	});
}

var tweetCounter = "0";
function tweets() {	
	$(".tweets").each(function(){
		tweetCounter++;
	});
	$(".tweets").css({height:tweetCounter * 800});
	$('.tweets').twitterSearch({ 
	}); 
}




