$(document).ready(function() {
	$('#products_sub_nav').css({width:'0px',display:'block'});
	//$('#zip_code').numeric();
		
	$('#slide_dots').tabs('#index_slides > div', {
		effect: 'fade',
		fadeOutSpeed: 500, 
		rotate: true
		}).slideshow({
			autoplay: true, 
			interval: 10000
			});

	$('#dealer_locator_trigger').click(function() {
		if ($('#locator_external_catcher').length == 0) {  
			$('body').prepend('<div id="locator_external_catcher">&nbsp;</div>');
		} else {
			$('#locator_external_catcher').remove();	
		}
		
		$('#dealer_locator_form_container').slideToggle('fast', function() {
			$('#dealer_locator_trigger').toggleClass('trigger_active');
		});
		return false;
	});
	
	$('#locator_external_catcher').live('click', function() {
		$('#dealer_locator_form_container').slideUp('fast', function() {
			$('#dealer_locator_trigger').toggleClass('trigger_active');
		});
		$(this).remove();
	});
	
	$('#counselor_trigger').click(function() {
		$('#product_counselor').toggle('fast');
	});
	
	//dealer locator form field label
	$(':text').labelify();
	
	$('#product_info_tabs').tabs('div#product_info_panes > div');
	
	//hover effects for product feature bullets
	$('.feature_bullet').hover(
		function() {//mouseover function
			var feature_id = $(this).attr('id').split('_');
			var id = feature_id[feature_id.length-1];
			$('#product_feature_thumb_' + id).toggleClass('active_feature');
		}, function() {//mouseout function
			var feature_id = $(this).attr('id').split('_');
			var id = feature_id[feature_id.length-1];
			
			$('#product_feature_thumb_' + id).toggleClass('active_feature');
	});
	
	$('.feature_thumb').hover(
		function() {//mouseover function
			var feature_id = $(this).attr('id').split('_');
			var id = feature_id[feature_id.length-1];
			$('#product_feature_bullet_' + id).toggleClass('active_feature');
		}, function() {//mouseout function
			var feature_id = $(this).attr('id').split('_');
			var id = feature_id[feature_id.length-1];
			
			$('#product_feature_bullet_' + id).toggleClass('active_feature');
	});
	
	//overlay effect for product features
	$('a.feature_trigger').overlay({
		mask:'#000000',	
		onBeforeLoad: function() {
			var wrap = this.getOverlay().find('.content_wrap');
			wrap.load(this.getTrigger().attr('href'));
		},
		onLoad: function() {
			$('#feature_copy').animate({width:'250px', paddingRight:'15px', paddingLeft:'15px'});
		}
	});
		
	$("div.overlay").appendTo('body');
	
	//configuration utility overlay
	// $('#counselor_utility').overlay({
	// 	mask: '#000000'
	// });
	
	$('#counselor_utility').overlay({
		mask:'#000000',
		onBeforeLoad: function() {
			var wrap = this.getOverlay().find('.content_wrap');
			wrap.load(this.getTrigger().attr("href"));
		}
	});
	
	
	$('#organization_container').hide();
	$('#bus_name_container').hide();
	
	$('#relationship').change(function() {
		if ($(this).val() == "res_cust") {
			$('#organization_container').slideDown('fast');
			$('#bus_name_container').slideUp('fast');
		} else {
			$('#organization_container').slideUp('fast');
			$('#bus_name_container').slideDown('fast');
		}
	});
	
	$('#nav_head ul ul').css({'left':'152px','width':'0','overflow':'hidden'});
	$('#nav_head ul li').hover(
		function() {
			var top_pos = $(this).offset();
			$(this).children('ul').css({'top':top_pos.top});
			$(this).children('ul').stop().animate({width:'200px'},300);
		},
		function() {
			$(this).children('ul').stop().animate({width:'0'},300);
		}
	);
	
	$('span.explanation').css({top:'-140px'});
	$('.loop_install').hover(function() {
		$(this).children('.explanation').stop().animate({top:'0px'},300);
		if ( $('#loop_instruction').is(':visible') ) {
			$('#loop_instruction').slideUp('fast');
		}
	}, function() {
		$(this).children('.explanation').stop().animate({top:'-140px'},300);
	});
		
	$('#heating_cooling_panes').scrollable().navigator({
		navi: '#heating_cooling_tabs',
		naviItem: 'li',
		activeClass: 'current'
	});
	
	$('.small_loop_install').overlay({
		mask:'#000000',	
		onBeforeLoad: function() {
			var wrap = this.getOverlay().find('.content_wrap');
			wrap.load(this.getTrigger().attr('href'));
		}
	});
	
	$('#why_container dd').hide(0, function() {
		$(this).parent('dl').css({"width":"500px"});
		$(this).prev('dt').addClass('dynamic_term');
	});

	$('#why_container dt').click(function() {
		var definition = $(this).next('dd');
		var other_defs = $(this).siblings('dd');
		var other_terms = $(this).siblings('dt');
		$(this).addClass('active_button');
		
		other_terms.removeClass('active_button');
		if (other_defs.is(':visible')) {
			other_defs.css({width:'0px',display:'none'});
		}
		definition.addClass('dynamic_explanation');
		definition.show();
		definition.animate({width:'250px'},500);
	});
	
	// $('.dealer_email').click(function() {
	// 	var target = $(this).closest('.info').next('.support');
	// 	target.find('.dealer_email').slideToggle('fast');
	// 	return false;
	// });
	
	$('.dealer_email').overlay({
		effect:'apple',
		fixed:false,
		onBeforeLoad: function() {
			var wrap = this.getOverlay().find('.content_wrap');
			wrap.load(this.getTrigger().attr('href'));
		}
	});
	
	$('.phone_number').hide();
	
	$('.phone_click').click(function() {
		var dealer_id = $(this).attr('href').split('/')[$(this).attr('href').split('/').length-1];
		var zip_code = $('#page_photo_head > div > span').text().split(' ')[$('#page_photo_head > div > span').text().split(' ').length-1];
		
		$(this).next('.phone_number').show('fast');
		
		$.post('/dealer/phone_lead.cfm?id=' + dealer_id + '&zip=' + zip_code, function(data) {
		});
		
		return false;
	});
	
});
