//
// hijacking thickbox class for the home page (and other pages that
// bug out on AJAX
// to enable:include instead "new_home_includes.shtml" which uses this file (/include/thicpopk.js) and /include/thickpop.css.
// -b
// 

//SAMPLE LINK: a href="/fresh-direct.html?height=400&amp;width=600" title="$100 of Free Groceries"  class="thickbox">$100 of FREE Groceries</a></td>


//var tb_pathToImage = "/include/thickbox/bigrotation.gif";

/*!!!!!!!!!!!!!!!!! edit below this line at your own risk !!!!!!!!!!!!!!!!!!!!!!!*/

//on page load call tb_init
$(document).ready(function(){   
	tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
//	imgLoader = new Image();// preload image
//	imgLoader.src = tb_pathToImage;
});

//add thickbox to href & area elements that have a class of .thickbox
function tb_init(domChunk){
	$(domChunk).click(function(){
	var t = this.title || null;
	var a = this.href;
	var g = this.rel || false;
	var sz = this.name;
	//passing ht wd info in name property:    name="henry?height=350&width=500" 
	var ht = sz.slice(sz.indexOf("height=") + 7, sz.indexOf("&width="));
	var wd = sz.slice(sz.indexOf("width=")+6);
	tb_show(t,a,g,ht,wd,sz);
	this.blur();
	return false;
	});
}

function tb_show(caption, url, imageGroup, ht, wd, sz) {//function called when the user clicks on a thickbox link

	try {
		idd =sz.slice(0, sz.indexOf("?"));
	//	alert('id11'+idd);
	//	idd = idd.slice(0,idd.indexOf(".htm"));
	//	alert('id12'+idd);
		idd = idd.replace("-","_"); // IE bugs on dashes
	//	alert('id13'+idd);
		newwindow = window.open(url, idd,"width=" + wd + ",height=" + ht + ",resizable=no,scrollbars=yes");

		if (window.focus) {newwindow.focus();}
	//	newwindow.document.write("<TITLE>"+caption+"</TITLE>"); // add title to popup...eventually
	
	} catch(e) {
	alert (e);   //debug
		//nothing here
	}

}


//vestigial thickbox code  here
		

//helper functions below
function tb_showIframe(){
	$("#TB_load").remove();
	$("#TB_window").css({display:"block"});
}

function tb_remove() {
 	$("#TB_imageOff").unbind("click");
	$("#TB_closeWindowButton").unbind("click");
	$("#TB_window").fadeOut("fast",function(){$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
	$("#TB_load").remove();
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		$("body","html").css({height: "auto", width: "auto"});
		$("html").css("overflow","");
	}
	document.onkeydown = "";
	document.onkeyup = "";
	return false;
}

function tb_position() {
$("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
	if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
		$("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
	}
}

function 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 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 tb_detectMacXFF() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (userAgent.indexOf('mac') != -1 && userAgent.indexOf('firefox')!=-1) {
    return true;
  }
}


