/*
FROM thickbox.js TO foxybox.js:

# Replace all double spaces -> tabs
# Replace all $( and $. to jQuery( and jQuery.
# Replace all tb_ and TB_ to fc_tb_
# Replace all .thickbox to .foxycart
# Remove the input.foxycart (and area.foxycart) from the init()
# Add check for cart=checkout or cart=updateinfo, check for fc_PreProcess in fc_init
	# Replace 'tb_show(t,a,g);' with:
	// BEGIN ADDED BY FOXYCART
	if (this.href.match("cart=checkout") || this.href.match("cart=updateinfo")) {
		location.href = this.href;
	} else {
		// if they defined fc_PreProcess(), let them process the form data before we pass it along
		if (typeof(fc_PreProcess) == 'function') { 
			if (!fc_PreProcess()) {
				return false;
			}
		}
	  fc_tb_show(t,a,g);
	}
	// END ADDED BY FOXYCART

# Change params['width'] and params['height'] to params['x:width'] and params['x:height']
# Change default width, height to 500, 350

# Add src to iframe in fc_tb_show to prevent security warnings when loading on secure pages:
	src='https://www.foxycart.com/empty.html'

# Remove if statement for urlType == images
# Remove ajax code
# Remove iframe modal code
# Should only be left with a few lines:
	urlNoQuery = url.split('fc_tb_');
	jQuery("#fc_tb_iframeContent").remove();
	jQuery("#fc_tb_window").append(...
# Remove the positioning if/then statements, left with:
	fc_tb_position();
	if(jQuery.browser.safari){//safari needs help because it will not fire iframe onload
		jQuery("#fc_tb_load").remove();
		jQuery("#fc_tb_window").css({display:"block"});
	}

# Change loading gif to: https://www.foxycart.com/files/images/loadingAnimation.gif
# Add if exists test to loading gif variable to allow customization

# Add fc_UpdateCart(FoxyDomain) to fc_remove after the .remove() call

# Change from IDs to classes for all the closebuttons, add bottom row of buttons ("continue shopping").
# Change the click(fc_tb_remove) function to call on the new Top/Bot IDs

# Add span around the "or Esc Key" to ease styling.

*/

/*
 * Thickbox 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
*/

