//"Accept terms" form submission- By Dynamic Drive
//For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
//This credit MUST stay intact for use

var checkobj

function agreesubmit(el){
checkobj=el
if (document.all||document.getElementById){
for (i=0;i<checkobj.form.length;i++){  //hunt down submit button
var tempobj=checkobj.form.elements[i]
if(tempobj.type.toLowerCase()=="submit")
tempobj.disabled=!checkobj.checked
}
}
}

function defaultagree(el){
if (!document.all&&!document.getElementById){
if (window.checkobj&&checkobj.checked)
return true
else{
alert("Please read/accept terms to submit form")
return false
}
}
}

//for tmz email alerts
function validate_policy_agreement() {
  if(document.forms.alertsform.alertspolicycheck.checked) {
    return true;
  } else {
    alert("Please confirm that you have read and agree to the TMZ.com Privacy Policy by checking the box before you click subscribe.");
    return false;
  }
}

function makehomepage(target) {
	// sniff user agent for browser
	var exclude=1;
	var agt=navigator.userAgent.toLowerCase();
	var win=0;var mac=0;var lin=1;
	if(agt.indexOf('win')!=-1){win=1;lin=0;}
	if(agt.indexOf('mac')!=-1){mac=1;lin=0;}
	var lnx=0;if(lin){lnx=1;}
	var ice=0;
	var ie=0;var ie4=0;var ie5=0;var ie6=0;var com=0;var dcm;
	var op5=0;var op6=0;var op7=0;
	var ns4=0;var ns6=0;var ns7=0;var mz7=0;var kde=0;var saf=0;
	if(typeof navigator.vendor!="undefined" && navigator.vendor=="KDE"){
		var thisKDE=agt;
		var splitKDE=thisKDE.split("konqueror/");
		var aKDE=splitKDE[1].split("; ");
		var KDEn=parseFloat(aKDE[0]);
		if(KDEn>=2.2){
			kde=1;
			ns6=1;
			exclude=0;
			}
		}
	else if(agt.indexOf('webtv')!=-1){exclude=1;}
	else if(typeof window.opera!="undefined"){
		exclude=0;
		if(/opera[\/ ][5]/.test(agt)){op5=1;}
		if(/opera[\/ ][6]/.test(agt)){op6=1;}
		if(/opera[\/ ][7-9]/.test(agt)){op7=1;}
		}
	else if(typeof document.all!="undefined"&&!kde){
		exclude=0;
		ie=1;
		if(typeof document.getElementById!="undefined"){
			ie5=1;
			if(agt.indexOf("msie 6")!=-1){
				ie6=1;
				dcm=document.compatMode;
				if(dcm!="BackCompat"){com=1;}
				}
			}
		else{ie4=1;}
		}
	else if(typeof document.getElementById!="undefined"){
		exclude=0;
		if(agt.indexOf("netscape/6")!=-1||agt.indexOf("netscape6")!=-1){ns6=1;}
		else if(agt.indexOf("netscape/7")!=-1||agt.indexOf("netscape7")!=-1){ns6=1;ns7=1;}
		else if(agt.indexOf("gecko")!=-1){ns6=1;mz7=1;}
		if(agt.indexOf("safari")!=-1 || (typeof document.childNodes!="undefined" && typeof document.all=="undefined" && typeof navigator.taintEnabled=="undefined")){mz7=0;ns6=1;saf=1;}
		}
	else if((agt.indexOf('mozilla')!=-1)&&(parseInt(navigator.appVersion)>=4)){
		exclude=0;
		ns4=1;
		if(typeof navigator.mimeTypes['*']=="undefined"){
			exclude=1;
			ns4=0;
			}
		}
	if(agt.indexOf('escape')!=-1){exclude=1;ns4=0;}
	if(typeof navigator.__ice_version!="undefined"){exclude=1;ie4=0;}

	// if IE make this the homepage
	if(ie) {
		target.style.behavior='url(#default#homepage)';
		target.setHomePage('http://www.tmz.com/');
	}

	// if safari go to safari page
	if(saf) {
		window.location = "http://www.tmz.com/maketmzmyhomepage_safari"
	}

	// if firefox go to firefox page
	if(mz7) {
		window.location = "http://www.tmz.com/maketmzmyhomepage_firefox"
	}

	return false;
}

