$(window).load(function () {

});

$(document).ready(function(){
	
	$('#tabSelect a[rel="mapView"]').click(function() {
	
		$('#tabSelect .active').removeClass('active');
		$(this).addClass('active');
	
		$('.tabList').removeClass('active');
		$('.tabMap').addClass('active')
	
		return false;
	});
	
	$('#tabSelect a[rel="listView"]').click(function() {
	
		$('#tabSelect .active').removeClass('active');
		$(this).addClass('active');
	
		if( $('.tabList').has('.active') ) {
			$('.tabList ol').removeClass('galleryView').addClass('listView');
		}
	
		if( $('.tabMap').has('.active') ) { 
			$('.tabMap').removeClass('active');
			$('.tabList').addClass('active');
		}
		
		return false;
	
	});
	
	$('#tabSelect a[rel="galleryView"]').click(function() {
	
		$('#tabSelect .active').removeClass('active');
		$(this).addClass('active');
		
		if( $('.tabList').has('.active') ) {
			$('.tabList ol').removeClass('listView').addClass('galleryView');
		}
		
		if( $('.tabMap').has('.active') ) { 
			$('.tabMap').removeClass('active');
			$('.tabList').addClass('active');
		}
				
		return false;
	
	});
	
	$('#csNav a').click(function() {
	
		$('#csNav a.current').removeClass('current');
		$(this).addClass('current');
		var rel = $(this).attr("rel");
//		alert(rel);
		
		$('.slideHolder .current').removeClass('current');
		$('#' + rel ).addClass('current');
		
		return false;
		
	})
	
	var featuredProductsPrev = $('#prevFeat'),
				featuredProductsNext = $('#nextFeat'),
				slideWidth = 340,
				holderPosition = 0,
				holder = $('#featList ol');
					
			var elementWidthTotal = holder.children().length * slideWidth;
				
		    holder.width(elementWidthTotal);
			
			featuredProductsNext.bind('click', function() {
				
				if((holderPosition-slideWidth) > -(elementWidthTotal)) {
				
					holderPosition = holderPosition - slideWidth;
					holder.animate({ 'left': holderPosition + 'px' }, {duration:800, easing: 'easeOutCirc'});				
									}
				
				
				return false;
					
			});
			
			featuredProductsPrev.bind('click', function() {
				
				if(holderPosition < 0) {
			
					holderPosition = holderPosition + slideWidth;
					holder.animate({ 'left': holderPosition + 'px' }, {duration:800, easing: 'easeOutCirc'});
					
				}
			
				return false;
				
			});
	
	
	function equalHeight(group) {
	         tallest = 0;
	         group.each(function() {
	             thisHeight = $(this).height();
	             if(thisHeight > tallest) {
	                 tallest = thisHeight;
	             }
	         });
	         group.height(tallest);
	     }
	
	equalHeight($(".contentCol"));
	equalHeight($(".questionSection, .specialSection, .newsletterBlock"));
	

	if ($("#aside img").length) {
		$("#aside img").imgCenter({
				scaleToFit: false,
				centerVertical: true
			});
	}
	
	
	$('.selectCaption').live('click', function() {
		$(this).parent().find("ol").toggle();
		return false;
	});	
	
	$('.selectelectList a').live('click', function() {
		var ul = $(this).parent().parent()
		
		var valueReplace =  $(this).html();
		ul.prev().html(valueReplace);
		
		ul.parent().prev().val($(this).find("span.value").html())
		
		ul.hide();
		
		return false;
	});
	
	$('.funkySelect').each(function() {
		
		// $(this).hide();
		var inputSelect = $(this);
		var selectClass = $(this).attr('title');
		var selected = $(this).find("option[selected]");
		var options = $(this).find("option");
				
		var funkySelectHtml = '<div class="selectHolder' + " " + selectClass + '"></div>';	
		$(this).after(funkySelectHtml);
		
		$(this).next('.selectHolder').append('<a class="selectCaption" href="#">' + selected.text() + '<span class="value">' + selected.val() + '</span></a>');
		$(this).next('.selectHolder').append('<ol class="selectelectList listClear"></ol>');
		
		options.each(function(){
			$(this).parent().next('.selectHolder').find('.selectelectList').append('<li><a href="#">' + $(this).text() + '<span class="value">' + $(this).val() + '</span></a></li>');
		});
	
		$(this).hide();
		
	});
	
});

