

/*
 * 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
*/

//reassign the document.domain

try {
    var myTldHostDomain = "";
    var currentPageHref = location.href.toString();
    var myUri = currentPageHref.split("://");
    var myHostUri = myUri[1].split("/");
    var myTld = myHostUri[0].split(".");
    
    len = myTld.length;

    myTldHostDomain = myTld[len-2] + "." + myTld[len-1];

    if(myTldHostDomain != "")
	{
	    document.domain = myTldHostDomain;
	}
} catch (ex) {
    //console.log(ex);
    
}

window.onerror = function() { return true; }

var $_hm_j = jQuery.noConflict();

 
var tb_pathToImage = "/signup/scripts/loadingAnimation.gif";
var __se_tb_resizeEleId = "";
var __tb_params = "";

var __se_imgCache = new Array();
$_hm_j(document).ready(function(){
	__se_imgCache['tb_next'] = new Image();// preload image
	__se_imgCache['tb_next'].src = "/signup/css/next_button.jpg";
    });

var __myHrefPages = new Array();
var __lastWindowLoc = "";
/**
    try {
	__lastWindowLoc = window.location.href;
	if(__lastWindowLoc.indexOf("#")!=-1)
	    {
		var clean = __lastWindowLoc.split("#");
		window.location.href = clean[0];
		__lastWindowLoc = clean[0];
	    }
    } catch (ex) {

    }
**/
var __wasNavClick = true;
var __wasBackNav = false;

function __se_check_history()
{
    return;
    try {
    if(this.location.href != __lastWindowLoc)
	{
	    if(!__wasNavClick)
		{
		    __lastWindowLoc = location.href;

		    var myLoc = location.href;
		    if(__myHrefPages[myLoc] && myLoc[myLoc.length-1] != "#")
			{
			    // console.log(__myHrefPages[myLoc]);
			    var toNav = __myHrefPages[myLoc];


			    //this should be a map here..

			    if(toNav.args)
			     {
				    __wasBackNav =true;
				    tb_show.apply(null, toNav.args);
			     } else {
				try_tb_remove();

			    }
			    __myHrefPages[myLoc] = false;		      
			} else {
			try_tb_remove();

		    }
       	    } else {

		    }
		//this was a tb_user_click 
		//tb should catch it

    }
	    __wasNavClick = false;
	    __lastWindowLoc = this.location.href;	   	
	    __wasBackNav = false;	 
	    __windowClick = false;
	    


    } catch (ex) {


    }
}

var __se_check_history_ival;

function __start_se_check_history()
{

    //    clearInterval(__se_check_history_ival);
    //  __se_check_history_ival = setInterval(__se_check_history,500);    
}

function __stop_se_check_history()
{
    //    __myHrefPages = new Array();
    //    clearInterval(__se_check_history_ival);
    //  __lastWindowLoc = this.location.href;

}



function __se_cache_next(src)
{
    if(src && src.toLowerCase().indexOf(".jpg") != -1)
	{
	    var id = parseInt(Math.random() *12345678);
	    __se_imgCache[id] = new Image();// preload image
	    __se_imgCache[id].src = src;
	}
}


try {

if ( document.all && !window.opera && !window.XMLHttpRequest && $_hm_j.browser.msie )
    {var isIE6 = true;}
else
    { var isIE6 = false;} ;
$_hm_j.browser.msie6 = isIE6;

} catch (ex) {
}



//add thickbox to href & area elements that have a class of .thickbox
function tb_init(domChunk){
	$_hm_j(domChunk).click(function(){
	var t = this.title || this.name || null;
	var a = this.href || this.alt;
	var g = this.rel || false;
	tb_show(t,a,g);
	this.blur();
	return false;
	});
}

