function resizeFont(element_id, amount, min, max)
{
    amount = Number(amount);
    var font = document.getElementById(element_id);
    doResize(font, amount, min, max);
}

function resizeFontClass(tag_name, class_name, amount, min, max)
{
    amount = Number(amount);
    var all_tags = document.getElementsByTagName(tag_name);
    for (var i = 0; i < all_tags.length; i++)
    {
        if (all_tags[i].className == class_name)
        {
            var font = all_tags[i];
            doResize(font, amount, min, max);
        }
    }
}

function doResize(font, amount, min, max) {
    var old_size = "12px";
    if (document.defaultView && document.defaultView.getComputedStyle) {
        old_size = parseInt(document.defaultView.getComputedStyle(font, "").getPropertyValue("font-size").replace('px', '').replace('em', '').replace('pt', ''));
    }
    else if (font.currentStyle) {
        old_size = parseInt(font.currentStyle.fontSize.replace('px', '').replace('em', '').replace('pt', ''));
    }
    if (amount == 0 || old_size == 0) {
        return false;
    }
    if (old_size+amount < min) {
        font.style.fontSize = min;
    }
    else if (old_size+amount > max) {
        font.style.fontSize = max;
    }
    else {
        font.style.fontSize = (old_size+amount)+"px";
    }
}

function initSmoothScroll() {
    window.addEvent('domready',function() { new SmoothScroll({ duration:3000 }, window); });
}

function toggleSlideDisappear(objname,obj2name){
    if(document.getElementById(objname).style.display == "none"){
        // div is hidden, so let's slide down
        document.getElementById(obj2name).style.display = "none";
        document.getElementById(objname).style.display = "block";
    }else{
        // div is not hidden, so slide up
        slideup(objname);
    }
}
function toggleSlide2(objname) {
    if (document.getElementById(objname).style.display == "none") {
        document.getElementById(objname).style.display = "block";
        var imagevar = objname + "img";
        changearrow(imagevar, "down-arrow.gif");
    }
    else {
        document.getElementById(objname).style.display = "none";
        var imagevar = objname + "img";
        changearrow(imagevar, "right-arrow.gif");
    }
}

function changearrow(img_name,img_src) {
    document.getElementById(img_name).src=img_src;
}

function toggleSlide3(objname){
  if(document.getElementById(objname).style.display == "none"){
    slidedown(objname);
  }
}

//graybox stuff
function fadeBox(divName, endOpac){
	var grayBox = document.getElementById(divName);
    if(!grayBox) {
        window.gbinterval = clearInterval(window.gbinterval);
        return false;
    }
	var i = parseFloat(grayBox.style.opacity);
	var step = 0.1;
	if(endOpac){
		if(i < endOpac){
			i += step;
			document.getElementById(divName).style.filter = "alpha(opacity=" + i*100 + ")";
			document.getElementById(divName).style.opacity = i;
		}else{
            window.gbinterval = clearInterval(window.gbinterval);
        }
	}else{
		if(i > endOpac){
			i -= step;
			document.getElementById(divName).style.filter = "alpha(opacity=" + (i*100) + ")";
			document.getElementById(divName).style.opacity = i;
		}else {
			window.gbinterval = clearInterval(window.gbinterval);
			showhidediv(divName,2);
		}
	}
}

function showhidediv(divname,type){
	box=document.getElementById(divname);
	box.style.display=(type==1) ? "block":"none";
}

