/*
 * fade 3.1 - One Box To Rule Them All.
 * By Cody Lindley (http://www.codylindley.com)
 * Copyright (c) 2007 cody lindley
 * Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
*/
		  

/*!!!!!!!!!!!!!!!!! edit below this line at your own risk !!!!!!!!!!!!!!!!!!!!!!!*/

//on page load call fd_init
jQuery(document).ready(function(){   
	fd_init('a.fade');//pass where to apply fade
});

//add fade to href & area elements that have a class of .fade
function fd_init(domChunk){
	jQuery(domChunk).click(function(){
	var t =  this.id.toLowerCase();
	var a = this.href;
	//var g = this.rel || false;
	fd_show(t,a);
	this.blur();
	return false;
	});
}

function fd_show(caption, url) {//function called when the user clicks on a fade link
	var pathToMovie = url;
	try {
		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
			jQuery("body","html").css({height: "100%", width: "100%"});
			jQuery("html").css("overflow","hidden");
			if (document.getElementById("FD_HideSelect") === null) {//iframe to hide select elements in ie6
				FD_WIDTH =  625; // IE6 parameters defaults to 632 if no paramaters were added to URL
				FD_HEIGHT = 432; //IE6 parametersdefaults to 432 if no paramaters were added to URL
				//ajaxContentW = FD_WIDTH;  //IE6
				//ajaxContentH = FD_HEIGHT;  //IE6    and below too ie6 unto line54

				jQuery("body").append("<iframe id='FD_HideSelect'></iframe><div id='FD_overlay'></div><div id='FD_window'></div>");
				jQuery("#FD_overlay").click(fd_remove);
				jQuery("#FD_window").append("<div id='FD_title' style='width:625px'><div id='FD_ajaxWindowTitle'></div><div id='FD_closeAjaxWindow'><img src='/taec/Catalog/images/icon_pop_close.gif' width='33' height='34' border='0' id='FD_closeWindowButton'></img> </div></div><div id='FD_ajaxContent' style='width:640px;height:450px'><object id='movie' type='application/x-shockwave-flash' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='https:\//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab' width='630' height='430'>" + 
				"<param name='movie' value='/taec/components/Description/ssd_video/none.swf' />" +
				"<param name='quality' value='high' />" +
				"<param name='bgcolor' value='#ffffff' />"  +
				"<param name='FlashVars' value='null' />" +
				"<param name='menu' value='true' />" +
				"<param name='play' value='true' />" +
				"<param name='loop' value='false' />" +
				"<param name='scale' value='showall' />" +
				"<param name='wmode' value='window' />" +
				"<embed src='/taec/components/Description/ssd_video/none.swf' name='movie' play='true' loop='false' quality='best' wmode='window' scale='showall'  devicefont='false' menu='true' allowscriptaccess='sameDomain' type='application/x-shockwave-flash' pluginspage='https://www.macromedia.com/go/getflashplayer' width='632' height='432' />"+ 
			"</object>" + "</div>");
				if(window.movie){
			   		try{
    				window.movie.LoadMovie(0,pathToMovie);// IE   Loads the movie to the object tag
				 	}
					catch(e){
				    window.movie[1].src=pathToMovie;  //  Safari . Sets the source of the embed tag
					}  	
				}
			 	else{	
			 	document.movie.src=pathToMovie;  // Mozilla. Sets the source of the embed tag
				}
			}
		jQuery("#FD_window").css("display","block");
		fd_position();
		jQuery("#FD_closeWindowButton").click(fd_remove);

		}else{//all others
			if(document.getElementById("FD_overlay") === null){
				FD_WIDTH =  625; //defaults to 630 if no paramaters were added to URL
				FD_HEIGHT = 440; //defaults to 440 if no paramaters were added to URL
				ajaxContentW = FD_WIDTH - 30;
				ajaxContentH = FD_HEIGHT - 15;
				jQuery("body").append("<div id='FD_overlay'></div><div id='FD_window'></div>");
				jQuery("#FD_overlay").click(fd_remove);
				jQuery("#FD_window").append("<div id='FD_title'><div id='FD_ajaxWindowTitle'></div><div id='FD_closeAjaxWindow'><img src='/taec/Catalog/images/icon_pop_close.gif' width='33' height='34' border='0' id='FD_closeWindowButton'></img> </div></div><div id='FD_ajaxContent' style='width:650px;height:440px'><object id='movie' type='application/x-shockwave-flash' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='https:\//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab' width='650' height='440'>" + 
				"<param name='movie' value='/taec/components/Description/ssd_video/none.swf' />" +
				"<param name='quality' value='high' />" +
				"<param name='bgcolor' value='#ffffff' />"  +
				"<param name='FlashVars' value='null' />" +
				"<embed src='/taec/components/Description/ssd_video/none.swf' name='movie' play='true' loop='false' quality='best' wmode='window' scale='showall' devicefont='false' menu='true' bgcolor='#ffffff' allowscriptaccess='sameDomain' type='application/x-shockwave-flash' pluginspage='https://www.macromedia.com/go/getflashplayer' width='650' height='440' />"+ 
			"</object>" + "</div>");
				if(window.movie){
			   		try{
    				window.movie.LoadMovie(0,pathToMovie);// IE   Loads the movie to the object tag
				 	}
					catch(e){
				    window.movie[1].src=pathToMovie;  //  Safari . Sets the source of the embed tag
					}  	
				}
			 	else{	
			 	document.movie.src=pathToMovie;  // Mozilla. Sets the source of the embed tag
				}
			}
		}
		if(fd_detectMacXFF()){
			jQuery("#FD_overlay").addClass("FD_overlayMacFFBGHack");//use png overlay so hide flash
		}else{
			jQuery("#FD_overlay").addClass("FD_overlayBG");//use background and opacity
		}
		jQuery("#FD_window").css("display","block");
		fd_position();
		jQuery("#FD_closeWindowButton").click(fd_remove);

		if(url.indexOf("notThere")){//code to show images(nothing to do)
				
		}else{//code to show html
			if (jQuery("#FD_window")){// not an iframe, ajax
				jQuery("#FD_window").css("display","block");
				if(jQuery("#FD_window").css("display","block")){
				}else{//this means the window is already up, we are just loading new content via ajax
					jQuery("#FD_ajaxContent")[0].style.width = ajaxContentW +"px";
					jQuery("#FD_ajaxContent")[0].style.height = ajaxContentH +"px";
					jQuery("#FD_ajaxContent")[0].scrollTop = 0;
				}
			}
		}   
	} catch(e) {
		//nothing here
	}
}

//helper functions below
function fd_showIframe(){
	jQuery("#FD_load").remove();
	jQuery("#FD_window").css({display:"block"});
}

function fd_remove() {
 	jQuery("#FD_imageOff").unbind("click");
	jQuery("#FD_closeWindowButton").unbind("click");
	jQuery("#FD_window").fadeOut("fast",function(){jQuery('#FD_window,#FD_overlay,#FD_HideSelect').trigger("unload").unbind().remove();});
	//jQuery("#FD_load").remove();
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		jQuery("body","html").css({height: "auto", width: "auto"});
		jQuery("html").css("overflow","");
	}
	document.onkeydown = "";
	document.onkeyup = "";
	return false;
}

function fd_position() {
jQuery("#FD_window").css({marginLeft: '-' + parseInt((FD_WIDTH / 2),10) + 'px', width: FD_WIDTH + 'px'});
	if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
		jQuery("#FD_window").css({marginTop: '-' + parseInt((FD_HEIGHT / 2),10) + 'px'});
	}
}


function fd_getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	arrayPageSize = [w,h];
	return arrayPageSize;
}

function fd_detectMacXFF() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
    return true;
  }
}


