(function($){
  var cache = [];
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery);

$(document).ready(function(){
	
	// Hinge Track Flash / Fancybox
	
	$("a.fb").fancybox({
		width: 550,
		height: 400,
		overlayShow: true,
		overlayOpacity: 0.4,
		hideOnContentClick: true,
		type: 'swf'
	});
	
	// Tabs on specs pages
	
	function clear_specs(){
		$("div.spec_pane").removeClass("visible");
		$("li.spec_tab").removeClass("selected");
	}
	
	$("a[href=#description]").click(function(){
		clear_specs();
		$("div#spec_description").addClass("visible");
		$(this).parent("li").addClass("selected");
		return false;
	});
	
	$("a[href=#features]").click(function(){
		clear_specs();
		$("div#spec_features").addClass("visible");
		$(this).parent("li").addClass("selected");
		return false;
	});
	
	$("a[href=#specification]").click(function(){
		clear_specs();
		$("div#spec_specification").addClass("visible");
		$(this).parent("li").addClass("selected");
		return false;
	});
	
	$("a[href=#price_and_service]").click(function(){
		clear_specs();
		$("div#spec_price_and_service").addClass("visible");
		$(this).parent("li").addClass("selected");
		return false;
	});
	
	// Curved Prices
	
	$("div#curved_prices_right a:first").addClass("selected");
	
	$("div#curved_prices_right a").hover(function(){
		$("div#curved_prices_right a").removeClass("selected");
		$(this).addClass("selected");
	},function(){});
	
	// Feature list
	
	$("div#spec_feature_list a:first").addClass("selected");
	
	$("div#spec_feature_list a").hover(function(){
		$("div#spec_feature_list a").removeClass("selected");
		$(this).addClass("selected");
	},function(){});
	
	// Menu
	
	$("div#menu ul li").hover(function(){
		$(this).find("ul").show();
		$(this).addClass("menu_on");
	},function(){
		$(this).find("ul").hide();
		$(this).removeClass("menu_on");
	});
	
	// Table alt rows
	
	$("div#spectable table tr:odd").addClass("alt");
	
	$("div#spectable table tr td:first-child").addClass("letter");
	
	// Adjust warranty option columns
	
	var max_height = 0;
	
	$("div.warranty_level").each(function(){
		if( $(this).height() > max_height ){
			max_height = $(this).height();
		}
	});
	
	$("div.warranty_level").height( max_height );
	
	// Top button
	
	$(window).load(function(){
		$("#img_offer_button").effect( 'bounce' );
		setInterval(function(){
			$("#img_offer_button").effect( 'pulsate', {
				times: 3
			}, 300 );
		}, 10000 );
	});
	
	// Areas we cover
	
	$("#coverage_area_hover").hover(function(){
		$(this).children("#areas_list").show();
	},function(){
		$(this).children("#areas_list").hide();
	});
	
	jQuery.preLoadImages( "static/img/areas_bg.png" );
	
	$("#areas_we_cover").click(function(){
		return false;
	});
	
});
