$(document).ready(function(){
	
	//Work Rotation
	$('ul.rotation').cycle();	
	$('#trophies').cycle();
	
	//Navigation hover
	$('#navigation ul li').hover(function(){
		$(this).addClass('hover');
	}, function(){
		$(this).removeClass('hover');
	});
	
	// Title Hover
	var title = $('#logo a').html();
	$('#logo a').empty().css('opacity', 1);
	$('<div>' + title +'</div>').css({
						background: "url('css/images/logo-blur.jpg')",
						width: '100%',
						height: '100%',
						display: 'block',
						opacity: 0
					})
					.appendTo('#logo a');
	$('#logo a div').hover(function(){
						$(this).animate({opacity: 1});
					},function(){
						$(this).animate({opacity: 0});
					});
					
	// Tagline Animate
	$('#header h3 span').fadeTo(0,0);
	$('#experienced').fadeTo(2000, 1, function(){
		if(jQuery.browser.msie) this.style.removeAttribute("filter");
		$('#creative').fadeTo(1200, 1, function(){
			if(jQuery.browser.msie) this.style.removeAttribute("filter");
			$('#successful').fadeTo(1200, 1, function(){
				if(jQuery.browser.msie) this.style.removeAttribute("filter");
			});
		});
	});
	
	// Awards
	var featuredAward;
	var slidespeed = 800;
	$('#awardtitleholder').children().fadeOut();
	
	var thetop = 251;
	var top = 292;
	$('.awardslist li').each(function(){
		$(this).css({
			position: 'absolute',
			top: top + 'px',
			width: '100%'
		}).data('naturaltop', top + 'px');
		top = top + 30;
	});
	
	$('.awardslist li:first').each(function(){
		
		featuredAward = $(this);
		
		//If a hyperlink exists from previous slide, remove it
		if( $('#awardimage a').size() > 0 )
			$('#awardimage').html( $('#awardimage a').html() );
			
		$('#awardimage img').fadeOut((slidespeed / 2), function(){
			
			//Explode REL... first = image src, second = video src
			var parts = featuredAward.attr('rel').split("|");
			var imageSrc = parts[0];
			
			//Set image src
			$(this).attr('src',parts[0]);
			
			//If video available, wrap in hyperlink for ThickBox
			if( parts.length > 1 ){
				$(this).wrap("<a href='" + base_url + "video.php?video=" + parts[1] + "&amp;TB_iframe=true&amp;height=400&amp;width=600' class='thickbox' title=''></a>");
				tb_init('a.thickbox');
			}
			$(this).fadeIn(slidespeed / 2);
			
		});
		$(this).animate({
			top: '251px'
		}, slidespeed);
	});

	$('.awardslist li').click(function(){
		
		//If a hyperlink exists from previous slide, remove it
		if( $('#awardimage a').size() > 0 )
			$('#awardimage').html( $('#awardimage a').html() );
			
		featuredAward.animate({
			top: featuredAward.data('naturaltop')
		}, slidespeed);
		featuredAward = $(this);
		
		//Fade out image
		$('#awardimage img').fadeOut((slidespeed / 2), function(){
			
			//Explode REL... first = image src, second = video src
			var parts = featuredAward.attr('rel').split("|");
			var imageSrc = parts[0];
			
			//Set image src
			$(this).attr('src',parts[0]);
			
			//If video available, wrap in hyperlink for ThickBox
			if( parts.length > 1 ){
				$(this).wrap("<a href='" + base_url + "video.php?video=" + parts[1] + "&amp;TB_iframe=true&amp;height=400&amp;width=600' class='thickbox' title=''></a>");
				tb_init('a.thickbox');
			}
			$(this).fadeIn(slidespeed / 2);
			
		});
		$(this).animate({
			top: thetop + 'px'
		}, slidespeed);
	});
	
	//Fix awards list menu
	if( $('#awardsList').size() > 0)
		$('#awardsList li').each(function(){ $(this).prependTo( $(this).parent() ) });
	
});