//BEGIN MOBILE ALERTS AJAX FORM
  var tmz_malerts_xreq = false;
  var TMZ_QWAPI_PROXY = "http://www.tmz.com/qwapi_proxy.php";

  function tmz_init_request() {
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
      tmz_malerts_xreq = new XMLHttpRequest();
      if (tmz_malerts_xreq.overrideMimeType) { tmz_malerts_xreq.overrideMimeType('text/html'); }
      } else if (window.ActiveXObject) { // IE
         try {tmz_malerts_xreq = new ActiveXObject("Msxml2.XMLHTTP");} catch (e) {
            try {tmz_malerts_xreq = new ActiveXObject("Microsoft.XMLHTTP");} catch (e) {}}}
    if (!tmz_malerts_xreq) {return false;}
    return true; }
  function tmz_make_request(url, params) {
    if(!tmz_init_request()) { tmz_malerts_failed("Error, please try again."); return false; }
    tmz_malerts_xreq.open("POST", url, true);
    tmz_malerts_xreq.onreadystatechange = tmz_ajax_statechange;
    tmz_malerts_xreq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    tmz_malerts_xreq.setRequestHeader("Content-length", params.length);
    tmz_malerts_xreq.setRequestHeader("Connection", "close");
    tmz_malerts_xreq.send(params);
    return true; }
  function tmz_ajax_statechange() {
    if (tmz_malerts_xreq.readyState == 4) {
      if (tmz_malerts_xreq.status == 200) { tmz_malerts_success(); }
      else { tmz_malerts_failed("Submission Failed. Try again."); }}}
  function tmz_malerts_submit() {
    if((phoneNumber = tmz_malerts_number_validate())) {
      tmz_malerts_editable(false);
      tmz_malerts_status("Please wait...");
      tmz_make_request(TMZ_QWAPI_PROXY, "phoneNumber=" + phoneNumber); }
    else {
      tmz_malerts_failed("Invalid Number."); }}
  function tmz_malerts_number_validate() {
    re = /^[\s]*1?[\s\(]*(\d\d\d)[\s\.\-\)]*(\d\d\d)[\s\.\-]*(\d\d\d\d)[\s]*$/m;
    match = re.exec(document.getElementById("malerts-number").value);
    if (!match) { return false; }
    else { return match[1] + match[2] + match[3]; }}
  function tmz_malerts_success() { document.getElementById("malerts-wrap").innerHTML = "<p>You will now receive TMZ alerts on your phone!</p>"; }
  function tmz_malerts_failed(err) { tmz_malerts_editable(true); tmz_malerts_status(err); }
  function tmz_malerts_status(err) { document.getElementById("malerts-status").innerHTML = err; }
  function tmz_malerts_editable(b) {
    document.getElementById("malerts-number").disabled = !b;
    document.getElementById("malerts-button").disabled = !b; }
  function tmz_fix_height(id) { d = document.getElementById(id); d.style.height = d.offsetHeight+"px";}
//END MOBILE ALERTS AJAX FORM

//CRZ: makes the heights the same of all tags with id's in arr. Will not set tallest element's style.height.
  function tmz_equalize_heights (arr) {
    var largesse = 0, i=0;
    for (i=0; i< arr.length; i++) {
      if(document.getElementById(arr[i]).offsetHeight > largesse) {
        largesse = document.getElementById(arr[i]).offsetHeight;  }}
    for (i=0; i< arr.length; i++) {
      if(document.getElementById(arr[i]).offsetHeight != largesse) {
        document.getElementById(arr[i]).style.height = largesse.toString() + "px"; }}}

//CRZ: sets a negative margin for sidebar-bottom if needed. removes it if not needed.
//     should be run after onload and immediately after sidebar-bottom tag.
  function tmz_fix_bottomsidebar() {
    sbb = document.getElementById("sidebar-bottom");
    delta = document.getElementById("main").offsetHeight - document.getElementById("sidebar").offsetHeight;
    if(delta <= sbb.offsetHeight) { sbb.style.marginTop = "0px"; }
    else {
      sbb.style.marginTop = "-" + sbb.offsetHeight + "px"; }}


/* BCSinglePlayer.js
This script generates single title brightcove players for use on the TMZ main page and blog entry pages.  The player can be parameterized with a titleID to play.  Insert this call in the HTML where you want a player to appear:
 <script>insertBCSinglePlayer(000000000);</script>
where 0000000000 is the titleID of the title you want this player to display.
*/

// n stores the number of BC single title players that have been created so far, so we can generate
// unique ids for each one.
var n = 0;

