/*
 * 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
*/
		  
/*!!!!!!!!!!!!!!!!! edit below this line at your own risk !!!!!!!!!!!!!!!!!!!!!!!*/

//on page load call tb_init
$(document).ready(function(){   

	edgebox_init('a.edgebox, area.edgebox, input.edgebox');//pass where to apply thickbox
});


//add thickbox to href & area elements that have a class of .thickbox
function edgebox_init(domChunk){

    $(domChunk).click(function(){
    	    var t = this.title || this.name || null;
	    var a = this.href || this.alt;
	    var g = this.rel || false;
	    edgebox_show(t,a,g);
	    this.blur();
	    return false;
	});
}

function edgebox_show(caption, url, imageGroup) {//function called when the user clicks on a thickbox link
    $("body").append("<div id='edgebox_overlay'></div><div id='edgebox_window'></div>");
    $("#edgebox_overlay").click(edgebox_remove);


    var queryString = url.replace(/^[^\?]+\??/,'');
    var params = tb_parseQuery( queryString );


    TB_WIDTH = (params['width']*1) + 30 || 630; //defaults to 630 if no paramaters were added to URL
    TB_HEIGHT = (params['height']*1) + 40 || 440; //defaults to 440 if no paramaters were added to URL

    alert(TB_WIDTH);
    ajaxContentW = TB_WIDTH - 30;
    ajaxContentH = TB_HEIGHT - 45;

    $("#edgebox_window").append("<div id='edgebox_ajaxContent' class='edgebox_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");
    $("#edgebox_window").fadeIn("slow");



}




function edgebox_remove() {
 	$("#TB_imageOff").unbind("click");
	$("#TB_closeWindowButton").unbind("click");
	$("#edgebox_window").fadeOut("fast",function(){$('#edgebox_window,#edgebox_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 ( !($.browser.msie && $.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;
}

