﻿/// <reference path="~/scripts/jquery-1.2.6.js" />

$(document).ready(function() {
	setupMainFlash();
  setupFlashHeaders();
	lightboxImages();
	hideProductInfo();
	sortTable("table.sortable");
	setupExpandableDLs();
});

function setupMainFlash(){
	var img = $("#HomePageImage");
	
	if(img.length > 0){
		replaceImageWithFlash(img[0], img[0].id, img[0].src, 597, 405, "9.0.0", {}, {wmode:"transparent"}, {wmode:"transparent"});
		}
	}

function setupFlashHeaders() {
  var header = $(".FlashReplaceHeader");

  // If there is a header to replace.
  if (header.length > 0) {
		replaceImageWithFlash(header[0], header[0].id, header[0].src, 585, 156, "9.0.0", {}, {}, {});
  }
}

function lightboxImages(){
		$('a.lightbox').nyroModal({ minWidth: 100, minHeight: 100 });
}

function hideProductInfo(){
	$("#productImages li:not(#productDefaultImage)").hide();
	}

function sortTable(elementId){
	var table = $(elementId);
	
	if(table.length > 0){
    // extend the default setting to always include the zebra widget. 
    $.tablesorter.defaults.widgets = ['zebra']; 
    // extend the default setting to always sort on the first column 
    $.tablesorter.defaults.sortList = [[0,0]]; 
		//Make it sortable
		table.tablesorter({cssHeader:"sortableTableHeader", cssAsc:"sortableTableHeaderAsc", cssDesc:"sortableTableHeaderDesc"});
	}	
}

function setupExpandableDLs(){
	if($("dl.expandableDefinition").length > 0){
		$("dl.expandableDefinition dd").hide();
		$("dl.expandableDefinition dt").click(function(){
																		$(this).next().slideToggle('normal');
																		}
									).hover(function() {
										$(this).addClass('hover');
										}, function() {
											$(this).removeClass('hover');
										});
	}
}

function replaceImageWithFlash(element, imageId, imageUrl, width, height, flashversion, flashvars, params, attributes){
	var flashUrl = imageUrl.substr(0, imageUrl.length - 3) + "swf";
	var baseUrl = imageUrl.substr(0, imageUrl.length - 4);

	// We need an ID to properly insert the flash. Create one if needed.
	if (imageId == "") {
		element.id = imageId = "ContentHeader_" + new Date().getMilliseconds();
		}

	attributes.id = imageId + "_SWF";
	attributes.base = baseUrl;
	params.base = baseUrl;
	swfobject.embedSWF(flashUrl, imageId, width, height, flashversion, false, flashvars, params, attributes);
	}