function insertBCSinglePlayer(videoId) {

	var flashId = "f" + String(n);

	var str = '';
        str += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="480" height="316" id="inline" align="middle">';
        str += '<param name="allowScriptAccess" value="always" />';
        str += '<param name="allowFullScreen" value="true" />';
        str += '<param name="movie" value="http://tmz.vo.llnwd.net/o28/player/inline.swf?mediaKey=' + videoId + '"/>';
        str += '<param name="wmode" value="opaque">';
        str += '<param name="quality" value="high" />';
        str += '<param name="bgcolor" value="#ffffff" />';
        str += '<embed src="http://tmz.vo.llnwd.net/o28/player/inline.swf?mediaKey=' + videoId + '" quality="high" bgcolor="#ffffff" width="480" height="316" name="inline" align="middle" allowScriptAccess="always" wmode="opaque" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"/>';
        str += '</object>';


	// write the flash obj to the page
	document.write(str);

	// increment the counter
	n++;

}

// n stores the number of BC single title players that have been created so far, so we can generate
// unique ids for each one.
var n = 0;
// tmztv_embed_video : {% asset version?src=/swf/tmztv_embed_video.swf %}
function insertTMZTVpromovideo(videoId,tmztv_embed_video) {

	var flashId = "f" + String(n);

	var str = '';
	str += '<center>';
	str += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
	str += 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ';
	str += 'width="300" height="254" id="' + flashId + '" align="middle">';
	str += '<param name="allowScriptAccess" value="always" />';
	str += '<param name="movie" value="'+tmztv_embed_video+'?videoId=' + videoId + '&flashId=' + flashId + '" />';
        str += '<param name="wmode" value="opaque">';
	str += '<param name="quality" value="high" />';
	str += '<param name="bgcolor" value="#ffffff" />';
	str += '<embed src="'+tmztv_embed_video+'?videoId=' + videoId + '&flashId=' + flashId + '" quality="high" bgcolor="#ffffff" ';
	str += 'width="300" height="254" name="' + flashId + '" ';
	str += 'align="middle" allowScriptAccess="always" wmode="opaque" ';
	str += 'type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	str += '</object>';
	str += '</center>';

	// write the flash obj to the page
	document.write(str);

	// increment the counter
	n++;
}

// n stores the number of BC single title players that have been created so far, so we can generate
// unique ids for each one.
var n = 0;
// tmztv2_embed_video : {% asset version?src=/swf/tmztv2_embed_video.swf %}
function insertTMZTVembeddedvideo(videoId,tmztv2_embed_video) {

	var flashId = "f" + String(n);

	var str = '';
	str += '<center>';
	str += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"';
	str += 'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ';
	str += 'width="465" height="349" id="' + flashId + '" align="middle">';
	str += '<param name="allowScriptAccess" value="always" />';
	str += '<param name="movie" value="'+tmztv2_embed_video+'?videoId=' + videoId + '&flashId=' + flashId + '" />';
        str += '<param name="wmode" value="opaque">';
	str += '<param name="quality" value="high" />';
	str += '<param name="bgcolor" value="#ffffff" />';
	str += '<embed src="'+tmztv2_embed_video+'?videoId=' + videoId + '&flashId=' + flashId + '" quality="high" bgcolor="#ffffff" ';
	str += 'width="465" height="349" name="' + flashId + '" ';
	str += 'align="middle" allowScriptAccess="always" wmode="opaque" ';
	str += 'type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	str += '</object>';
	str += '</center>';

	// write the flash obj to the page
	document.write(str);

	// increment the counter
	n++;
}


