// Home Slideshow
$(function(){
	$('#background').cycle({
		timeout: 10000
	});
	$('#slideshow .slides').cycle({
		pager: '#slideshow .nav .wrap',
		timeout: 10000
	});	
	$('#slideshow .nav a').click(function(){
		var slide = $(this).index('#slideshow .nav a');
		$('#background').cycle(slide);
	});
});

// Drop Down Nav
$(function(){
	$("#header .nav li:first").hoverIntent({ 
		timeout: 500,      
		over: function(){
			$("ul:first",this).stop(true,true).fadeIn();
			$("#header .nav li:first").addClass('hover');
		},
		out: function(){
			$("ul:first",this).stop(true,true).fadeOut();
			$("#header .nav li:first").removeClass('hover');
		}
	});	
});

// Nav Style Fix
$(function(){
	$('#header .nav li li:nth-child(3)').css('background','#333');
	$('#header .nav li li li:nth-child(3)').css('background','none');
});

// Overlays
$(function(){
	$('#overlay').css('opacity','0.5');
	// Slideshow
	$('#slideshow .slides .aslide a').click(function(){
		var overlay = $(this).parent().index('#slideshow .slides div');
		$('#overlay').fadeIn();
		$('#overlays').fadeIn();
		$('#overlays div').hide();
		$('#overlays div:eq('+overlay+')').show();
		return false;
	});
	// Other
	$('.overlay').click(function(){
		var id = $(this).attr('id');
		$('#overlay').fadeIn();
		$('#overlays').fadeIn();
		$('#overlays div').hide();
		$('#overlays div.'+id).show();
		return false;
	});
	var hover = false;
	$('#overlays div').hover(function(){ 
		hover = true; 
	},function(){ 
		hover = false; 
	});
	$("body").mouseup(function(){ 
		if(!hover) $('#overlay, #overlays').fadeOut();
	});
	$('#overlays .close').click(function(){
		$('#overlay, #overlays').fadeOut();
		return false;
	});
});

// Content Tabs
$(function(){
	$('#content .tablist ul a').click(function(){
		$('#content .tablist ul a').removeClass('active');
		$(this).addClass('active');
		var tab = $(this).parent().index('#content .tablist ul li');
		$('#content .tab').hide();
		$('#content .tab:eq('+tab+')').show();
		return false;
	});
});

// Content Tabs Hash
$(function(){
	if(window.location.hash != ''){
		var hash = window.location.hash.substring(1);
		if(hash == 'case-studies'){var tab = 0};
		if(hash == 'multimedia-assets'){var tab = 1};
		if(hash == 'thought-leadership'){var tab = 2};
		if(hash == 'sales-enablement'){var tab = 3};
		$('#content .tablist ul a').removeClass('active');
		$('#content .tablist ul li:eq('+tab+') a').addClass('active');
		$('#content .tab').hide();
		$('#content .tab:eq('+tab+')').show();
		return false;
	}
});

// Content Toggle
$(function(){
	$('#content h2 span a, #content h3 span a').toggle(function(){
		$(this).text('[hide]');
		$(this).parent().parent().nextAll('.toggle').first().show();
		return false;
	}, function(){
		$(this).text('[show]');
		$(this).parent().parent().nextAll('.toggle').first().hide();
		return false;
	});
});

// Map Embed
$(function(){
	$('#content .tablist ul a.mapembed').click(function(){
		$('#mapembed').html('<iframe width="523" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps/ms?hl=en&amp;ie=UTF8&amp;msa=0&amp;msid=212861431304320009225.00048e45acf5921cf0e78&amp;source=embed&amp;vpsrc=6&amp;ll=44.087585,0.703125&amp;spn=143.512909,7.734375&amp;z=1&amp;output=embed"></iframe>')
	});
});
