var FODval="hellskitchen";
////////////// Imported from old Hell's Kitchen site for Features page //////
    function openVid(id){
	openWin(id,'foxVideoPlayer','656','680');
    }

    function openWin(theURL, theName, theWidth, theHeight, theBars)
    {
       var width=theWidth;
       var height=theHeight;
       var theName=theName;
       var bars=theBars;
       var winl = (screen.width - width) / 3;
       var wint = (screen.height - height) / 2;
       var theFeatures = "width=" + width + ",height=" + height +",top="+wint+",left="+winl+",scrollbars="+bars;

       var theWin = window.open(theURL,theName,theFeatures);
       theWin.focus();
    }


//a closure so it couldn't conflict with anything
(function() {

//////////////// Added by Alayta ///////////////////////
    window.changeSeasons = function(dd) {
        var ind = dd.selectedIndex;
        var season = dd.options[ind].value
        var episodeDiv = document.getElementById('episodenav');
        var els = episodeDiv.getElementsByTagName('select');
        for (var i=0; i<els.length; i++) {
            var elId = els[i].id;
            if (elId==season) {
                els[i].className = '';
            }
            else {
                els[i].className = 'hide';
            }
        }
    }

	//addEvent from here: http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
	function addEvent(obj, type, fn) {
		if (obj.addEventListener) {
			obj.addEventListener(type, fn, false);
		} else if (obj.attachEvent) {
			obj["e"+type+fn] = fn;
			obj[type+fn] = function() { obj["e"+type+fn](window.event); }
			obj.attachEvent("on"+type, obj[type+fn]);
		}
	}
	
	function getElementsByClassName(node, classname) {
	    var a = [];
	    var re = new RegExp('(^| )'+classname+'( |$)');
	    var els = node.getElementsByTagName("*");
	    for(var i=0,j=els.length; i<j; i++)
	        if(re.test(els[i].className))a.push(els[i]);
	    return a;
	}
	
	addEvent(window, 'load', function () {

		var thumbnailList = document.getElementById('cast-thumbnails');		
		if (thumbnailList) { //if there is a thumbnail list on the page
			var thumbnailLinks = thumbnailList.getElementsByTagName('a');
			var lastProfile;
			
			for (var i=0; i<thumbnailLinks.length; i++) {			
				(function() {
					var a = thumbnailLinks[i];

					// Change profile on click
					var profile = document.getElementById(a.href.split("#")[1]);
					if (profile) { //if it links to a div
						if (i === 0) {
							profile.style.display = 'block';
							lastProfile = profile;
						}
						a.onclick = function () {
							lastProfile.style.display = 'none';
							profile.style.display = 'block';
							lastProfile = profile;
							return false;
						}
					}

					// Attaching hover effect
					// Hover images should be named exacly as default ones except that they should
					// end with "_hover.jpg" and not ".jpg" (as default images do).
					var img = a.getElementsByTagName("img")[0];
					var hoverImgSrc = img.src.replace(".jpg", "_hover.jpg");
					
					a.onmouseover = function () { img.src = hoverImgSrc; }
					a.onmouseout = function () { img.src = img.src.replace("_hover", ""); }
					
					new Image().src = hoverImgSrc; //preload
				})();
			}
		}
		
		//just reuse the gallery markup and it will work on any page
		var gallery = document.getElementById('photo-gallery');
		if (gallery) { //if there is a gallery on the page
			var links = gallery.getElementsByTagName('ul')[0].getElementsByTagName('a');
			
			var previewContainer = getElementsByClassName(gallery, 'preview')[0];
			var previewImg = document.createElement('img');
			var previewDesc = document.createElement('p');

			previewContainer.appendChild(previewImg);
			previewContainer.appendChild(previewDesc);
			
			var scrollUpLink = getElementsByClassName(gallery, 'scroll-top')[0];
			var scrollDownLink = getElementsByClassName(gallery, 'scroll-down')[0];			
			
			for (var i=5; i<links.length; i++) { 
				links[i].parentNode.style.display = "none";
			}
			
			var currentOffset = 0;
			
			function refreshThumbnailView() {
				function disable(el) {
					if (window.ActiveXObject) {
						el.style.zoom = 1;
						el.style.filter = 'alpha(opacity=40)';
					}
					el.style.opacity = '0.4';
				}
				function enable(el) {
					if (window.ActiveXObject) {
						el.style.zoom = 1;
						el.style.filter = '';
					}
					el.style.opacity = '';
				}
			
				for (var i=0; i<links.length; i++) {
					links[i].parentNode.style.display = 
						((i >= currentOffset) && (i < currentOffset+5)? 'block' : 'none')
				}
				if (links.length - currentOffset <= 5) disable(scrollDownLink);
				else enable(scrollDownLink);
				
				if (currentOffset == 0) disable(scrollUpLink);
				else enable(scrollUpLink);
			}
			
			scrollUpLink.onclick = function() {
				if (currentOffset > 0) currentOffset -= 5;
				refreshThumbnailView();
				return false;
			}
			scrollDownLink.onclick = function() {
				if (links.length - currentOffset > 5) currentOffset += 5;
				refreshThumbnailView();
				return false;
			}
			
			var lastLink;
			function selectImg(link) {
				var img = link.getElementsByTagName('img')[0];
				previewImg.src = img.src.replace('thumb', 'img')
				previewDesc.innerHTML = img.alt
				if (lastLink) lastLink.className = "";
				link.className = "current";
				lastLink = link;
			}
			
			var photoNum = 0;
			if (location.href.split('#').length > 1) {
				photoNum = parseInt(location.href.split('#')[1].match(/^photo-(\d+)/)[1]);
			}
			selectImg(links[(photoNum && photoNum <= links.length ? photoNum - 1 : 0)]); //select first
			currentOffset = (photoNum && photoNum <= links.length ? (photoNum-1) - ((photoNum-1)%5) : 0);
			
			refreshThumbnailView();

			for (var i=0; i<links.length; i++) {
				links[i].onclick = function() {
					selectImg(this);
					return false;
				}
			}
		}
	});

	window.goToPage = function(dd) {
		var ind = dd.selectedIndex;
		if (ind == 0) { return; }
		var url = dd.options[ind].value
		window.location=url;
	}
})();

function go(where){
	if(where!="") window.location=where;
}