;(function($){
	$.fn.superfish = function(op){

		var sf = $.fn.superfish,
			c = sf.c,
			$arrow = $(['<span class="',c.arrowClass,'"> &#187;</span>'].join('')),
			over = function(){
				var $$ = $(this), menu = getMenu($$);
				clearTimeout(menu.sfTimer);
				$$.showSuperfishUl().siblings().hideSuperfishUl();
			},
			out = function(){
				var $$ = $(this), menu = getMenu($$), o = sf.op;
				clearTimeout(menu.sfTimer);
				menu.sfTimer=setTimeout(function(){
					o.retainPath=($.inArray($$[0],o.$path)>-1);
					$$.hideSuperfishUl();
					if (o.$path.length && $$.parents(['li.',o.hoverClass].join('')).length<1){over.call(o.$path);}
				},o.delay);
			},
			getMenu = function($menu){
				var menu = $menu.parents(['ul.',c.menuClass,':first'].join(''))[0];
				sf.op = sf.o[menu.serial];
				return menu;
			},
			addArrow = function($a){ $a.addClass(c.anchorClass).append($arrow.clone()); };

		return this.each(function() {
			var s = this.serial = sf.o.length;
			var o = $.extend({},sf.defaults,op);
			o.$path = $('li.'+o.pathClass,this).slice(0,o.pathLevels).each(function(){
				$(this).addClass([o.hoverClass,c.bcClass].join(' '))
					.filter('li:has(ul)').removeClass(o.pathClass);
			});
			sf.o[s] = sf.op = o;

			$('li:has(ul)',this)[($.fn.hoverIntent && !o.disableHI) ? 'hoverIntent' : 'hover'](over,out).each(function() {
				if (o.autoArrows) addArrow( $('>a:first-child',this) );
			})
			.not('.'+c.bcClass)
				.hideSuperfishUl();

			var $a = $('a',this);
			$a.each(function(i){
				var $li = $a.eq(i).parents('li');
				$a.eq(i).focus(function(){over.call($li);}).blur(function(){out.call($li);});
			});
			o.onInit.call(this);

		}).each(function() {
			var menuClasses = [c.menuClass];
			if (sf.op.dropShadows  && !($.browser.msie && $.browser.version < 7)) menuClasses.push(c.shadowClass);
			$(this).addClass(menuClasses.join(' '));
		});
	};

	var sf = $.fn.superfish;
	sf.o = [];
	sf.op = {};
	sf.IE7fix = function(){
		var o = sf.op;
		if ($.browser.msie && $.browser.version > 6 && o.dropShadows && o.animation.opacity!=undefined)
			this.toggleClass(sf.c.shadowClass+'-off');
		};
	sf.c = {
		bcClass     : 'sf-breadcrumb',
		menuClass   : 'sf-js-enabled',
		anchorClass : 'sf-with-ul',
		arrowClass  : 'sf-sub-indicator',
		shadowClass : 'sf-shadow'
	};
	sf.defaults = {
		hoverClass	: 'sfHover',
		pathClass	: 'overideThisToUse',
		pathLevels	: 1,
		delay		: 800,
		animation	: {opacity:'show'},
		speed		: 'normal',
		autoArrows	: true,
		dropShadows : true,
		disableHI	: false,		// true disables hoverIntent detection
		onInit		: function(){}, // callback functions
		onBeforeShow: function(){},
		onShow		: function(){},
		onHide		: function(){}
	};
	$.fn.extend({
		hideSuperfishUl : function(){
			var o = sf.op,
				not = (o.retainPath===true) ? o.$path : '';
			o.retainPath = false;
			var $ul = $(['li.',o.hoverClass].join(''),this).add(this).not(not).removeClass(o.hoverClass)
					.find('>ul').hide().css('visibility','hidden');
			o.onHide.call($ul);
			return this;
		},
		showSuperfishUl : function(){
			var o = sf.op,
				sh = sf.c.shadowClass+'-off',
				$ul = this.addClass(o.hoverClass)
					.find('>ul:hidden').css('visibility','visible');
			sf.IE7fix.call($ul);
			o.onBeforeShow.call($ul);
			$ul.animate(o.animation,o.speed,function(){ sf.IE7fix.call($ul); o.onShow.call($ul); });
			return this;
		}
	});

})(jQuery);

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 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;
}

//Cross Promo
var d=document; var w=window;var docHg;
var range=400;
var cod_arr=new Array();
var arrLen = 0;
var modSpan = 6;
var currId = 0;
var opt = {
	ae:function(o,et,fn){if(o.addEventListener)o.addEventListener(et,fn,false);else if(o.attachEvent)o.attachEvent("on"+et,fn);},
	gt:function(t,o){o=o?o:document;return o.getElementsByTagName(t)},
	gc:function(c,t,s,o){var r=new Array();var os=opt.gt(t,o);for(var i=0,j=0,l=os.length;i<l;i++){var sc = s + os[i].className + s;if(sc.indexOf(s+c+s)!=-1){r[j] = os[i];j++;}}return r;},
        nview:function(obj,i) {
                if (obj.loaded==null) {
                    obj.loaded=0;
                }
                if (obj.loaded==0) {
                    var relTop=obj.offsetTop-(w.scrollY||d.documentElement.scrollTop);
                    if((relTop-docHg-20)<range) {
                      var codUrl=opt.gt('a',obj)[0].href;
                      opt.xhr(codUrl,obj,i);
                    }
                }
        },
        doCod:function(){
                var l=cod_arr.length;
                for (var i=0;i<l;i++) {
                        opt.nview(cod_arr[i],i);
                }
        },
        xhr:function(u,obj,i){
                obj.loaded=1;
                var f,r,m='GET';
                f=function(){if(r.readyState>3)opt.update(obj,r,i);}
                r= window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
                r.onreadystatechange=f;
                r.open(m,u,1);
                r.setRequestHeader('content-type','text/xml');
                r.send('');
        },
        update:function(obj,r,i) {
                if(r.status==200){
                        obj.innerHTML=r.responseText;
                } else {obj.loaded=0;}
        },
        init:function() {
                        cod_arr=opt.gc('cod','div','',document);
                        docHg=w.innerHeight||d.documentElement.offsetHeight;
                        opt.doCod();
                        opt.ae(window,'scroll',opt.doCod);
        },
        res:function(){
                docHg=w.innerHeight||d.documentElement.offsetHeight;
                opt.doCod();
        }

}
opt.ae(window,'resize',opt.res);
opt.ae(window,'load',opt.init);

