function anyPopup(url,h,w){window.open(url,"TMZ","scrollbars=yes,location=no,directories=no,height="+h+",width="+w+",menubar=no");}


function flagComment(commentId, domId, url) {
    var commentAjax = new Ajax(url, {method: 'get', update: $(domId)});
    commentAjax.request();
}

var Gallery = new Class({
	
	initialize: function() {
		this.imageIndex = 0;
		this.amountOfClicks = 0;
		this.adShowInterval = 5; 						// How many clicks before showing an ad
		this.adDomId = 'interstitial_ad'; 	// The DOM ID of the interstitial ad
		this.showingAd = false;							// Are we showing an ad right now?
		this.displayInterstitialAds = true;
		this.adExists = false;
		this.imageArray = Array();
		this.magicNumbers = Array();
	},
	
	addImage: function(id, src, mn, description, credit) {
		this.imageArray.push([id, src, mn, description, credit]);
	},
	
	switchImage: function(idx) {
		
		this.imageIndex = idx;
		var img = this.imageArray[idx];
		
		// Switch all DOM elements that need it
		$('full_image').src = img[1];
		$('image_count').setHTML((idx + 1) + "/" + this.imageArray.length);
		$('full_image_description').setHTML(img[3]);
		$('full_image_credit').setHTML(img[4]);


		// Hide the ad if we're showing it
		if(this.showingAd) this.hideAd();
				
		// Deep linking
		document.location.href = document.location.href.split("#")[0] + "#" + (img[0]);
		
		// Setting Omniture vars -- the first two lines are heavy handed but have been agreed upon.
		s_265.prop12=document.location.href.split("?")[0].split("#")[0];
		s_265.pageURL=document.location.href.split("?")[0].split("#")[0] + "#" + (img[0]);
		s_265.campaign="";
		s_265.eVar16="";
		s_265.eVar18="";
		s_265.eVar19="";
		s_265.referrer="";
		var s_code=s_265.t(); 	// .t(); sends the impression to Omniture.
		var s_code2=s.t();

		this.recordHit(img[0]); // Required for comscore
	},
	
	shouldDisplayAd: function() {
	  if(this.displayInterstitialAds == false) return false;
		this.amountOfClicks++;
		return (this.amountOfClicks % this.adShowInterval) == 0;
	},
	
	// We display the ad by turning on the wrapper (black background) and then calling htmlAdWH as per the FIF_Ad_Refresh_Ad_Call_Instructions document
	displayAd: function() {
		this.showingAd = true;
		$('interstitial_ad_wrapper').setStyle("display", "block");
                $('full_image_mid').setStyle('z-index', '10005');
		$('image_count').setHTML("");
		$('full_image_description').setHTML("");
		$('full_image_credit').setHTML("");
		if(this.adExists) {
			adsReloadAd(this.adDomId);
		} else {
			htmlAdWH(this.magicNumbers[4], '300', '250', 'ajax', this.adDomId);
			this.adExists = true;
		}
	},
	
	// We hide the ad by calling adsClrAd as per the FIF_Ad_Refresh_Ad_Call_Instructions document, then hiding the wrapper div.
	hideAd: function() {
		//adsClrAd(this.adDomId);
		$('interstitial_ad_wrapper').setStyle("display", "none");
                $('full_image_mid').setStyle('z-index', '1');
		this.showingAd = false;
	},
	
	// This is only called during page load to facilitate deep linking. Note that this is probably bad for SEO.
	gotoImage: function(idx) {
		this.imageIndex = this.getIndexByID(idx);
		var img = this.imageArray[this.imageIndex];
		
		// Switch all DOM elements that need it
		$('full_image').src = img[1];
		$('image_count').setHTML((this.imageIndex + 1) + "/" + this.imageArray.length);
		$('full_image_description').setHTML(img[3]);
		$('full_image_credit').setHTML(img[4]);
	},
	
	recordHit: function(id) {
		new Ajax('/record_image_hit.html?id=' + id).request();
	},
	
	next: function() {
		// If we should display the add, short circuit the image switch and display the ad.
		if(this.shouldDisplayAd()) {
			this.displayAd();
		} else {
			this.imageIndex += 1;
			if (this.imageIndex >= this.imageArray.length)
				this.imageIndex = 0;
			this.switchImage(this.imageIndex);
		}
	},
	
	previous: function() {
		if(this.shouldDisplayAd()) {
			this.displayAd();
		} else {
			this.imageIndex -= 1;
			if (this.imageIndex <= -1)
				this.imageIndex = this.imageArray.length - 1;
			this.switchImage(this.imageIndex);
		}
	},
	
	getIndexByID: function(image_id) {
		for(var i = 0; i < this.imageArray.length; i++) {
			if(this.imageArray[i][0] == image_id) {
				return i;
			}
		}
		return 0;
	}
	
});

