$(function(){
	var video_obj = "";
	function embed_video() {
		// check if SWF hasn't been removed, if this is the case, create a new alternative content container
		var c = document.getElementById("video_content");
		if (!c) {
			var d = document.createElement("div");
			d.setAttribute("id", "video_content");
			document.getElementById("video_frame").appendChild(d);
		}
		var attrs = { align: "middle", wmode: "opaque" };
		var params = { quality: "high", bgcolor: "#34441D", wmode: "opaque" };
		var id = "video_content";
		swfobject.embedSWF(video_obj, "video_content", "468", "302", "8", "/video/expressInstall.swf", false, params, attrs);
	}
	// Video Links
	$('.video_overlay').colorbox({width:"480px", scrolling:false});
	// Contact Overlay
	$('.sub_nav_menu a[rel=#contact_overlay]').colorbox({inline:true, href:"#contact_overlay", opacity:0.75, width:"336px"});
	
	// Products Gallery
	$('.image_frame').loopedSlider({
		container: ".product_images",
		slides: ".slides",
		pagination: "pagination",
		slidespeed: 800
	});
	
	// Tooltip
	$('.tooltip-trigger').tooltip({
		position: "top center",
		relative: true,
		offset: [-2, 0],
		tip: '.tooltip'
	});
	
	// Product Highlight
	$(".product_image img").animate({opacity: 0}, 1);
	$('.product_image map area').hover(
		function() {
			var idx = $('.product_image map area').index(this);
			var img_num = idx + 1;
			$(".product_image img").attr('src',"img/product_highlight/product_highlight-" + img_num + ".jpg");
			$(".product_image img").stop(true,true).animate({opacity: 1}, 300);
			$(".product_description #desc").stop(true,true).hide();
			$(".product_description #feature_desc").empty();
			$(".product_features li:eq("+idx+")").clone().appendTo(".product_description #feature_desc");
			$(".product_description #feature_desc").show();
		},
		function() {
			$(".product_image img").stop(true,true).animate({opacity: 0}, 200);
			$(".product_description #feature_desc").stop(true,true).hide();
			$(".product_description #feature_desc").empty();
			$(".product_description #desc").show();
		}
	);

	// Products Table column highlight and link to product gallery
	$('.products_table colgroup.product_cols col').each(function() {
		product_idx = $('.products_table table colgroup.product_cols col').index(this);
        $(this).attr("id", "col"+product_idx);
    });
	$('.products_table table').each(function(){
		$('.products_table table td').each(function() {
			var col_idx = $(this).parent().children('td').index(this);
			var col_id = $('.products_table table colgroup.product_cols col').eq(col_idx).attr('id');
			$(this).attr('rel', col_id);
			$(this).hover(function() {
		        $('.products_table table td[rel='+$(this).attr('rel')+']').addClass("hover");
		    }, function() {
		        $('.products_table table td[rel='+$(this).attr('rel')+']').removeClass("hover");
		    });
			var col_url = $(".product_nav li a[class!=category_pg_link]").eq(col_idx).attr('href');
			$(this).click(function() {
				window.location=col_url; return false;
			});
	    });
	});
	
	// Weeds Diagram
	$('.weeds_list a').each(function(){
		var weed_idx = $('.weeds_list a').index(this) + 1;
		$(this).click(
			function(){
				$('#weeds_diagram').css('background-image',"url('img/weeds/aquatic_weeds-"+weed_idx+".png')");
				$('.weeds .example_photo img').attr('src','img/weeds/aquatic_weeds-'+weed_idx+'-example.jpg');
				$('.weeds .example_photo img').css('border-color','#2F4258');
				$('#weeds_descriptions p').hide();
				$('#weeds_descriptions #w'+weed_idx).show();
				$('.weeds_list a').removeClass('active');
				$(this).addClass('active');
			}
		);
	});
	$('#weeds_diagram .close').click(function(){
		$('#weeds_diagram').css('background-image',"url('img/weeds/aquatic_weeds-inactive.png')");
		$('.weeds .example_photo img').attr('src','img/weeds/aquatic_weeds-inactive-example.png');
		$('.weeds .example_photo img').css('border-color','#7E481C');
		$('#weeds_descriptions p').hide();
		$('.weeds_list a').removeClass('active');
		$('#weeds_descriptions #w0').show();
	});
		
});