if (!fc_tb_pathToImage) {
	var fc_tb_pathToImage = "https://www.foxycart.com/files/images/loadingAnimation.gif";
}
/*!!!!!!!!!!!!!!!!! edit below this line at your own risk !!!!!!!!!!!!!!!!!!!!!!!*/
//on page load call fc_tb_init
jQuery(document).ready(function(){	 
	fc_tb_init('a.foxycart');//pass where to apply thickbox
	imgLoader = new Image();// preload image
	imgLoader.src = fc_tb_pathToImage;
});
//add thickbox to href & area elements that have a class of .foxycart
function fc_tb_init(domChunk){
	jQuery(domChunk).click(function(){
	var t = this.title || this.name || null;
	var a = this.href || this.alt;
	var g = this.rel || false;
	// BEGIN ADDED BY FOXYCART
	if (this.href.match("cart=checkout") || this.href.match("cart=updateinfo")) {
		location.href = this.href;
	} else {
		// if they defined fc_PreProcess(), let them process the form data before we pass it along
		if (typeof(fc_PreProcess) == 'function' && !this.href.match("cart=view")) {
			MyFoxyData = this.href.substring(this.href.indexOf("?")+1);
			MyFoxyID = jQuery(this).attr('id');
			if (!fc_PreProcess(MyFoxyData, MyFoxyID)) {
				return false;
			}
		}
	  fc_tb_show(t,a,g);
	}
	// END ADDED BY FOXYCART
	this.blur();
	return false;
	});
}
function fc_tb_show(caption, url, imageGroup) {//function called when the user clicks on a thickbox link
	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("fc_tb_HideSelect") === null) {//iframe to hide select elements in ie6
				jQuery("body").append("<iframe id='fc_tb_HideSelect' src='https://www.foxycart.com/empty.html'></iframe><div id='fc_tb_overlay'></div><div id='fc_tb_window'></div>");
				jQuery("#fc_tb_overlay").click(fc_tb_remove);
			}
		}else{//all others
			if(document.getElementById("fc_tb_overlay") === null){
				jQuery("body").append("<div id='fc_tb_overlay'></div><div id='fc_tb_window'></div>");
				jQuery("#fc_tb_overlay").click(fc_tb_remove);
			}
		}
		
		if(fc_tb_detectMacXFF()){
			jQuery("#fc_tb_overlay").addClass("fc_tb_overlayMacFFBGHack");//use png overlay so hide flash
		}else{
			jQuery("#fc_tb_overlay").addClass("fc_tb_overlayBG");//use background and opacity
		}
		
		if(caption===null){caption="";}
		jQuery("body").append("<div id='fc_tb_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
		jQuery('#fc_tb_load').show();//show loader
		
		var baseURL;
		 if(url.indexOf("?")!==-1){ //ff there is a query string involved
			baseURL = url.substr(0, url.indexOf("?"));
		 }else{ 
				 baseURL = url;
		 }
		 
		 var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
		 var urlType = baseURL.toLowerCase().match(urlString);

			
		var queryString = url.replace(/^[^\?]+\??/,'');
		var params = fc_tb_parseQuery( queryString );
		if (typeof(fc_tb_WIDTH)=='undefined') {
			fc_tb_WIDTH = (params['x:width']*1) + 30 || 650;
		}
		if (typeof(fc_tb_HEIGHT)=='undefined') {
			fc_tb_HEIGHT = (params['x:height']*1) + 40 || 450;
		}
		ajaxContentW = fc_tb_WIDTH - 30;
		ajaxContentH = fc_tb_HEIGHT - 45;
		
		// FOXYCART: This is all that's left
		url = url.replace(/'/g, "%27");
		jQuery("#fc_tb_iframeContent").remove();
		jQuery("#fc_tb_window").append("<div id='fc_tb_titleTop' class='fc_tb_title'><div id='fc_tb_ajaxWindowTitleTop' class='fc_tb_ajaxWindowTitle'>"+caption+"</div><div class='fc_tb_closeAjaxWindow' id='fc_tb_closeAjaxWindowTop'><a href='#' class='fc_tb_closeWindowButton fc_link_nav' id='fc_tb_closeWindowButtonTop' title='Close'>close</a> <span>or Esc Key</span></div></div><iframe allowtransparency='true' frameborder='0' hspace='0' src='"+url+"' id='fc_tb_iframeContent' name='fc_tb_iframeContent"+Math.round(Math.random()*1000)+"' onload='fc_tb_showIframe()' style='width:"+(ajaxContentW + 30)+"px;height:"+(ajaxContentH + 17)+"px;' > </iframe> <div class='fc_tb_title' id='fc_tb_titleBot'><div class='fc_tb_closeAjaxWindow' id='fc_tb_closeAjaxWindowBot'><a href='#' class='fc_tb_closeWindowButton fc_link_nav' id='fc_tb_closeWindowButtonBot' title='Continue Shopping'><span>&laquo;</span>Continue Shopping</a></div></div>");
		// FOXYCART: End "all that's left"
		
		jQuery("#fc_tb_closeWindowButtonTop, #fc_tb_closeWindowButtonBot").click(fc_tb_remove);
			
		fc_tb_position();
		if(jQuery.browser.safari){//safari needs help because it will not fire iframe onload
			jQuery("#fc_tb_load").remove();
			jQuery("#fc_tb_window").css({display:"block"});
		}


		if(!params['modal']){
			document.onkeyup = function(e){	 
				if (e == null) { // ie
					keycode = event.keyCode;
				} else { // mozilla
					keycode = e.which;
				}
				if(keycode == 27){ // close
					fc_tb_remove();
				}	
			};
		}
		
	} catch(e) {
		//nothing here
	}
}
//helper functions below
function fc_tb_showIframe(){
	jQuery("#fc_tb_load").remove();
	jQuery("#fc_tb_window").css({display:"block"});
}
function fc_tb_remove() {
	 jQuery("#fc_tb_imageOff").unbind("click");
	jQuery("#fc_tb_closeWindowButtonTop, #fc_tb_closeWindowButtonBot").unbind("click");
	jQuery("#fc_tb_window").fadeOut("fast",function(){jQuery('#fc_tb_window,#fc_tb_overlay,#fc_tb_HideSelect').trigger("unload").unbind().remove();});
	jQuery("#fc_tb_load").remove();
	
	// BEGIN ADDED BY FOXYCART
	fc_UpdateCart(FoxyDomain);
	// DONE ADDED BY FOXYCART
	
	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 fc_tb_position() {
jQuery("#fc_tb_window").css({marginLeft: '-' + parseInt((fc_tb_WIDTH / 2),10) + 'px', width: fc_tb_WIDTH + 'px'});
	if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
		jQuery("#fc_tb_window").css({marginTop: '-' + parseInt((fc_tb_HEIGHT / 2),10) + 'px'});
	}
}
function fc_tb_parseQuery ( query ) {
	 var Params = {};
	 if ( ! query ) {return Params;}// return empty object
	 var Pairs = query.split(/[;&]/);
	 for ( var i = 0; i < Pairs.length; i++ ) {
			var KeyVal = Pairs[i].split('=');
			if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
			var key = unescape( KeyVal[0] );
			var val = unescape( KeyVal[1] );
			val = val.replace(/\+/g, ' ');
			Params[key] = val;
	 }
	 return Params;
}
function fc_tb_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 fc_tb_detectMacXFF() {
	var userAgent = navigator.userAgent.toLowerCase();
	if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
		return true;
	}
}