function countCartridges() {
   var cartCount = 0;
   end = false;
   do {
      if(document.getElementById('cart'+cartCount)) {
         cartCount++;
      } else {
         end = true;
      }
   } while (end == false)
   arrLen = cartCount;
}

function showCartridges( startId ) {
  if(arrLen == 0) {
    countCartridges();
  }
  var i,j;
  for (i=0,j=startId; i < modSpan; i++,j++) {
     var strCart = j%arrLen;
     document.getElementById('cartridge'+i).innerHTML = document.getElementById('cart'+strCart).innerHTML;
  }
}

function isModFetched (modId) {
  if(document.getElementById('cart'+modId).innerHTML.length>0) {
      return true;
  } else {
      return false;
  }
}

function nextCartridge () {
  if(arrLen == 0) {
     countCartridges();
  }
  currId = currId + 1;
  if ( !isModFetched( (currId+modSpan)%arrLen ) ) {
      fetchModule((currId+modSpan)%arrLen);
  }
  showCartridges(currId);
}

function prevCartridge () {
  if(arrLen == 0) {
    countCartridges();
  }
  if(currId!=0) {
      currId = currId - 1
  } else {
      currId=arrLen-1;
  }

  if ( !isModFetched( (currId+modSpan)%arrLen ) ) {
      fetchModule((currId+modSpan)%arrLen);
  }
  showCartridges(currId);
}
// Crosspromo end

// Cards on table
var cott = {
    timeout: 3750,
    maxLink: 0,
    init: function() {
        var topLink = document.getElementById("toplink");
        var links = topLink.getElementsByTagName("A");
        cott.maxLink = links.length;
        if (links.length == 0) { return; }
        for(var i=0;i<links.length;i++) {
            links[i].style.backgroundColor = '#fff';
            links[i].style.zoom = 1;
            if (i>0) { links[i].style.display = 'none'; }
        }
        setTimeout("cott.rotateLink(2)", cott.timeout);
    },
    fadeTo: function(obj, lvl) {
        obj.style.filter = 'alpha(opacity=' + lvl*10 + ')';
        obj.style.opacity = lvl/10;
    },
    rotateLink: function (linkNo) {
        cott.displayNextLink(linkNo);
        var nextLink = linkNo + 1;
        if (nextLink > cott.maxLink) {
            nextLink = 1;
        }
        var t = setTimeout("cott.rotateLink(" + nextLink + ")", cott.timeout);
    },
    displayNextLink: function(linkNo) {
        var lastLink = linkNo-1;
        if (lastLink == 0) {
            lastLink = cott.maxLink;
        }
        cott.fade("cottLink"+lastLink, "cottLink"+linkNo, -9.9);
    },
    fade: function(from, to, stage) {
        if (!document.getElementById(from)) { return; }
        fobj = document.getElementById(from);
        if (!document.getElementById(to)) { return; }
        tobj = document.getElementById(to);
        if (stage < 0) {
            cott.fadeTo(fobj, Math.abs(stage));
        } else if (stage == 10) {
            cott.fadeTo(tobj, 9.9);
        } else if (stage == 0) {
            fobj.style.display = 'none';
            cott.fadeTo(tobj, 1);
            tobj.style.display = 'inline';
        } else {
            cott.fadeTo(tobj, stage);
        }
        if (stage != 10) {
            var b = setTimeout("cott.fade('" + from + "', '" + to + "', " + parseInt(stage+1) + ")", 40);
        }
    }
};

