$(document).ready(function () {
	
	//alert(SITE_URI);
	
	if(SITE_URI == 'home' && segTwo == ''){
			$('.subNav li:first.first').addClass('active');
	}
		
	$(".equalHeight").equalHeight();
	
	$('ul.subNav li.hasChildren div').hide();
	
	if($('ul.subNav li.hasChildren div ul li.active').parent().parent().is(':hidden')){
		$('ul.subNav li.hasChildren div ul li.active').parent().parent().show();
	};
	
	$('ul.subNav li.hasChildren a').click(function () {
		if($(this).siblings('div').is(':hidden')){
			$('ul.subNav li.hasChildren').removeClass('opened');
			$('ul.subNav li.hasChildren div').slideUp();
			$(this).parent('li.hasChildren').addClass('opened');
			$(this).siblings('div').slideDown();
		}else{
			$(this).parent('li.hasChildren').removeClass('opened');
			$(this).siblings('div').slideUp();
		}
	});
	
	$('#fader img:gt(0)').hide();
	$('#fader img:first').addClass('active');
	$('#fader div:gt(0)').hide();
	$('#fader div:first').addClass('active');
	$('#fader span:gt(0)').hide();
	$('#fader span:first').addClass('active');
	
	$('#fader img').css({'position':'absolute','top':0,'right':0});
	
	$('#fader img').click(function () {
			
		if($(this).next().size()>0){
			$(this).fadeOut(1000).removeClass('active').next('img').fadeIn(1000).addClass('active');
			$('#fader div.active').hide().removeClass('active').next('div').fadeIn(1000).addClass('active');
			$('#fader span.active').hide().removeClass('active').next('span').fadeIn(1000).addClass('active');
		}else{
			$(this).hide().removeClass('active');
			$('#fader img:first').fadeIn(1000).addClass('active');
			$('#fader div.active').hide().removeClass('active');
			$('#fader div:first').fadeIn(1000).addClass('active');
			$('#fader span.active').hide().removeClass('active');
			$('#fader span:first').fadeIn(1000).addClass('active');
		}
		
	});
	
	$('.fadercontrols a.prev').click(function () {
		if($('#fader img.active').prev().size()>0){
			$('#fader img.active').fadeOut(1000).removeClass('active').prev('img').fadeIn(1000).addClass('active');
			$('#fader div.active').hide().removeClass('active').prev('div').fadeIn(1000).addClass('active');
			$('#fader span.active').hide().removeClass('active').prev('span').fadeIn(1000).addClass('active');
		}else{
			$('#fader img.active').fadeOut(1000).removeClass('active');
			$('#fader img:last').fadeIn(1000).addClass('active');
			$('#fader div.active').hide().removeClass('active');
			$('#fader div:last').fadeIn(1000).addClass('active');
			$('#fader span.active').hide().removeClass('active');
			$('#fader span:last').fadeIn(1000).addClass('active');
		}
		var imgHeight = 0;
		imgHeight = $('#fader img.active').height();
		 $('#fader').css({'height':imgHeight+'px'});
		return false;
	});
	$('.fadercontrols a.next').click(function () {
		if($('#fader img.active').next().size()>0){
			$('#fader img.active').fadeOut(1000).removeClass('active').next('img').fadeIn(1000).addClass('active');
			$('#fader div.active').hide().removeClass('active').next('div').fadeIn(1000).addClass('active');
			$('#fader span.active').hide().removeClass('active').next('span').fadeIn(1000).addClass('active');
		}else{
			$('#fader img.active').fadeOut(1000).removeClass('active');
			$('#fader img:first').fadeIn(1000).addClass('active');
			$('#fader div.active').hide().removeClass('active');
			$('#fader div:first').fadeIn(1000).addClass('active');
			$('#fader span.active').hide().removeClass('active');
			$('#fader span:first').fadeIn(1000).addClass('active');
		}
		var imgHeight = 0;
		imgHeight = $('#fader img.active').height();
		 $('#fader').css({'height':imgHeight+'px'});
		return false;
	});
	
	setInterval(function () {
		var imgHeight = 0;
		 imgHeight = $('#fader img.active').height();
		 $('#fader').css({'height':imgHeight+'px'});
		   }, 100);
	
})






	
$.fn.equalHeight = function () {

			var height		= 0;
			var maxHeight	= 0;
		
			// Store the tallest element's height
			this.each(function () {
				height		= $(this).outerHeight();
				maxHeight	= (height > maxHeight) ? height : maxHeight;
			});
		
			// Set element's min-height to tallest element's height
			return this.each(function () {
				var t			= $(this);
				var minHeight	= maxHeight - (t.outerHeight() - t.height());
				var property	= $.browser.msie && $.browser.version < 7 ? 'height' : 'min-height';
		
				t.css(property, minHeight + 'px');
			});

};