function tb_show(caption, url, imageGroup, myTourLink, myGallInfo, mySignupHref) {
    $_hm_j(this).wresize(__se_tb_resize);
    //    _se_fj_t(url);
    __start_se_check_history();
//function called when the user clicks on a thickbox link

    var catchEscapeKey = true;

		var baseURL;
	   if(url.indexOf("?")!=-1){ //ff there is a query string involved
			baseURL = url.substr(0, url.indexOf("?"));
	   }else{ 
	   		baseURL = url;
	   }

	   if(0)
	       {
	   //keep track of our history here

			try 
			    {
			       
					if(!__wasBackNav)
					    {
						var windowLoc = "";
						var windowLocDirty = location.href;
					if(windowLocDirty.indexOf("#")>0)
					{
					    windowLoc = windowLocDirty.split("#");
					    windowLoc = windowLoc[0];

				        } else {
					    windowLoc = windowLocDirty;
					}

				
						windowLoc = windowLoc + "#"+(parseInt(Math.random()*12345 + Math.random()*34567)+2);
					
						__myHrefPages[windowLoc] = {'myPrevHref':location.href, 'args':arguments};
						//		console.log("doing window.location.href"+this.location.href);
						try {
						    //				window.location.href = windowLoc;
						} catch (ex) {

						}
					    }


					__wasBackNav = false;
					__wasNavClick = true;
					
			    } catch (ex) {

			}
			//end history track
	

	       }
    var myNextImg ='';
    var isJpgSlideshow = false;
    var mySignupPageLink = '';
    if(typeof myGallInfo != "undefined")
	{

	    isJpgSlidehow = true;
	    var lastGallImg= '';
	    for(var i in myGallInfo)
		{
		    
		    if(lastGallImg != '')
			{
			    myNextImg = myGallInfo[i];
			    break;
			}
		    
		    if(myGallInfo[i] == baseURL)
			lastGallImg = myGallInfo[i];
		}

    //if we have isJpgSlideshow && myNextImg show a next arrow btn, otherwise do our hard sell	

	    if(myNextImg == '' || typeof myNextImg == "undefined")
		{
		    myNextImg = mySignupHref;
		} else {

		//var galInfo = {'362' : { 'hirez_count' : '0', 'pic_count' : '157', 'video_count': '0' } };
		var my_pic_count=0;
		var my_gal_id=0;
		//global
		if(typeof galInfo != "undefined")
		    {
			for(j in galInfo)
			    {
				if(galInfo[j].pic_count > my_pic_count)
			    {
				my_pic_count = galInfo[j].pic_count;
				my_gal_id=j;

			    }
		    }
		    }

		

		if(my_gal_id && my_pic_count)
		    {
			mySignupPageLink = "<a style='text-decoration:underline;cursor:pointer;' onclick=\"javascript:tb_show('','"+mySignupHref+"?set_publish::id="+my_gal_id+"&TB_iframe=1', '','"+myTourLink+"');\">Join now to see all "+my_pic_count+" pics from this set!</a>";

		    } else {
			mySignupPageLink = "<a style='text-decoration:underline;cursor:pointer;' onclick=\"javascript:tb_show('','"+mySignupHref+"?set_publish::id="+my_gal_id+"&TB_iframe=1', '','"+myTourLink+"');\">Join now to see all my Hawt Pics and Vids!</a>";
		}
	    }
	       
	}



    var myTB_tourPageLink ='';
    if(myTourLink =='')

	{
	    myTourLink = "/";

	    //we should also investigate if the close should be in the top left, and have the iframe be a modal window?

	    //href="#"
	    myTB_TR_string = "<a id='TB_closeWindowButton' title='Close'>CLOSE (X)</a>";
	} else {
	if(myTourLink.indexOf("livephotos.mandymayhem.com") != -1)
	    {
		myTB_tourPageLink = "<b>Check out my LIVE SHOOT <a href='"+myTourLink+"' target='_blank' onClick='void(setTimeout(tb_remove, 100));' >HERE</a></b>";

	    } else {
	
	    if(myTourLink.indexOf("signup.php") != -1)
		myTB_tourPageLink = "<B><a href='"+myTourLink+"' id='TB_tourLinkButton'>Watch the rest of this scene HERE!</A></B>";
	    else
		    myTB_tourPageLink = "Not sure yet? <a href='"+myTourLink+"' id='TB_tourLinkButton' title='Preview'>Check out my tour preview!</a>";
	}
    }

	try {
		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
			$_hm_j("body","html").css({height: "100%", width: "100%"});
			$_hm_j("html").css("overflow","hidden");
			if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
				$_hm_j("body").append("<iframe id='TB_HideSelect' src='javascript:false' APPLICATION='yes'></iframe><div id='TB_overlay'></div><div id='TB_window'></div>");
				//$_hm_j("#TB_overlay").click(tb_remove);
			}
		}else{//all others
			if(document.getElementById("TB_overlay") === null){
				$_hm_j("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
				//$_hm_j("#TB_overlay").click(tb_remove);
			}
		}
		
		if(tb_detectMacXFF()){
			$_hm_j("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
		}else{
			$_hm_j("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
		}
		
		if(caption===null){caption="";}
		$_hm_j("body").append("<div id='TB_load'><img src='"+imgLoader.src+"' /></div>");//add loader to the page
		$_hm_j('#TB_load').show();//show loader
		

	   
	   var urlString = /\.jpg$_hm_j|\.jpeg$_hm_j|\.png$_hm_j|\.gif$_hm_j|\.bmp$_hm_j/;
	   var urlType = baseURL.toLowerCase().match(urlString);


	   if(urlType == '.jpg' || urlType == '.jpeg' || urlType == '.png' || urlType == '.gif' || urlType == '.bmp'){//code to show images
	       
	       TB_PrevCaption = "";
	       TB_PrevURL = "";
	       TB_PrevHTML = "";
	       TB_NextCaption = "";
	       TB_NextURL = "";
	       TB_NextHTML = "";
	       TB_imageCount = "";
	       TB_FoundURL = false;
	       if(imageGroup){
		   TB_TempArray = $("a[@rel="+imageGroup+"]").get();
		   for (TB_Counter = 0; ((TB_Counter < TB_TempArray.length) && (TB_NextHTML === "")); TB_Counter++) {
		       var urlTypeTemp = TB_TempArray[TB_Counter].href.toLowerCase().match(urlString);
		       if (!(TB_TempArray[TB_Counter].href == url)) {
			   if (TB_FoundURL) {
			       TB_NextCaption = TB_TempArray[TB_Counter].title;
			       TB_NextURL = TB_TempArray[TB_Counter].href;
			       TB_NextHTML = "<span id='TB_next'>&nbsp;&nbsp;<a href='#'>Next &gt;</a></span>";
			   } else {
			       TB_PrevCaption = TB_TempArray[TB_Counter].title;
			       TB_PrevURL = TB_TempArray[TB_Counter].href;
			       TB_PrevHTML = "<span id='TB_prev'>&nbsp;&nbsp;<a href='#'>&lt; Prev</a></span>";
			   }
		       } else {
			   TB_FoundURL = true;
			   TB_imageCount = "Image " + (TB_Counter + 1) +" of "+ (TB_TempArray.length);
		       }
		   }
	       }

	       imgPreloader = new Image();
	       imgPreloader.onload = function(){
		   imgPreloader.onload = null;
		   
		   // Resizing large images - orginal by Christian Montoya edited by me.
		   var pagesize = tb_getPageSize();
		   var x = pagesize[0] - 350;
		   var y = pagesize[1] - 350;
		   var imageWidth = imgPreloader.width;
		   var imageHeight = imgPreloader.height;
		   if (imageWidth > x) {
		       imageHeight = imageHeight * (x / imageWidth); 
		       imageWidth = x; 
		       if (imageHeight > y) { 
			   imageWidth = imageWidth * (y / imageHeight); 
			   imageHeight = y; 
		       }
		   } else if (imageHeight > y) { 
		       imageWidth = imageWidth * (y / imageHeight); 
		       imageHeight = y; 
		       if (imageWidth > x) { 
			   imageHeight = imageHeight * (x / imageWidth); 
			   imageWidth = x;
		       }
		   }
		   // End Resizing
		   
		   TB_WIDTH = imageWidth + 30;
		   TB_HEIGHT = imageHeight + 60;
		   $("#TB_window").append("<a  id='TB_ImageOff' title='Close'><img id='TB_Image' src='"+url+"' width='"+imageWidth+"' height='"+imageHeight+"' alt='"+caption+"'/></a>" + "<div id='TB_caption'>"+caption+"<div id='TB_secondLine'>" + TB_imageCount + TB_PrevHTML + TB_NextHTML + "</div></div><div id='TB_closeWindow'><a id='TB_closeWindowButton' title='Close'>close</a> or Esc Key</div>"); 
		   
		   $("#TB_closeWindowButton").click(tb_remove);
		   
		   if (!(TB_PrevHTML === "")) {
		       function goPrev(){
			   if($(document).unbind("click",goPrev)){$(document).unbind("click",goPrev);}
			   $("#TB_window").remove();
			   $("body").append("<div id='TB_window'></div>");
			   tb_show(TB_PrevCaption, TB_PrevURL, imageGroup);
			   return false;
		       }
		       $("#TB_prev").click(goPrev);
		   }
		   
		   if (!(TB_NextHTML === "")) {
		       function goNext(){
			   $("#TB_window").remove();
			   $("body").append("<div id='TB_window'></div>");
			   tb_show(TB_NextCaption, TB_NextURL, imageGroup);
			   return false;
		       }
		       $("#TB_next").click(goNext);
		       
		   }

		   document.onkeydown = function(e){ 
		       if (e == null) { // ie
			   keycode = event.keyCode;
		       } else { // mozilla
			   keycode = e.which;
		       }
		       if(keycode == 27){ // close
			   tb_remove();
		       } else if(keycode == 190){ // display previous image
			   if(!(TB_NextHTML == "")){
			       document.onkeydown = "";
			       goNext();
			   }
		       } else if(keycode == 188){ // display next image
			   if(!(TB_PrevHTML == "")){
			       document.onkeydown = "";
			       goPrev();
			   }
		       }
		   };
		   
		   tb_position();
		   $("#TB_load").remove();
		   $("#TB_ImageOff").click(tb_remove);
		   $("#TB_window").css({display:"block"}); //for safari using css instead of show
	       };
	       
	       imgPreloader.src = url;
	   }else{//code to show html



			var queryString = url.replace(/^[^\?]+\??/,'');
			var params = tb_parseQuery( queryString );
			__tb_params = params;
			//2008-08-06 - add in max iframe size
			    var mySizes = getIframeSize();
			TB_HEIGHT = mySizes[0];
			ajaxContentH = mySizes[1];
			TB_WIDTH = mySizes[2];
			ajaxContentW= mySizes[3];




			//	      	    TB_HEIGHT = pagesize[1]-40;
			//                  ajaxContentH = TB_HEIGHT -36;
			//                  TB_WIDTH = Math.min(1100,pagesize[0] - 200);
			//                  ajaxContentW = TB_WIDTH - 30;
				


			
			if(url.indexOf('TB_iframe') != -1){// either iframe or ajax window		
					urlNoQuery = url.split('TB_');
					
					//alert(urlNoQuery[0][urlNoQuery[0].length-1]);
					var myQ = urlNoQuery[0];
					//			
					//					alert(myQ);
					if(myQ.charAt(myQ.length -1) == "&")
					{
					    urlNoQuery[0] = urlNoQuery[0].substring(0, urlNoQuery[0].length-1);
					    //alert(myQ);
					} else if(myQ.charAt(myQ.length-1) == "?") {
					    urlNoQuery[0] = urlNoQuery[0].substring(0, urlNoQuery[0].length-1);
					}

					cleanUrl = url.split('?');					
					$_hm_j("#TB_iframeContent").remove();
				        $_hm_j("#TB_window").css({display:"block"});
					
					//inline slideshow
					if(url.toLowerCase().indexOf(".jpg")>0)
					{


					    $_hm_j("#TB_load").remove();
					    var mySizes = getImgIframeSize();
					    TB_HEIGHT = mySizes[0];
					    ajaxContentH = mySizes[1];
					    TB_WIDTH = mySizes[2];
					    ajaxContentW= mySizes[3];

					    if(($_hm_j("#TB_window").children("*").length)>1)
						{

						    $_hm_j("#TB_window").remove();
						    $_hm_j("body").append("<div id='TB_window'></div>");			     
						    $_hm_j("#TB_window").css({display:"block"});
						    
						}

					    var myBgStyle = "";
					    try {
						if(cleanUrl && cleanUrl[0] && cleanUrl[0].indexOf("mandymayhem.com/") != -1)
						{
						    myBgStyle = "background: url(/images/live_mayhem_bg.jpg) repeat;";
						}
					    } catch (ex) {

					    }
					    myTBHtml = "<div id='TB_title' style='width:"+(ajaxContentW+30)+"px;'><div id='TB_ajaxWindowTitle' style='font-weight:bold;'>"+mySignupPageLink+"</div><div id='TB_ajaxWindowTitle' style='margin:0 auto;'>"+myTB_tourPageLink + 

 	"</div><div id='TB_closeAjaxWindow' style='width:100px;'><a  id='TB_closeWindowButton' title='Close'>CLOSE (X)</a></div></div>" +  

						"<div id='TB_imgiframeContent' name='TB_imgiframeContent"+Math.round(Math.random()*1000)+"' style='height:"+ajaxContentH+"px;width:"+(ajaxContentW+30)+"px;left:0px;top:0px;"+myBgStyle+"'>" +

						"<div id='TB_imgContainerContent' style='position:absolute;top:27px;left:0px;overflow:auto;width:"+(ajaxContentW+30)+"px;height:"+ajaxContentH+"px;text-align:center;'>" +
"<img src='"+cleanUrl[0]+"' style='border: solid black 2px;margin-2px;' onLoad='__se_cache_next(\""+myNextImg+"\");' ></div>"+

"<div id='TB_nextBtn' style='position:absolute; left:12px;top:28px;'>"+

"<a style='cursor:pointer;' onclick=\"javascript:tb_show('','"+myNextImg+"?TB_iframe=1', '','"+myTourLink+"', allImgs,'"+mySignupHref+"');\"><img src='/signup/css/next_button.jpg' border=0></a></div>" +

" </div>";
					    __se_tb_resizeEleId = "TB_imgiframeContent";
					    //pull our X/Y
					    var myScrollY = $_hm_j("html").get(0).scrollTop;
					    var myScrollX = $_hm_j("html").get(0).scrollLeft;

					    $_hm_j("html").css("overflow","hidden");
					    setTimeout(function() { window.scrollTo(myScrollX, myScrollY); });
					    $_hm_j("#TB_window").css("margin-left","0px");
					    skipMargin=true;
					    $_hm_j("#TB_window").append(myTBHtml);


  //  style='margin:0 auto;width:100%;height:"+(ajaxContentH + 17)+"px;backround-color:#666666;text-align:center;' ALLOWTRANSPARENCY=true  > </iframe>");

					    } else if(params['modal'] != "true"){					   
	                                            $_hm_j("#TB_load").remove();


		                                if($_hm_j("#TB_window").children("*").length>1)
                                                {
                                                    $_hm_j("#TB_window").remove();
                                                    $_hm_j("body").append("<div id='TB_window'></div>");
                                                    $_hm_j("#TB_window").css({display:"block"});
                                                }
						//jdj2008-10-08
						$_hm_j("#TB_overlay").click(tb_remove);

					catchEscapeKey = true;
				      
					$_hm_j("#TB_window").append("<div id='TB_title' style='width:"+(ajaxContentW+30)+"px;'><div id='TB_ajaxWindowTitle' style='padding-left:20px;margin:0 auto;'>"+myTB_tourPageLink+"</div><div id='TB_closeAjaxWindow'  style='width:100px;'><a  id='TB_closeWindowButton' title='Close'>CLOSE (X)</a></div></div><iframe APPLICATION='yes' frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"' style='width:"+(ajaxContentW + 30)+"px;height:"+(ajaxContentH + 17)+"px;' ></iframe>");
					__se_tb_resizeEleId = "TB_iframeContent";


					}else{//iframe modal

					                                                $_hm_j("#TB_load").remove();

					    //get rid fo an existing modal
					    if($_hm_j("#TB_window").children("*").length>1)
                                                {
                                                    $_hm_j("#TB_window").remove();
                                                    $_hm_j("body").append("<div id='TB_window'></div>");
                                                    $_hm_j("#TB_window").css({display:"block"});
                                                }



					    
					    		    $_hm_j("#TB_overlay").unbind();
					    $_hm_j("#TB_window").append("<iframe APPLICATION='yes' frameborder='0' hspace='0' src='"+urlNoQuery[0]+"' id='TB_iframeContent' name='TB_iframeContent"+Math.round(Math.random()*1000)+"'  style='width:"+(ajaxContentW + 30)+"px;height:"+(ajaxContentH + 17)+"px;'></iframe>");
					   __se_tb_resizeEleId = "TB_iframeContent";

					}
			}else{// not an iframe, ajax
			    __se_tb_resizeEleId='';
					if($_hm_j("#TB_window").css("display") != "block"){
						if(params['modal'] != "true"){//ajax no modal
						$_hm_j("#TB_window").append("<div id='TB_title'><div id='TB_ajaxWindowTitle'>"+caption+"</div><div id='TB_closeAjaxWindow'><a id='TB_closeWindowButton'>close</a> or Esc Key</div></div><div id='TB_ajaxContent' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px'></div>");
						}else{//ajax modal
						$_hm_j("#TB_overlay").unbind();
						$_hm_j("#TB_window").append("<div id='TB_ajaxContent' class='TB_modal' style='width:"+ajaxContentW+"px;height:"+ajaxContentH+"px;'></div>");	
						}
					}else{//this means the window is already up, we are just loading new content via ajax
						$_hm_j("#TB_ajaxContent")[0].style.width = ajaxContentW +"px";
						$_hm_j("#TB_ajaxContent")[0].style.height = ajaxContentH +"px";
						$_hm_j("#TB_ajaxContent")[0].scrollTop = 0;
						$_hm_j("#TB_ajaxWindowTitle").html(caption);
					   					}
					//								}			
			}


					
			$_hm_j("#TB_closeWindowButton").click(__se_hist_tb_remove);
			
				if(url.indexOf('TB_inline') != -1){	
					$_hm_j("#TB_ajaxContent").append($_hm_j('#' + params['inlineId']).children());
					$_hm_j("#TB_window").unload(function () {
						$_hm_j('#' + params['inlineId']).append( $_hm_j("#TB_ajaxContent").children() ); // move elements back when you're finished
					});
					tb_position();
					$_hm_j("#TB_load").remove();
					$_hm_j("#TB_window").css({display:"block"}); 
				}else if(url.indexOf('TB_iframe') != -1){
					tb_position();
					if($_hm_j.browser.safari){//safari needs help because it will not fire iframe onload
						$_hm_j("#TB_load").remove();
						$_hm_j("#TB_window").css({display:"block"});
					}
				}else{
					$_hm_j("#TB_ajaxContent").load(url += "&random=" + (new Date().getTime()),function(){//to do a post change this load method
						tb_position();
						$_hm_j("#TB_load").remove();
						//tb_init("#TB_ajaxContent a.thickbox");
						$_hm_j("#TB_window").css({display:"block"});
					});
				}
			
		}

		if(!params['modal'] || catchEscapeKey){
			document.onkeyup = function(e){ 	
				if (e == null) { // ie
					keycode = event.keyCode;
				} else { // mozilla
					keycode = e.which;
				}
				if(keycode == 27){ // close
					tb_remove();
				}	
			};
		}
		
	} catch(e) {
	    //alert(e);		
	    //nothing here
	}
}

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

function __se_hist_tb_remove()
{
    __wasNavClick = true;
    try {

	__stop_se_check_history();
    } catch (ex) {

    }

    tb_remove();
}


function try_tb_remove()
{
    try {
	tb_remove();
    } catch (ex) {

    }
}

function tb_remove() {
	/**

2008-08-12 - cut this
    try {

	   thi si no longer needed
var myWin = $_hm_j('#TB_window').get(0);
    var objects = myWin.getElementsByTagName("OBJECT");
    for (var i = objects.length - 1; i >= 0; i--) {
	objects[i].style.display = 'none';
	for (var x in objects[i]) {
	    if (typeof objects[i][x] == 'function') {
		objects[i][x] = function(){};
	    }
	}
    }


    } catch (ex) {

    }
	**/




    //   $_hm_j("#TB_iframeContent").each(function() { this.src = 'http://funneltube.com/c.html';});

    //    setTimeout(__tb_reframe_delay, 50);
    __tb_reframe_delay();

}
 

function __tb_reframe_delay()
{
    try {
    __se_tb_resizeEleId = "";
    __tb_params = false;

    //    $_hm_j("#TB_iframeContent").each(function() { this.src = 'http://funneltube.com/c.html';});
  $_hm_j("#TB_iframeContent").each(function() { this.src = '';});



    $_hm_j(this).unbind("resize",__se_tb_resize);
    $_hm_j("#TB_imageOff").unbind("click");
	$_hm_j("#TB_closeWindowButton").unbind("click");
	//	$_hm_j("#TB_window").fadeOut("fast",function(){$_hm_j('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();});
	$_hm_j('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind().remove();

	$_hm_j("#TB_load").remove();
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		$_hm_j("body","html").css({height: "auto", width: "auto"});
		$_hm_j("html").css("overflow","");
	}
		$_hm_j("html").css("overflow","");
	document.onkeydown = "";
	document.onkeyup = "";

    } catch (ex) {

    }
	return false;
}


var skipMargin = false;
function tb_position() {

    /**
$_hm_j("#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
		$_hm_j("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
	}

    if(jQuery.browser.msie && !(jQuery.browser.msie6))
	{
	    $_hm_j("#TB_window").css({position: 'fixed'});
	}
    **/


    $_hm_j("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});


    if ( !(jQuery.browser.msie6)) { // take away IE6
	$_hm_j("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
    } 

}

function __se_tb_resize()
{
    //    __se_tb_resizeEleId = "TB_imgiframeContent";
    //
    if(__se_tb_resizeEleId != "")
	{
	    if(__se_tb_resizeEleId == "TB_imgiframeContent")
		{
		    //
		    mySizes = getImgIframeSize();

		    $_hm_j("#TB_imgiframeContent,#TB_imgContainerContent").css("height",mySizes[1]);
		    //we are +30 for some reason?..
		    $_hm_j("#TB_imgiframeContent,#TB_imgContainerContent,#TB_title").css("width",mySizes[3]+30);


		    //		    console.log("doing:"+__se_tb_resizeEleId);
		} else if (__se_tb_resizeEleId  == "TB_iframeContent") {
		mySizes = getIframeSize();

		$_hm_j("#TB_iframeContent").css("height",mySizes[1]+17);
		$_hm_j("#TB_iframeContent,#TB_title").css("width",mySizes[3]+30);
	    } else {
		mySizes = getIframeSize();

                $_hm_j("#TB_iframeContent").css("height",mySizes[1]+17);
                $_hm_j("#TB_iframeContent").css("width",mySizes[3]+30);
	    }
	    
	    tb_position();
	}

    //    var w = $_hm_j( window );
    // var H = w.height();
    // var W = w.width();
    //   console.log("w is now W"+W+", h is now H:"+H);
}


function getIframeSize(s)
{
    var params = __tb_params;
    var pagesize = tb_getPageSize();

    TB_WIDTH = Math.min(pagesize[0]-30, (params['width']*1) + 30 || 890); //defaults to 630 if no paramaters were added to URL
    TB_HEIGHT = Math.min(pagesize[1]-40, (params['height']*1) + 40 || 570); //defaults to 440 if no paramaters were added to URL
    ajaxContentW = TB_WIDTH - 30;
    ajaxContentH = TB_HEIGHT - 36;

    return [TB_HEIGHT,ajaxContentH,TB_WIDTH,ajaxContentW];
}



function getImgIframeSize()
{
    var pagesize = tb_getPageSize();
    TB_HEIGHT = pagesize[1]-40;
    ajaxContentH = TB_HEIGHT -36;
    TB_WIDTH = Math.min(1100,pagesize[0] - 200);
    ajaxContentW = TB_WIDTH - 30;

    return [TB_HEIGHT,ajaxContentH,TB_WIDTH,ajaxContentW];
}


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;
  }
}