function buildCottImg(num) {
   var cPar = document.getElementById('card_' + num);
   var cImg = document.getElementById('image_' + num);
   var cPhoto = document.getElementById('photo_' + num);

   var newImg = new Image();

   if(navigator.userAgent.indexOf('MSIE') != -1) {
        newImg.setAttribute('src', cImg.href);
        newImg.setAttribute('alt', cImg.firstChild.nodeValue);
        cottDelay(100);
   } else {
     try
     {
         newImg.setAttribute('src', cImg);
         newImg.setAttribute('alt', cImg.innerHTML);
         cPhoto.appendChild(newImg);
     }
     catch (e)
     {
         //create html string for new input element
         var sHTML = "<a href=\"" + cPhoto + "\" target=\"_blank\"><img alt=\"" + cImg.innerHTML + "\" src=\"" + cImg + "\"></a>";
          cPhoto.innerHTML = sHTML;
     }
  }

   if (cPhoto != null) {
        try
        {
            cPhoto.appendChild(newImg);
        }
        catch (e){}
        cPhoto.removeAttribute("id");
        cImg.parentNode.removeChild(cImg);
   } else {
        try
        {
        newImg.parentNode.replaceChild(newImg,cImg);
        }
        catch (e){}
   }
     return false;
}

function cottDelay(millis) {
    var date = new Date();
    var curDate = null;
    do { curDate = new Date(); }
    while(curDate-date < millis);
}

function displayCottMods(firstMod) {

  modInst = modInst + firstMod;
  if(modInst == -1) {
      modInst = maxCards - 1;
  }

  for (var m=0; m<3; m++) {
     var inst = (modInst + m)%(maxCards);
     var topcard='showcard'+ m;
     var hiddenCardId = "card_" + inst;
     var parentDiv = document.createElement("div");
     var hiddenCard = document.createElement("div");

     if(document.getElementById('image_'+inst)) {
         buildCottImg(inst);

         if(navigator.userAgent.indexOf('MSIE') != -1) {
             cottDelay(200);
         }
     }

     hiddenCard.id = "slot_" + inst;
     hiddenCard.className = "card";
     hiddenCard.innerHTML = (document.getElementById(hiddenCardId).innerHTML);
     parentDiv.appendChild(hiddenCard);
     document.getElementById(topcard).innerHTML = parentDiv.innerHTML;
  }
    return false;
}

function cottInit() {

   displayCottMods(0);
   document.getElementById('topHiddenModules').className="hideCards";
   document.getElementById('arrows').className="show_arws";
   document.getElementById('showcard0').className="showCards";
   document.getElementById('showcard1').className="showCards";
   document.getElementById('showcard2').className="showCards";
}

// Shared functions

function findMousePos(e) {
	var posY = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posY = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posY = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	return posY;
}



//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();}
}

var is_flash = false; var flashVer = 7;
if (window.ActiveXObject && !is_mac) {document.write('<scr' + 'ipt language="VBScript">' + '\n' + 'On Error Resume Next' + '\n' + 'is_Flash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & flashVer)))' + '\n' + '<\/sc' + 'ript>'); }
else {var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0; var pluginStr = plugin.description; if (plugin){ if (parseInt(pluginStr.substring(pluginStr.indexOf(".")-1)) >= flashVer) { is_flash = true; }}}

// 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};
}

