// let's do this
Cufon.replace('h1');

$(function(){
	$.ajax({
		type: "GET",
		url: "/featured.xml",
		dataType: "xml",
		success: parseXml
	})
	// top tab dropdowns
	$('#tabs li:has(div)').hover(
		function() { $('div:first', this).fadeIn(); },
		function() { $('div', this).hide(); }
	);
	// secondary nav dropdowns
	$('#secondarymenu li:has(ul)').hover(
		function() { $('ul:first', this).fadeIn(); },
		function() { $('ul', this).hide(); }
	);
	
	// random quotes for blue strip
	var totalNum = $("#bluestrip span").size();
	var randomNum = Math.floor(Math.random()*totalNum);
	$('#bluestrip span:eq(' + randomNum + ')').css("display", "block");
	
	if ($(".thumbs").length) {
		$(".thumbs a").click(function(){
			var enlarged = $(this).attr("href");
			$("#enlarged img").attr({src:enlarged});
			$("#clientinfo").append();
			return false;
		});
	}
	
	if ($(".enlarged").length) {
	$(document).ready(function() {	
	$('.image_thumb a').each(function(){
		$('<img/>')[0].src = $(this).attr('href');
	});
	//Show Banner
	$(".enlarged .desc").show(); //Show Banner
	$(".enlarged .block").animate({ opacity: 0.85 }, 1 ); //Set Opacity

	//Click and Hover events for thumbnail list
	$(".image_thumb ul li:first").addClass('active'); 
	$(".image_thumb ul li").click(function(){ 
		//Set Variables
		var imgAlt = $(this).find('img').attr("alt"); //Get Alt Tag of Image
		var imgTitle = $(this).find('a').attr("href"); //Get Main Image URL
		var imgDesc = $(this).find('.block').html(); 	//Get HTML of block
		var imgDescHeight = $(".enlarged").find('.block').height();	//Calculate height of block	
		
		if ($(this).is(".active")) {  //If it's already active, then...
			return false; // Don't click through
		} else {
			//Animate the Teaser				
			$(".enlarged .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 , function() {
				$(".enlarged .block").html(imgDesc).animate({ opacity: 0.85,	marginBottom: "0" }, 250 );
				$(".enlarged img").attr({ src: imgTitle , alt: imgAlt});
			});
		}
		
		$(".image_thumb ul li").removeClass('active'); //Remove class of 'active' on all lists
		$(this).addClass('active');  //add class of 'active' on this list only
		return false;
		
	}) .hover(function(){
		$(this).addClass('hover');
		}, function() {
		$(this).removeClass('hover');
	});
	
});
	}
});

function parseXml(xml){
	var totalClients = $(xml).find("project").length;
	var randomClient = Math.floor(Math.random()*totalClients);
	$(xml).find("project").each(function() {
    	$("#featuredclient").append(
			"<div><a href='" + $(this).find("link").text() + "' target='_blank'><img src='/images/featured/" + $(this).find("image").text() + "' alt='"  + $(this).find("title").text() + "' /><span class='clientname'>"  + $(this).find("title").text() + "</span></a></div>"
		);
  	})
	$('#featuredclient div:eq(' + randomClient + ')').show();
}