$(document).ready(function() {

	/* Main Navigation Dropdown */
	$('#header ul li a').hover(function() {
			$(this).parent().children('ul').show();
			$(this).addClass('active');
		},
		function() {
			$(this).parent().children('ul').hide();
			$(this).removeClass('active');
	});
	$('#header ul li ul').hover(function() {
			$(this).show();
			$(this).parent().children('a').addClass('active');
		},
		function() {
			$(this).hide();
			$(this).parent().children('a').removeClass('active');
	});
	
	/* Peer Navigation Hover */
	$('#activeBar').css({
		'top' : ($('#peer_nav ul li').offset().top - 20)+'px'});
		
	$('#peer_nav ul li').hover(function(){
			$('#activeBar').animate({top : ($(this).offset().top - 20)+'px', height : $(this).height()+'px'}, 50);
			$('#activeBar').css('display', 'block');
		},
		function(){

		});
	$('#peer_nav ul').hover(function(){
			$('#activeBar').animate({opacity : '0.8'}, 200);		
		},
		function(){
			$('#activeBar').animate({opacity : '0'}, 200);					
		});

	/* Services Hover */
	$('#services ul li').hover(function() {			
			switch($(this).attr('id')) {
				case 'management':
					color = '#0073AE'
					break;
				case 'development':
					color = '#8BC53E'
					break;
				case 'commercial':
					color = '#007C85'
					break;
				case 'about':
					color = '#cc6600'
					break;
				default:
					color = '#FFFFFF'
					break;
			}
			switch($(this).attr('class')) {
				case 'community_centers':
					color = '#4C721D'
					break;
				case 'medical':
					color = '#00A160'
					break;
				case 'corporate':
					color = '#00A0AF'
					break;
				case 'higher_education':
					color = '#695E4A'
					break;
				case 'multi_tenant':
					color = '#455560'
					break;
				case 'commercial_health_club':
					color = '#362C66'
					break;
				default:
					break;
			}
			
			$(this).addClass('active');			
			$(this).children('div').animate({backgroundColor: color}, 200);
			if($.support.style) {
				$(this).find('.colorbar').animate({opacity : '0.5'}, 200);
			}
			
		},
		function() {
			$(this).removeClass('active');
			$(this).children('div').animate({backgroundColor: '#FFFFFF'}, 200);
			if($.support.style) {
				$(this).find('.colorbar').animate({opacity : '0.5'}, 200);
			}
	});
	$('#services ul li').click(function() {
		window.location = $(this).children('div').children('h3').children('a').attr('href');
	});	
});


$(window).load(function() {
	//Load all images first
	if($('body').attr('id') == 'home') {	
		init_promo()		
	}
})
function init_promo() {
	$('#promo').cycle({
		fx: 'scrollHorz',
		timeout: 0,
		speed: 1500,
		prev: "#previous",
		next: "#next",
		easing: 'easeOutSine',
		before: onBefore,
		after: onAfter
	})
}
function onBefore() {
	$('p#count').fadeOut(300);
	$('div#current_caption').fadeOut(300);
}
function onAfter(curr, next, opts) {
	$('p#count').html((opts.currSlide + 1) + ' / ' + opts.slideCount).fadeIn(300);
	var str = $('div.slide_caption', next).html();
	$('div#current_caption').html(str).fadeIn(300);
}

//If we are not running IE6, activate sIFR
if(window.XMLHttpRequest) {
	var din = { src: '/assets/swf/DIN.swf' };
	var din_bold = { src: '/assets/swf/DIN_bold.swf' };

	sIFR.activate(din, din_bold);

	//We are not using sIFR on the promo due to the time involved in creating a workaround for the slideshow.
	/*
	sIFR.replace(din_bold, {
		selector: '#promo h2',
		css: '.sIFR-root { color: #FFFFFF; leading: -10; letter-spacing: -2; }',
		wmode: 'transparent'
	});
	*/
	
	sIFR.replace(din_bold, {
		selector: '#service_header h2',
		css: '.sIFR-root { color: #FFFFFF; leading: -10; letter-spacing: -2; }',
		wmode: 'transparent'
	});
	sIFR.replace(din_bold, {
		selector: '#peer_nav h2',
		css: '.sIFR-root { color: #FFFFFF; leading: -5;}',
		wmode: 'transparent'
	});
	sIFR.replace(din_bold, {
		selector: '#details h3',
		css: '.sIFR-root { color: #0073AE; leading: -10; letter-spacing: -1; }',
		wmode: 'transparent'
	});
}