//use this for a greybox fadeout
function smokeScreen(divId,endOpac){
    var topscroll=(document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
    if(endOpac>0){
        // hide scroll bars
        windowscroll=document.getElementsByTagName('html')[0];
        windowscroll.style.overflow="hidden";
        document.documentElement.scrollTop=topscroll;
        //initialize opacity
        box=document.getElementById(divId);
        box.style.opacity=0;
        box.style.filter="alpha(opacity=0)";
        //make div visible
        showhidediv(divId,1);
    }
    else{
        // put back the scrolls
        windowscroll=document.getElementsByTagName('html')[0];
        windowscroll.style.overflow="auto";
        // and for safari and chrome
        document.body.scrollTop += 1;
        document.body.scrollTop -= 1;
        document.documentElement.scrollTop=topscroll;
    }
    // fade in/out
    window.gbinterval=setInterval("fadeBox('"+divId+"',"+endOpac+")",25);
}
function spotLight(highlightId,smokeScreenId,highlightElementHeight,endOpacity){
    if(endOpacity>1) endOpacity = 1;
    else if(endOpacity<0) endOpacity = 0;
    var height = (window.innerHeight) ? window.innerHeight : document.documentElement.clientHeight;
    var eTop = document.getElementById(highlightId).offsetTop;
    var scrollLoc = eTop + (highlightElementHeight - height)/2.0;
    if(scrollLoc<0) scrollLoc = 0;
    smokeScreen(smokeScreenId,endOpacity);
    document.getElementById(smokeScreenId).style.top = scrollLoc+'px';
    document.body.scrollTop = scrollLoc;
    document.documentElement.scrollTop  = scrollLoc;
}
function tabSwap(id){
  var slideshow_e = id;
  selId = Number(id);
  for(s=1;s<=5;s++){
    if(slideshow_e == s){
      document.getElementById(s+10).style.display = "block";
      if(slideshow_e == 5){
        document.getElementById(slideshow_e).className = "nhp_topic_tab nhp_topic_sel nhp_topic_bot";
      }else{
        document.getElementById(slideshow_e).className = "nhp_topic_tab nhp_topic_sel";
      }
    }else{
      document.getElementById(s+10).style.display = "none";
      if(s == 5){
        document.getElementById(s).className = "nhp_topic_tab nhp_topic_bot";
      }else{
        document.getElementById(s).className = "nhp_topic_tab";
      }
    }
  }
}
function slideShow(){
  artSwitch = setInterval("changeInfo()", 7000);
}
function changeInfo(){
  if(slideshow_first){
    slideshow_i=1;
    slideshow_first = false;
  }
  if(selId != 10){
    selId = selId - 1;
    slideshow_i = selId;
    selId = 10;
  }
  for(s=1;s<=5;s++){
    sid = s-1;
    if(s == slideshow_ids[slideshow_i]){
      str = imageId[sid];
      document.getElementById(str).style.display = "block";
      if(s == 5){
        document.getElementById(slideshow_ids[sid]).className = "nhp_topic_tab nhp_topic_sel nhp_topic_bot";
      }else{
        document.getElementById(slideshow_ids[sid]).className = "nhp_topic_tab nhp_topic_sel";
      }
      slideshow_j = slideshow_j + 1;
    }else{
      str = imageId[sid];
      document.getElementById(str).style.display = "none";
      if(s == 5){
        document.getElementById(slideshow_ids[sid]).className = "nhp_topic_tab nhp_topic_bot";
      }else{
        document.getElementById(slideshow_ids[sid]).className = "nhp_topic_tab";
      }
      slideshow_j = slideshow_j + 1;
    }
    if(slideshow_j==5){
      slideshow_j=0;
    }
  }

  slideshow_i = slideshow_i + 1;
  if (slideshow_i > (slideshow_ids.length - 1)) {slideshow_i = 0;}
  if(!intContinue) {clearInterval(artSwitch);}
}
//Burn away header for flash ad on entertainment.  Since this is code that immediately executes, keep it at the bottom of the file.
if (window.location.href.match(/^http:\/\/(?:movies|games|music)\.toptenreviews\.com\//))
{
    window.burn_interval = null;
    window.burn_tries = 0;
    window.replaced_ad_1 = false;
    //Have to put this in two places so this will make sure it doesn't load twice.
    if (typeof window.burn_started == 'undefined')
    {
        window.burn_started = false;
    }
    //This will cause the burn-in ad to load after the page has loaded.
    if (!window.burn_started)
    {
        window.burn_started = true;

        setTimeout(function() { window.burn_interval = setInterval(function(){
            if (window.replaced_ad_1)
            {
                var burn_container = document.createElement('div');
                burn_container.style.width = '1055px';
                burn_container.style.height = '0px';
                burn_container.style.styleFloat = 'left';

                var burn_header = document.createElement('div');
                burn_header.style.position = 'absolute';
                burn_header.style.width = '1014px';
                burn_header.style.height = '178px';
                burn_header.style.marginLeft = '18px';
                burn_header.style.zIndex = '400';
                burn_header.id = 'burn_header_ad';
                burn_header.onmousedown = function(e) { window.location.href = ''; }

                var embed_obj = document.createElement('embed');

                if (typeof embed_obj.setAttribute != 'undefined')
                {
                    embed_obj.setAttribute('src', '');
                    embed_obj.setAttribute('width', '1014');
                    embed_obj.setAttribute('height', '178');
                    embed_obj.setAttribute('wmode', 'transparent');
                }
                else
                {
                    embed_obj.src = '';
                    embed_obj.width = '1014';
                    embed_obj.height = '178';
                    embed_obj.wmode = 'transparent';
                }

                burn_header.appendChild(embed_obj);

                var burn_header_close = document.createElement('div');
                burn_header_close.style.position = 'absolute';
                burn_header_close.style.width = '63px';
                burn_header_close.style.height = '16px';

                burn_header_close.style.marginLeft = '854px';
                burn_header_close.style.marginTop = '154px';
                burn_header_close.style.cursor = 'pointer';
                burn_header_close.style.zIndex = '401';
                burn_header_close.id = 'burn_header_ad_close';
                burn_header_close.onmousedown =  function(e) { if (!e) { e = window.event; } e.cancelBubble = true; if (e.stopPropagation) { e.stopPropagation(); } }
                burn_header_close.onclick = function(e) { this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode); swapad('ad_1', 'ad_swap_1'); }
                burn_header_close.innerHTML = '<img src="spacer.gif" width="63" height="16" />';

                burn_header.insertBefore(burn_header_close, burn_header.firstChild);
                burn_container.appendChild(burn_header);


                var divs = document.getElementsByTagName('div');
                for (var i = 0; i < divs.length; i++)
                {
                    if (divs[i].className && divs[i].className.indexOf('portal_body') != -1)
                    {
                        divs[i].insertBefore(burn_container, divs[i].firstChild);
                        break;
                    }
                }
                clearInterval(window.burn_interval);
            }
            else
            {
                window.burn_tries++;
                if (window.burn_tries >= 20)
                {
                    clearInterval(window.burn_interval);
                }
            }
        }, 1000); }, 5000);

        //Overwrite swap ad with exceptions for ads the burn-in ad will appear over.
        function swapad(to,from) {
            var todiv=document.getElementById(to);
            if (typeof window.replaced_ad_1 != 'undefined' && !window.replaced_ad_1 && to == 'ad_1')
            {
                todiv.style.height = '90px';  //so the page doesn't jump when closed.
                todiv.style.overflow = 'visible';
                var fromdiv = document.createElement('div');
                fromdiv.style.height = '90px';
                todiv.style.overflow = 'visible';
                var image = document.createElement('img');
                image.src = '';
                fromdiv.appendChild(image);
                todiv.innerHTML = '';
                setTimeout(function() {
                    todiv.appendChild(fromdiv);
                }, 0);
                window.replaced_ad_1 = true;
                return;
            }
            else
            {
                var fromdiv=document.getElementById(from);
            }
            todiv.innerHTML='';
            var par=fromdiv.parentNode;
            setTimeout(function() {
                par.removeChild(fromdiv);
                todiv.appendChild(fromdiv);
            },0);
            fromdiv.style.display="block";
        }
    }
}