var g = new Gallery();

function addImage(id, src, mn, description, credit) {
	g.addImage(id, src, mn, description, credit);
}

function gotoImage(idx) {
	g.gotoImage(idx);
}

function switchImage(idx) {
	g.switchImage(idx);
}

function next() {
	g.next();
}

function previous() {
	g.previous();
}

/* www.tmz.com's common_aol_tmz.js
**********************************************/

var is_aol = navigator.userAgent.toLowerCase().indexOf("aol") != -1;
var is_mac = navigator.userAgent.indexOf('Mac') != -1;

// Start Channel 
function channel_init(){
}

// Header2.0
function p_o(o){return document.getElementById(o);}

function ai_posX(obj){
 var left=0;
 if(obj.offsetParent){
  while(obj.offsetParent){
   left+=obj.offsetLeft;
   obj=obj.offsetParent;
  }
 }else if(obj.x)left+=obj.x;
 return left;
}
function ai_posY(obj){
 var top=0;
 if(obj.offsetParent){
  while(obj.offsetParent){
   top+=obj.offsetTop;
   obj=obj.offsetParent;
  }
 } else if(obj.x)top+=obj.y;
 return top;
}

function togMore(e,state){
 var oDiv=p_o('smore');
 if(state=='show'){
  posMore(e);
  oDiv.style.zIndex=99999999;
  oDiv.style.display='block';
 } else {
  oDiv.style.display='none';
 }
 return false;
}
function posMore(e){
	var oDiv=p_o('smore');
	var oLnk=p_o('smorea');
	posY = findMousePos(e);
	oDiv.style.left=(ai_posX(oLnk)+-50)+'px';
	oDiv.style.top=(posY+oLnk.offsetHeight/2)+'px';
}
// Begin : Headers 2 code
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function srchSub(ref){
  var frm=p_o("search");
  var queryval = frm.topquery.value.trim();
  queryval = queryval.replace( /\+/, " ");
  newurl = ref.href + queryval;
  window.location = newurl;
  return false;
}

function searchTarget(parent, url, newWindow, newTarget) {
    form = jQuery(parent + ' form')[0];
    // Set the target for the form
    form.action = url;
    if (newWindow) {
        form.target = '_blank';
    } else {
        form.target = '';
    }
    
    jQuery(parent + ' .searchCatBg').removeClass('searchCatBg');
    document.getElementById(newTarget).className = 'searchCatBg';

    return false;
}

function getElementsByClassName(strClass, strTag, objContElm) {
  strTag = strTag || "*";
  objContElm = objContElm || document;
  var objColl = objContElm.getElementsByTagName(strTag);
  if (!objColl.length &&  strTag == "*" &&  objContElm.all) objColl = objContElm.all;
  var arr = new Array();
  var delim = strClass.indexOf('|') != -1  ? '|' : ' ';
  var arrClass = strClass.split(delim);
  for (var i = 0, j = objColl.length; i < j; i++) {
    var arrObjClass = objColl[i].className.split(' ');
    if (delim == ' ' && arrClass.length > arrObjClass.length) continue;
    var c = 0;
    comparisonLoop:
    for (var k = 0, l = arrObjClass.length; k < l; k++) {
      for (var m = 0, n = arrClass.length; m < n; m++) {
        if (arrClass[m] == arrObjClass[k]) c++;
        if (( delim == '|' && c == 1) || (delim == ' ' && c == arrClass.length)) {
          arr[arr.length] = objColl[i];
          //arr.push(objColl[i]);
          break comparisonLoop;
        }
      }
    }
  }
  return arr;
}

function eventIsEnterKey(event) {
    if (event && event.which == 13 || window.event && window.event.keyCode == 13 || event && event.which == 3 || window.event && window.event.keyCode == 3) {
        return true;
    }
    return false;
}

function submitHeaderSearch(parent, event) {
    if (event == "onclick" || eventIsEnterKey(event)) {
        return srchSub2(parent);        
    } else {
        return true;
    }
}

function srchSub2(parent) {
    var frm = jQuery(parent + ' form')[0];
    var queryval = frm.query.value.trim();
    queryval = queryval.replace( /\+/, " ");
    var newurl = frm.action + queryval;
    if (frm.target == '_blank') {
        window.open(newurl, '_blank', '');
    } else {
        window.location = newurl;
    }
    return false;
}