// BEGIN Functions for ActiveX patch to IE/IE7 ------------------//
function FlashTag(src, width, height, version) {
    if (arguments.length < 4)
    {
        throw new Exception('RequiredAttributeException',
                            'You must pass in a src, width, height, and version when creating a FlashTag.');
    }

    for (var i = 0; i < arguments.length; ++i)
    {
        if (arguments[i] == undefined || arguments[i] == null)
        {
            throw new Exception('RequiredAttributeException',
                                'All constructor arguments must have values.');
        }
    }

    // Required
    this.src            =  src;
    this.width          =  width;
    this.height         =  height;
    this.version        =  version;

    this.id             =  null;
    this.flashVars      =  null;
    this.flashVarsStr   =  null;
    this.genericParam   = new Object();
    this.ie = (navigator.appName.indexOf ("Microsoft") != -1) ? 1 : 0;
}
FlashTag.prototype.setSource = function(src) {
    this.src = src;
}
FlashTag.prototype.setWidth = function(w) {
    this.width = width;
}
FlashTag.prototype.setHeight = function(h) {
    this.h = height;
}
FlashTag.prototype.setVersion = function(v) {
    this.version = v;
}
FlashTag.prototype.setId = function(id) {
    this.id = id;
}
FlashTag.prototype.setBgcolor = function(bgc) {
    if (bgc.charAt(0) != '#') bgc = '#' + bgc;
    this.genericParam['bgcolor'] = bgc;
}
FlashTag.prototype.addFlashVars = function(fvs) {
    this.flashVarsStr = fvs;
}
FlashTag.prototype.addFlashVar = function(n, v) {
    if (this.flashVars == null) this.flashVars = new Object();
    this.flashVars[n] = v;
}
FlashTag.prototype.removeFlashVar = function(n) {
    if (this.flashVars != null) this.flashVars[n] = undefined;
}
FlashTag.prototype.setSwliveconnect = function(swlc) {
    this.genericParam['swliveconnect'] = swlc;
}
FlashTag.prototype.setPlay = function(p) {
    this.genericParam['play'] = p;
}
FlashTag.prototype.setLoop = function(l) {
    this.genericParam['loop'] = l;
}
FlashTag.prototype.setMenu = function(m) {
    this.genericParam['menu'] = m;
}
FlashTag.prototype.setQuality = function(q) {
    if (q != 'low' && q != 'high' && q != 'autolow' && q != 'autohigh' && q != 'best')
    {
        throw new Exception('UnsupportedValueException',
                            'Supported values are "low", "high", "autolow", "autohigh", and "best".');
    }
    this.genericParam['quality'] = q;
}
FlashTag.prototype.setScale = function(sc) {
    if (sc != 'showall' && sc != 'noborder' && sc != 'exactfit' && sc != 'noscale')
    {
        throw new Exception('UnsupportedValueException',
                            'Supported values are "showall", "noborder", "exactfit, and "noscale".');
    }
    this.genericParam['scale'] = sc;
}
FlashTag.prototype.setAlign= function(a) {
    if (a != 'l' && a != 't' && a != 'r' && a != 'b')
    {
        throw new Exception('UnsupportedValueException',
                            'Supported values are "l", "t", "r" and "b".');
    }
    this.genericParam['align'] = a;
}
FlashTag.prototype.setSalign= function(sa) {
    if (sa != 'l' && sa != 't' && sa != 'r' && sa != 'b' && sa != 'tl' && sa != 'tr' && sa != 'bl' && sa != 'br')
    {
        throw new Exception('UnsupportedValueException',
                            'Supported values are "l", "t", "r", "b", "tl", "tr", "bl" and "br".');
    }
    this.genericParam['salign'] = sa;
}
FlashTag.prototype.setWmode = function(wm) {
    if (wm != 'window' && wm != 'opaque' && wm != 'transparent')
    {
        throw new Exception('UnsupportedValueException',
                            'Supported values are "window", "opaque", and "transparent".');
    }
    this.genericParam['wmode'] = wm;
}
FlashTag.prototype.setBase = function(base) {
    this.genericParam['base'] = base;
}
FlashTag.prototype.toString = function() {
    var flashTag = new String();
    if (this.ie)
    {
        flashTag += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
        if (this.id != null)
        {
            flashTag += 'id="'+this.id+'" ';
        }
        flashTag += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+this.version+'" ';
        flashTag += 'width="'+this.width+'" ';
        flashTag += 'height="'+this.height+'">';
        flashTag += '<param name="movie" value="'+this.src+'"/>';

        for (var n in this.genericParam)
        {
            if (this.genericParam[n] != undefined && this.genericParam[n] != null)
            {
                flashTag += '<param name="'+n+'" value="'+this.genericParam[n]+'"/>';
            }
        }

        if (this.flashVars != null)
        {
            var fv = this.getFlashVarsAsString();
            if (fv.length > 0)
            {
                flashTag += '<param name="flashvars" value="'+fv+'"/>';
            }
        }
        flashTag += '</object>';
    }
    else
    {
        flashTag += '<embed src="'+this.src+'"';
        flashTag += ' width="'+this.width+'"';
        flashTag += ' height="'+this.height+'"';
        flashTag += ' type="application/x-shockwave-flash"';
        if (this.id != null)
        {
            flashTag += ' name="'+this.id+'"';
        }

        for (var n in this.genericParam)
        {
            if (this.genericParam[n] != undefined && this.genericParam[n] != null)
            {
                flashTag += (' '+n+'="'+this.genericParam[n]+'"');
            }
        }
        if (this.flashVars != null || this.flashVarsStr != null)
        {
            var fv = this.getFlashVarsAsString();
            if (fv.length > 0)
            {
                flashTag += ' flashvars="'+fv+'"';
            }
        }
        flashTag += ' pluginspage="http://www.macromedia.com/go/getflashplayer">';
        flashTag += '</embed>';
    }
    return flashTag;
}
FlashTag.prototype.write = function(doc) {
    doc.write(this.toString());
}
FlashTag.prototype.getFlashVarsAsString = function() {
    var qs = new String();
    for (var n in this.flashVars)
    {
        if (this.flashVars[n] != undefined && this.flashVars[n] != null)
        {
            qs += (escape(n)+'='+escape(this.flashVars[n])+'&');
        }
    }

    if (this.flashVarsStr != null) return qs + this.flashVarsStr;

    return qs.substring(0, qs.length-1);
}
FlashTag.prototype.setParams = function( id, bgc, fvs, swlc, p, l, m, q, sc, a, wm, base ) {
    if (id != null) this.id             =  id;
    if (fvs != null) this.flashVarsStr   =  fvs;

    if (bgc != null) this.setBgcolor(bgc);
    if (swlc != null) this.setSwliveconnect(swlc);
    if (p != null) this.setPlay(p);
    if (l != null) this.setLoop(l);
    if (m != null) this.setMenu(m);
    if (q != null) this.setQuality(q);
    if (sc != null) this.setScale(sc);
    if (a != null) this.setAlign(a);
    if (wm != null) this.setWmode(wm);
    if (base != null) this.setBase(base);
}
function writeOnLoad() {
         try {
                 if ( flashTagParams != undefined ) {
                         var tag =  new FlashTag(flashTagParams.src, flashTagParams.width, flashTagParams.height, flashTagParams.version );
                         document.write(tag.toString());
                 }
         } catch(ex) {
                // Do nothing
         }
}
writeOnLoad();
// END Functions for ActiveX patch to IE/IE7 ------------------//



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);
       }
    }
}


