﻿/*
'--------------------------------------------------------------------------------------------------
' Title			: Mathews ProStaff View ProStaffer
' Description	: JavaScript functions and declarations for the view proStaff page
'--------------------------------------------------------------------------------------------------
' History
' 03/31/2009	: DPE - Created Page
'--------------------------------------------------------------------------------------------------
*/

var swfPlayerReady = false;

// Function to initiate switching between product tabs
function initViewProdTabs(){
	
	// Lets start with a clean slate
	$(".box").hide();
	$("#primaryGraphic").hide();
	$("#videoPlayerBox").html("");
	
	// Then lets find out which tab is requested
	var reqTab = window.location.hash.replace(/#/,"")
	if(reqTab == "") {reqTab = "overview";}
	
	// Next, add the action to each button
	$("#shooterNav li[class!='retailer'] a").click(function(){
		switchTabs($(this).attr("rel"));
	});
	
	switchTabs(reqTab); // Finally, setup the initial state
}

// Actually performs the tab switching
function switchTabs(reqTab) {

	// Set set the selected button
	$("#shooterNav li[class!='retailer']").each(function(){
		if($(this).find("a").attr("rel") == reqTab){
			$(this).addClass("sel");
		} else {
			$(this).removeClass("sel");		
		}
	});
	
	// Turn everything off
	$(".box").hide();
	$("#primaryGraphic").hide();
	$("#videoPlayerBox").html("");	
	
	// The turn on what we need
	switch(reqTab) {
		case "overview":
			$("#overview").show();
			$("#primaryGraphic").show();
			break;
		case "specs":
			$("#specs").show();
			$("#primaryGraphic").show();
			break;
		case "gallery":
			$("#gallery").show();
			if($("#gallery .images")){
				$("#videoPlayerBox").html("");
				$("#largeImgBox").show();
			} else {
				$("#largeImgBox").hide();
				$("#videoPlayerBox").show();			
			}
			break;
		case "testimonials":
			$("#testimonials").show();
			//$("#primaryGraphic").show();
			break;
		default:
			$("#overview").show();
			$("#primaryGraphic").show();
			break;
	}
}

function initSwitchImg(){

	// Apply the action to the thubnail links	
	$("#imgNav li a").click(function(){
		
		//get the large image attributes
		var largeImgSrc 	= $(this).find("img").attr("src").replace(/w70/,"w365");
		var largeImgAlt 	= $(this).find("img").attr("alt");
		largeImgSrc 		= largeImgSrc.replace(/_sq/,"");
		var closeUpImgSrc	= largeImgSrc.replace(/w365_/,"");
		
		// Remove any videos that are playing
		$("#videoPlayerBox").html("");
		
		// Set the large image to the requested one display it
		$("#largeImg").attr({src:largeImgSrc,alt:largeImgAlt,jqimg:closeUpImgSrc});
		$("#largeImgBox").show();

	});
	
	// Preload the large images
	largeImgs	= new Array(); // Array to hold the LARGE preloaded images
	closeUpImgs	= new Array(); // Array to hold the SUPER/MAGNIFY preloaded images

	$("#imgNav li a img").each(function(i){
		var largeImgSrc		= $(this).attr("src").replace(/w70/,"w365");
		largeImgSrc			= largeImgSrc.replace(/_sq/,"");
		largeImgs[i]		= new Image;
		largeImgs[i].src	= largeImgSrc;
		var closeUpImgSrc	= largeImgSrc.replace(/_w365/,"");
		closeUpImgs[i]		= new Image;
		closeUpImgs[i].src	= closeUpImgSrc;
	});
	
}

function initSwitchVid() {
	$("#vidNav li a").click(function(){
		
		// Turn off any large images...
		$("#largeImgBox").hide();
		
		var videoObj	= document.getElementById("videoPlayer");
		var flvInfo		= $(this).attr("rel");
		var strUrl		= "/site/layouts/products/ajax/setVideoObject.asp";
		
		$.ajax({
			url: strUrl,
			data: "flvInfo=" + flvInfo + "",
     		error: function (xhr, desc, exceptionobj) {
				alert(xhr.responseText);
			},
			success: function(output){
				if(output.error) {
					alert(output.error);
					return;
				}
				$("#videoPlayerBox").html(output)
		   }
		 });
		 				
	});
}

function initVideoBtns(){
	$(".videoBtn").click(function(){

		reqTab = $(this).attr("href").replace(/.*#/,"");
		//alert(reqTab);
		switchTabs(reqTab);
		
		// Turn off any large images...
		$("#largeImgBox").hide();
		
		var videoObj	= document.getElementById("videoPlayer");
		var flvInfo		= $(this).attr("rel");
		var strUrl		= "/site/layouts/products/ajax/setVideoObject.asp";
		
		$.ajax({
			url: strUrl,
			data: "flvInfo=" + flvInfo + "",
     		error: function (xhr, desc, exceptionobj) {
				alert(xhr.responseText);
			},
			success: function(output){
				if(output.error) {
					alert(output.error);
					return;
				}
				$("#videoPlayerBox").html(output)
			}
		 });
		 			
	});
}

function initTestimonialSwitch() {

}

function initSifr(){
	if(typeof sIFR == "function"){ // Fancy Text for the page title...
		sIFR.replaceElement("h1", named({sFlashSrc:"/site/swf/sifr-myriadProCond.swf",sColor:"#a97c25",sWmode:"opaque"}));
	};
}

// Replaces tradtional body onLoad="" functionality throughout the site
$(document).ready(function(){
	initViewProdTabs(); // initiates switching between product tabs
	initSwitchImg();	// initiates image switching on the gallery tab
	initSwitchVid();	// initiates video switching on the gallery tab
	initVideoBtns();	// initiates the View Video btn in the overview
	initSifr();			// initiates the Flash text replacement for the page title
	//$(".jqzoom").jqueryzoom({xzoom:400,yzoom:400,offset:0,position:"left",preload:0}); // Initiates the magnifier/close-up image functions
	
});
