var IS_NICK_DEV = window.location.hostname.indexOf('www.nick.com') == -1;
var NICK_DEBUG = IS_NICK_DEV && window && typeof window.console != "undefined";

var lastLayer = null;
var lastSubLayer = null;

var startIndex = 5;
var currentZIndex = startIndex;
var maxZIndex = 20;

function toTop(layerName, subLayerName) {
	if(layerName == 'header' && document.getElementById(layerName) == null) {
		layerName = 'headerUni';
	}
	document.getElementById(layerName).style.zIndex = currentZIndex;

	currentZIndex = (currentZIndex + 1) % maxZIndex;
	if(currentZIndex == 0) currentZIndex += startIndex;

	lastLayer = layerName;
	lastSubLayer = subLayerName;
	
}

function toBottom(layerName, subLayerName){
	if(layerName == 'header' && document.getElementById(layerName) == null) {
		layerName = 'headerUni';
	}

	if(layerName == lastLayer && subLayerName != lastSubLayer) {
		return;
	}

	if(layerName == 'toolbar') {
		document.getElementById(layerName).style.zIndex = 0;
	} else {
		document.getElementById(layerName).style.zIndex = 1;
	}
	lastLayer = null;
	lastSubLayer = null;
}

// 2008-06-27:carrillos
function validateDivIds() {
	//if(window.location.hostname.indexOf('mtvi.com') < 0) return;
	if(!NICK_DEBUG) return;

	var dupes = new Object();

	// NodeList, not an array. Can't join divs and objects
	var divs = document.getElementsByTagName('div');
	for(var i = 0; i < divs.length; i++) {
		if(divs[i].id == null || divs[i].id == "" || divs[i].id == "FLASH_AD") continue;

		if(dupes[divs[i].id] != null) {
			alert("Warning: Duplicate element ID found: ["+divs[i].id+"]");
		}
		dupes[divs[i].id] = divs[i].id;
	}

	var objects = document.getElementsByTagName('object');
	for(var i = 0; i < objects.length; i++) {
		if(objects[i].id == null || objects[i].id == "" || objects[i].id == "FLASH_AD") continue;

		if(dupes[objects[i].id] != null) {
			alert("Warning: Duplicate element ID found: ["+objects[i].id+"]");
		}
		dupes[objects[i].id] = objects[i].id;
	}
}

isEmptyString = function(obj) {
	return obj == null || trim(obj) == "" || obj == "undefined";
}

trim = function(str) {
	return str.replace(/^\s+|\s+$/g, '');
}

/*
	This will override the doLog method coming from: /dynamo/javascript/swfobject/swfobject_utils.js
	We cannot remove the definition from there as it is being used by other sites. nickjr/pc/nan/upick
*/
// 2008-10-14:carrillos
doLog = function() {
	if(!NICK_DEBUG) return; // flag should already verify window && window.console. Fixes an odd bug

	if(typeof window.console.debug != "undefined") {
		// firebug error console
		window.console.debug.apply(window.console, arguments);
	} else if(typeof window.console.log != "undefined") {
		// safari/chrome error console
		window.console.log.apply(window.console, arguments);
	}
}

function createIframe(divId, url, w, h) {
	var iHTML = "<iframe width='"+w+"' height='"+h+"' src='"+url+"' frameborder='0' scrolling='no' allowtransparency='no'></iframe>";
	document.getElementById(divId).style.height = String(h)+"px";
	document.getElementById(divId).style.width = String(w)+"px";
	document.getElementById(divId).innerHTML = iHTML;
		
	if(Number(w) > 700) {
		var adleft = Number(w) + 150;
		moveRightAd(adleft);
	}
}

function moveRightAd(left) {
	if(left != "null" || left != "") {
		document.getElementById("rightAd").style.left = String(left)+"px";
	}
}