/* New JS for Too Fab */

/* Plugins & Libraries
**************************/

/* [PNS]
* This plugin has been modified to allow you to override the behavior by applying class="superaint" to an element.
* Please consider that before upgrading this plugin
*/

jQuery.fn.supersleight = function(settings) {
	settings = jQuery.extend({
		imgs: true,
		backgrounds: true,
		shim: 'x.gif',
		apply_positioning: true
	}, settings);

	return this.each(function(){
		if (jQuery.browser.msie && parseInt(jQuery.browser.version, 10) < 7 && parseInt(jQuery.browser.version, 10) > 4) {
			jQuery(this).find('*').andSelf().each(function(i,obj) {
				if(jQuery(this).is('.superaint')) return; /* [PNS] Don't sleight that which super aint */
				var self = jQuery(obj);
				// background pngs
				if (settings.backgrounds && self.css('background-image').match(/\.png/i) !== null) {
					var bg = self.css('background-image');
					var src = bg.substring(5,bg.length-2);
					var mode = (self.css('background-repeat') == 'no-repeat' ? 'crop' : 'scale');
					var styles = {
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='" + mode + "')",
						'background-image': 'url('+settings.shim+')'
					};
					self.css(styles);
				};
				// image elements
				if (settings.imgs && self.is('img[src$=png]')){
					var styles = {
						'width': self.width() + 'px',
						'height': self.height() + 'px',
						'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + self.attr('src') + "', sizingMethod='scale')"
					};
					self.css(styles).attr('src', settings.shim);
				};
				// apply position to 'active' elements
				if (settings.apply_positioning && self.is('a, input') && (self.css('position') === '' || self.css('position') == 'static')){
					self.css('position', 'relative');
				};
			});
		};
	});
};

/* Application Code
**************************/

$(document).ready(function() {

  /* PNG transparency for IE6 */
  $('#page-wrap, #header, .navigation, #footer').supersleight({shim: document.shimUrl });

  /* search */
  $('.query').focus(function() {
    $(this).parent().parent().addClass("focused").supersleight({shim: document.shimUrl });
  });
  $('.query').blur(function() {
    if($.trim($(this).val())=='') {
      $(this).parent().parent().removeClass("focused");
    }
  });

  $('.search-wrapper li a').click(function(evt) {
    evt.preventDefault();
    $(this).parent().parent().parent().find('form').attr('action', $(this).attr('href'));
    $(this).parent().parent().find('.searchCatBg').removeClass('searchCatBg');
    $(this).parent().addClass('searchCatBg');
  });

  $('.query-wrapper form').submit(function(evt) {
    evt.preventDefault();
    submitSearchForm($(this)[0]);
  });

  $('.srchLnk').click(function(evt) {
    evt.preventDefault();
    submitSearchForm($(this).parent().parent()[0]);
  });

  function submitSearchForm(form) {
    var queryval = $(form).find('input').val().trim().replace(/\+/, " ");
    var newurl = form.action + queryval;
    if(form.target == '_blank') {
      window.open(newurl, '_blank', '');
    } else {
      window.location = newurl;
    }
  }

  $('.search-wrapper li a:first').click();

  $('.query').each(function() {
    if(!$.trim($(this).val())=='') $(this).parent().parent().addClass("focused").supersleight({shim: document.shimUrl });
  });

  /* dropdown */
  $('ul.sf-menu').superfish({
	pathClass : 'current',
    	animation : {opacity:'show'},
        autoArrows: false,
    	delay : 1000
  });
});