//adRefresh
function adRefresh() {
var adSpots = '0';
try {
if (pgAdSpots != null && pgAdSpots != 'undefined' && pgAdSpots != '') {
adSpots = pgAdSpots;
}
} catch(e) {
adSpots = '0';
}
try {
top.ch_refresher.refresh_ads_by_spot(adSpots);
} catch(e) { }
return true;
}

// NON-MODULE CODE
function popup_window(url,width,height){
	var features="status=0,menubar=0,location=0,toolbar=0";
	if (!isNaN(parseInt(width))){features+=",width="+width;}
	if (!isNaN(parseInt(height))){features+=",height="+height;}
	if (typeof(window.screenLeft)!="undefined"){
		features+=",left="+window.screenLeft;
		features+=",left="+Math.round(window.screenLeft+((document.body.clientWidth/2)-(width/2)));
	} else if (typeof(window.screenX)!="undefined"){
		features+=",left="+Math.round(window.screenX+((window.outerWidth/2)-(width/2)));
	}
	if (typeof(window.screenTop)!="undefined"){
		features+=",top="+window.screenTop;
		features+=",top="+Math.round(window.screenTop+150);
	} else if (typeof(window.screenY)!="undefined"){
		features+=",top="+Math.round(window.screenY+((window.outerHeight-window.innerHeight)+150));
	}
	var popupWin=window.open(url,"popupWin",features);
	if (popupWin.focus){popupWin.focus();}
}

function popupWindow(url,width,height,features) {
	if (!isNaN(parseInt(width))){features+=",width="+width;}
	if (!isNaN(parseInt(height))){features+=",height="+height;}
	if (typeof(window.screenLeft)!="undefined"){
		features+=",left="+window.screenLeft;
		features+=",left="+Math.round(window.screenLeft+((document.body.clientWidth/2)-(width/2)));
	} else if (typeof(window.screenX)!="undefined"){
		features+=",left="+Math.round(window.screenX+((window.outerWidth/2)-(width/2)));
	}
	if (typeof(window.screenTop)!="undefined"){
		features+=",top="+window.screenTop;
		features+=",top="+Math.round(window.screenTop+150);
	} else if (typeof(window.screenY)!="undefined"){
		features+=",top="+Math.round(window.screenY+((window.outerHeight-window.innerHeight)+150));
	}
	var popupWin=window.open(url,"popupWin",features);
	//if (popupWin.focus){popupWin.focus();}
}

// gets the value of the query string
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
}

navigator.userAgent.toLowerCase().indexOf('msie')!=-1?bb_ie=1:bb_ie=0;

function bb_o(o){return document.getElementById(o);}

function bb_l(o){return o.getElementsByTagName("li");}

//Dynamic CSS manipulation tools.
function setClassByID(objectID, newClass)
{
        var object = document.getElementById(objectID);
        object.className = newClass;
}

function setClassByObj(senderObj, newClass)
{
        senderObj.className = newClass;
}

//This function recursivelly finds a DIV in a parent element.
//It is needed because the mozilla and ie doms have different hierarchies.
//Called from hiLiteRow, a top11deeplink function.
function recurseDiv(el)
{
        if (el.nodeName == "DIV")
        {
                return el;
        }
        else if (el.hasChildNodes)
        {
                for (i = 0 ; i < el.childNodes.length; i++)
                {
                        if (el.childNodes[i].nodeName == "DIV")
                        {
                                return el.childNodes[i];
                        }
                        else if (el.childNodes[i].hasChildNodes)
                        {
                                var returnEl = recurseDiv(el.childNodes[i]);
                                if (returnEl) return returnEl;
                        }
                }
        }
        else
        {return null};
}

function rsiAdInit(segmax) {

    var segQS="";
    var segs_beg=document.cookie.indexOf('rsi_segs=');
    if(segs_beg>=0){
        segs_beg=document.cookie.indexOf('=',segs_beg)+1;
        if(segs_beg>0){
            var segs_end=document.cookie.indexOf(';',segs_beg);
            if(segs_end==-1)segs_end=document.cookie.length;
            rsi_segs=document.cookie.substring(segs_beg,segs_end).split('|');
            for (var i=0;i<Math.min(segmax,rsi_segs.length);i++){
                segQS+=rsi_segs[i].replace(/.*_(.*)/,"rsi=$1;");
            }
            adSetOthDclk(segQS);
       }
    }
}
