﻿try { console.log('init console... done'); } catch (e) { console = { log: function () { } } }


// the "Juicy Fruit" framework (c) Nickelodeon - Scott Miller

//var section = window.location.pathname.split('/')[1];
var section = 'games';
var subsection = '';
if(window.location.pathname.split('/')[3]) subsection = window.location.pathname.split('/')[3].split('.')[0].toLowerCase();

var QSo = "###"; // Query string object
if(window.location.search!="") 
{   
	QSo = new Object;
	QSo = getQueryStringObject(window.location.search);
}

var sizing=false;
var numOfBGs = 2;// number of backgrounds. Names:1,2,3,etc.

var s_account = "";
if (window.location.hostname == "www.nicktoons.co.uk" || window.location.hostname == "nicktoons.co.uk") { s_account = "nickelodeonukprod";

    function alert() { };

}
else {
    s_account = "nickelodeonukdev" 
}

var pagingCreated=false;

$(document).ready(function () {


    $('#nav a').click(function () {
        var l = $(this).attr('id').toString().replace(/hyperlink/gi, '');
        trackFeatured('nicktoons-' + l, s_account, this);
    });

    $('.promo-big').hover(function () {
        Cufon.replace($('#mainTitle', this), {
            color: '#fff',
            textShadow: '1px 1px rgba(0,0,0,0.4)'

        });
    });
    $('.promo-big').mouseout(function () {
        Cufon.replace($('#mainTitle', this), {
            color: '#fff',
            textShadow: '1px 1px rgba(0,0,0,0.4)'
        });
    });

    $('#home-promos .promo').each(
	function () {
	    var imagePath = $(this).children('img').attr('src');
	    $(this).css({ 'background': 'url(' + imagePath + ') no-repeat' });
	    $('img', this).attr('src', '/global/img/promos/mask.png');
	});

    $('#home-promos span').hover(function () {
        Cufon.replace($(this).parent().children('span').children('span'), {
            color: '#231f20'
        });
    });
    $('#home-promos span').mouseout(function () {
        Cufon.replace($(this).parent().children('span').children('span'), {
            color: '#ffffff',
            textShadow: '1px 1px rgba(0,0,0,0.2)'
        });
    });

    $('#games-promos .promo').each(
	function () {
	    var imagePath = $(this).children('img').attr('src');
	    $(this).css({ 'background': 'url(' + imagePath + ') no-repeat' });
	    $('img', this).attr('src', '/global/img/promos/mask.png');
	    Cufon.replace($(this).children('span').children('span'), {
	        color: '#231f20',
	        textShadow: '0px 0px rgba(0,0,0,0)'
	    });


	});

    $('a#make-this-my-homepage').click(function () {
        if ($.browser.msie) {
            document.body.style.behavior = 'url(#default#homepage)';
            document.body.setHomePage(window.location.href);
            return false;
        }
    });

    $('#search label').click(function () {
        if ($(this).siblings('input').val() == '') {
            $(this).fadeOut(250);
            $(this).siblings('input').focus();
        }
    });

    $('#search input,.field input,.field textarea').focus(function () {
        if ($(this).val() == '') $(this).siblings('label').fadeOut(300);
    });

    $('#search input,.field input,.field textarea').blur(function () {
        if ($(this).val() == '') $(this).siblings('label').fadeIn(200);
    });

    $('#button-search').click(function () {
        if ($('#search input').val() != "")
            window.location.href = "http://www.nick.co.uk/search.aspx?search=" + $('#search input').val();
    });

    $('#search input').keypress(function (e) {
        if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
            $('#button-search').click();
            return false;
        } else {
            return true;
        }
    });

    initCarousel();

    $('.whatson-list .row').click(function () {
        var thisRow = $(this);
        if (!thisRow.hasClass('on')) {
            $('.on').removeClass('on').children('.desc').slideUp(500);
            thisRow.addClass('on').children('.desc').slideDown(500)
        } else {
            thisRow.removeClass('on').children('.desc').slideUp(500);
        }
    });

    $('.help-list .question').click(function () {
        if (!$(this).parent().hasClass('on')) {
            $('.on').removeClass('on').children('.desc').slideUp(500);
            $(this).parent().addClass('on').children('.desc').slideDown(500);
        } else {
            $(this).parent().removeClass('on').children('.desc').slideUp(500);
        }
    });

    $('.help-list .row a[href*="#"]').click(function () {
        var anchor = $(this).attr('href').replace('#', '');
        anchor--;
        $('.help-list span.on').children('.desc').slideUp(500, function () {
            $('.help-list span.on').removeClass('on');
            $('.help-list .row:eq(' + anchor + ')').addClass('on').children('.desc').slideDown(500);
        });
        return false;
    });

    $('.field input[value!=""],.field textarea[value!=""]').siblings('label').hide();

    // external links - add rel="ext" to open in new window
    $('a[rel="external"],a[rel="ext"]').attr('title', function () { return this.title + ' (opens in a new window)' }).click(function () {
        window.open(this.href);
        return false;
    });
});


function goPagingPage(thisPagingPage)
{
	var newTop = (thisPagingPage * 38)-38;
	$('#pages').css({ top:-(newTop)+'px' });
	pagingPage=thisPagingPage;
}

function goPage(thisPage, show, showPageSet)
{   
	var isShowSite = false;
	if(section == "clips") var list = "#list-clips";
	else if(section == "games") var list = "#list-games";
	else if(section == "shows")
	{   
		isShowSite=true;
		if(subsection=="clips") var list = "#list-clips";
		else if(subsection=="games") var list = "#list-games";
		else if(subsection=="blog") var list = '#blog-list';
	}
	else if(section=="blog") var list = '#blog-list';
	else if(section=="search.aspx") 
	{
		var list = "#list-results";
	}
	
	$('#pages a.on').removeClass('on');
	page = Number(thisPage);
	var newTop = ((page-1) * pageHeight);
	if (!show) {
		$(list).css({ top:-(newTop)+'px' });
	}
	else {
		$(showlist).css({ top:-(newTop)+'px' });
	}        
	$('#pages #page'+page).addClass('on'); 
	
	// - new paging count
	if(!pagingCreated) {
		var pagingCurr = $('<div id="paging-curr"><span>Page <span id="paging-current">1</span> of <span id="paging-total">1</span></span></div>');
		$('#button-next').after(pagingCurr);
		pagingCreated=true;
	}
	$('#paging-current').html(page);
	$('#paging-total').html(pageCount);
	//
	
	$('#button-next, #button-back').removeClass('disabled');        
	if(page==1) $('#button-back').addClass('disabled');
	if(page==pageCount) $('#button-next').addClass('disabled');
	
	if(page<=pagingPagesPerPage && pagingPage!=1) goPagingPage(1);
	if(page>pagingPagesPerPage && page<=(pagingPagesPerPage*2) && pagingPage!=2) goPagingPage(2);
	if(page>(pagingPagesPerPage*2) && page<=(pagingPagesPerPage*3) && pagingPage!=3) goPagingPage(3);
	if(page>(pagingPagesPerPage*3) && page<=(pagingPagesPerPage*4) && pagingPage!=4) goPagingPage(4);
	if(page>(pagingPagesPerPage*4) && page<=(pagingPagesPerPage*5) && pagingPage!=5) goPagingPage(5);
	if(page>(pagingPagesPerPage*5) && page<=(pagingPagesPerPage*6) && pagingPage!=6) goPagingPage(6);
	if(page>(pagingPagesPerPage*6) && page<=(pagingPagesPerPage*7) && pagingPage!=7) goPagingPage(7);
	if(page>(pagingPagesPerPage*7) && page<=(pagingPagesPerPage*8) && pagingPage!=8) goPagingPage(8);
	if(page>(pagingPagesPerPage*8) && page<=(pagingPagesPerPage*9) && pagingPage!=9) goPagingPage(9);
	if(page>(pagingPagesPerPage*9) && page<=(pagingPagesPerPage*10) && pagingPage!=10) goPagingPage(10);
	
	if(list=="#list-clips" && page!=1) 
	{
		if(!showPageSet) trackFeatured("clips page"+page, s_account, $("#paging-page #page"+page));
		else trackFeatured("clips pagingPage", s_account, $("#paging-page #page"+page));
	}
	else if(list=="#list-games" && page!=1)
	{
		if(!showPageSet) trackFeatured("games page"+page, s_account, $("#paging-page #page"+page));
		else trackFeatured("games pagingPage", s_account, $("#paging-page #page"+page));
	}
}

function showMorePages()
{
	if(page%10==0) page--;
	var newPage=page+10;
	newPage = (Math.floor(newPage / 10)*10)+1;
	goPage(newPage, false, true); 
}
function showLessPages()
{
	goPage((pagingPage-1)*10, false, true); 
}

/**
 * .disableTextSelect - Disable Text Select Plugin
 *
 * Version: 1.1
 * Updated: 2007-11-28
 *
 * Used to stop users from selecting text
 *
 * Copyright (c) 2007 James Dempster (letssurf@gmail.com, http://www.jdempster.com/category/jquery/disabletextselect/)
 *
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 **/
/**
 * Requirements:
 * - jQuery (John Resig, http://www.jquery.com/)
 **/
(function($){if($.browser.mozilla){$.fn.disableTextSelect=function(){return this.each(function(){$(this).css({"MozUserSelect":"none"})})};$.fn.enableTextSelect=function(){return this.each(function(){$(this).css({"MozUserSelect":""})})}}else{if($.browser.msie){$.fn.disableTextSelect=function(){return this.each(function(){$(this).bind("selectstart.disableTextSelect",function(){return false})})};$.fn.enableTextSelect=function(){return this.each(function(){$(this).unbind("selectstart.disableTextSelect")})}}else{$.fn.disableTextSelect=function(){return this.each(function(){$(this).bind("mousedown.disableTextSelect",function(){return false})})};$.fn.enableTextSelect=function(){return this.each(function(){$(this).unbind("mousedown.disableTextSelect")})}}}})(jQuery)


/* play clip function - to reload video player. needs to be here as referenced on shows/clips as well as clips hub
vars:
videoID = umaID
show name
clip title
string to pass to related clips service 
bool - true is for clips played within a show template */
function playClip(videoID, show, title, related, showclips) {
	
	var endSlate = '<div id="end-slate" class="list"><span class="replay"></span><ul></ul></div>';
	$('#clips-title').html(title);
	$('#clips-show').html(show);
	$('#clips #tabs').css({'top':'468px'});
	$('#clips #breadcrumb').css({'top':'515px'});
	$('#clips #paging').css({'top':'926px'});
	//sponsorship logo:
	$('#logo-overlay').addClass('playing');
	//$('#clips').height(949); - before new paging
	//$('#clips').height(860);
	if(showclips) $('body').scrollTo(470, 500);
	else $('body').scrollTo(320, 500);
	$('#videoplayer').html('').removeClass('loaded');
	var videoPlayer = '<object id="embeddedPlayer" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="100%" height="100%" ><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><param name="flashVars" value="autoPlay=true&'
	videoPlayer += dartKeyValues
	videoPlayer += '" /><param name="wmode" value="transparent" /><param name="movie" value="http://media.mtvnservices.com/mgid:uma:video:nick.co.uk:'
	videoPlayer += videoID;
	videoPlayer += '"  /><embed src="http://media.mtvnservices.com/mgid:uma:video:nick.co.uk:'
	videoPlayer += videoID;
	videoPlayer += '" id="embeddedPlayer" name="embeddedPlayer" flashVars="autoPlay=true&'
	videoPlayer += dartKeyValues
	videoPlayer += '" width="100%" height="100%" bgcolor="#000000" wMode="transparent" type="application/x-shockwave-flash" allowFullScreen="true" allowScriptAccess="always" /></object>'
	$('#videoplayer').html('').append(videoPlayer + endSlate);
	bindRelated(show, showclips);
}



function bindRelated(show, showclips, endslate) {
	show = show.replace("&amp;", "&").replace("'", "&#39;");
	show = jQuery.trim(show);
	$.ajax(
	{
		type: "POST",
		url: "/services/relatedcontent.asmx/RelatedClips",
		beforeSend: function (xhr) {
			xhr.setRequestHeader("Content-type", "application/json; charset=utf-8");
		},
		data: "{'show':'" + show + "','genre':'all'}",
		contentType: "application/json; charset=utf-8",
		dataType: "json",
		success: function (json) {
			var clipData = json.d;
			var relatedCount = 1;
			if ($('.InSkinContentContainer').width() > 555) {
				relatedCount = 2;
				$('#end-slate').addClass('inSkinDisabled');
			}
			else {
				$('#end-slate').removeClass('inSkinDisabled');
			
			}
			if (clipData.length > 0) {
				if (!endslate) {
					$('#list-related-clips').html('<ul></ul>');
					$('#related-clips').show();
				} else {
					$('#end-slate').show().html('<span class="relatedReplay"></span><ul></ul>');
				}
				for (var i = 0; i <= relatedCount; i++) {
					var thisClip = clipData[i];
					var elm = '<li><a title="Watch ' + thisClip.Show + ' - ' + thisClip.Description + '" rel="' + thisClip.Umaid + '">';
					elm += '<span class="list-img">';
					if (thisClip.Thumb == "") thisClip.Thumb = "/global/img/thumb.gif";
					elm += '<img src="' + thisClip.Thumb + '" alt="' + thisClip.Description + '" />';
					elm += '<span class="clip-hover"></span>';
					elm += '</span>';
					if (showclips) elm += '<span class="list-show" rel="' + thisClip.ShowUrl + '">' + thisClip.Show + '</span>';
					else elm += '<span class="list-show">' + thisClip.Show + '</span>';
					elm += '<span class="list-title">' + thisClip.Description + '</span>';
					elm += '<span class="playing"></span>';
					elm += '</a></li>';
					if (!endslate) $('#list-related-clips ul').append(elm);
					else $('#end-slate ul').append(elm);
				}
				if (!endslate) {
					if (showclips) {
						$('#list-related-clips a').unbind().click(function () {
							window.location = $(this).children('span.list-show').attr('rel');
							trackFeatured('shows:clips:relatedClip:' + $(this).attr('rel'), s_account, this);
						});
					} else {
						$('#list-related-clips a').unbind().click(function () {
							$('#list-clips a.on,#list-related-clips a.on').removeClass('on');
							playClip($(this).attr('rel'), $(this).children('.list-show').html(), $(this).children('.list-title').html(), true, false);
							trackFeatured('clips:relatedClip:' + $(this).attr('rel'), s_account, this);
						});
					}
				} else {
					$('#end-slate a').unbind().click(function () {
						$('#list-clips a.on,#list-related-clips a.on').removeClass('on');
						$('#end-slate').html('');
						playClip($(this).attr('rel'), $(this).children('.list-show').html(), $(this).children('.list-title').html(), true, false);
						trackFeatured('clips:endslate:' + $(this).attr('rel'), s_account, this);
					});
				}
			}

		},
		error: function () {
			errorHandler('#related-clips');
		}
	});
}

function randomBG()
{
	var folder = "";
	var BGnum = Math.floor(Math.random()*numOfBGs+1); // random num 0-3
	if (takeOverActive == false) {
	    $('#bg-character').css({ 'background-image': 'url(/global/img/bgs/' + BGnum + '.jpg)', 'background-color': '#f4f8f8', 'top': '-5px' });
	    placeBG();
	}
	else {
	    $('#bg-character').css({ 'background-image': 'none', 'background-color': 'transparent', 'top': '-5px' });
	
    }
}
$(window).resize(placeBG);
function placeBG()
{
	if(!sizing){
		sizing=true;
		var winH = $(document).height();
		$('#bg-character').css({'height':winH}); 
		setTimeout(function(){sizing=false}, 1000)
	}
}

function getQueryStringObject(str)
{
	try
	{
		var qs=[];
		var a=str.indexOf("?")>-1?str.split("?")[1].split("&"):str.split("&");
		for(var x=0;x<a.length;x++){var b=a[x].split("=");qs[b[0]]=b[1].split('%20').join(' ');}
		return qs;
	}
	catch(e){}
}

function errorHandler(o)
{
	$(o).hide();
	trackFeatured("ajax-error:"+o, s_account, this);
}


/* func to fire event on dropdown selects:
$('#MyDropDown').selected(function() { });
*/
(function($) {
	$.fn.selected = function(fn) {
		return this.each(function() {
			var clicknum = 0;
			$(this).click(function() {
				clicknum++;
				if (clicknum == 2) {
					clicknum = 0;
					fn();
				}
			});
		});
	}
})(jQuery);


/* EASING */

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend( jQuery.easing,
{
	def: 'easeOutQuad',
	swing: function (x, t, b, c, d) {
		//alert(jQuery.easing.default);
		return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
	},
	easeInQuad: function (x, t, b, c, d) {
		return c*(t/=d)*t + b;
	},
	easeOutQuad: function (x, t, b, c, d) {
		return -c *(t/=d)*(t-2) + b;
	},
	easeInOutQuad: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t + b;
		return -c/2 * ((--t)*(t-2) - 1) + b;
	},
	easeInCubic: function (x, t, b, c, d) {
		return c*(t/=d)*t*t + b;
	},
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	},
	easeInOutCubic: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t + b;
		return c/2*((t-=2)*t*t + 2) + b;
	},
	easeInQuart: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t + b;
	},
	easeOutQuart: function (x, t, b, c, d) {
		return -c * ((t=t/d-1)*t*t*t - 1) + b;
	},
	easeInOutQuart: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
		return -c/2 * ((t-=2)*t*t*t - 2) + b;
	},
	easeInQuint: function (x, t, b, c, d) {
		return c*(t/=d)*t*t*t*t + b;
	},
	easeOutQuint: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	},
	easeInOutQuint: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
		return c/2*((t-=2)*t*t*t*t + 2) + b;
	},
	easeInSine: function (x, t, b, c, d) {
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},
	easeOutSine: function (x, t, b, c, d) {
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	easeInOutSine: function (x, t, b, c, d) {
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
	},
	easeInExpo: function (x, t, b, c, d) {
		return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
	},
	easeOutExpo: function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	},
	easeInOutExpo: function (x, t, b, c, d) {
		if (t==0) return b;
		if (t==d) return b+c;
		if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
		return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
	},
	easeInCirc: function (x, t, b, c, d) {
		return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
	},
	easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	},
	easeInOutCirc: function (x, t, b, c, d) {
		if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
		return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
	},
	easeInElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
	},
	easeOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	},
	easeInOutElastic: function (x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d/2)==2) return b+c;  if (!p) p=d*(.3*1.5);
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
	},
	easeInBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*(t/=d)*t*((s+1)*t - s) + b;
	},
	easeOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	},
	easeInOutBack: function (x, t, b, c, d, s) {
		if (s == undefined) s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
	},
	easeInBounce: function (x, t, b, c, d) {
		return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
	},
	easeOutBounce: function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	},
	easeInOutBounce: function (x, t, b, c, d) {
		if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
		return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
	}
});

/* SCROLL TO */

;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);

/* KWICKS */

(function($){$.fn.kwicks=function(n){var p={isVertical:false,sticky:false,defaultKwick:0,event:'mouseover',spacing:0,duration:500};var o=$.extend(p,n);var q=(o.isVertical?'height':'width');var r=(o.isVertical?'top':'left');return this.each(function(){container=$(this);var k=container.children('li');var l=k.eq(0).css(q).replace(/px/,'');if(!o.max){o.max=(l*k.size())-(o.min*(k.size()-1))}else{o.min=((l*k.size())-o.max)/(k.size()-1)}if(o.isVertical){container.css({width:k.eq(0).css('width'),height:(l*k.size())+(o.spacing*(k.size()-1))+'px'})}else{container.css({width:(l*k.size())+(o.spacing*(k.size()-1))+'px',height:k.eq(0).css('height')})}var m=[];for(i=0;i<k.size();i++){m[i]=[];for(j=1;j<k.size()-1;j++){if(i==j){m[i][j]=o.isVertical?j*o.min+(j*o.spacing):j*o.min+(j*o.spacing)}else{m[i][j]=(j<=i?(j*o.min):(j-1)*o.min+o.max)+(j*o.spacing)}}}k.each(function(i){var h=$(this);if(i===0){h.css(r,'0px')}else if(i==k.size()-1){h.css(o.isVertical?'bottom':'right','0px')}else{if(o.sticky){h.css(r,m[o.defaultKwick][i])}else{h.css(r,(i*l)+(i*o.spacing))}}if(o.sticky){if(o.defaultKwick==i){h.css(q,o.max+'px');h.addClass('active')}else{h.css(q,o.min+'px')}}h.css({margin:0,position:'absolute'});h.bind(o.event,function(){var c=[];var d=[];k.stop().removeClass('active');for(j=0;j<k.size();j++){c[j]=k.eq(j).css(q).replace(/px/,'');d[j]=k.eq(j).css(r).replace(/px/,'')}var e={};e[q]=o.max;var f=o.max-c[i];var g=c[i]/f;h.addClass('active').animate(e,{step:function(a){var b=f!=0?a/f-g:1;k.each(function(j){if(j!=i){k.eq(j).css(q,c[j]-((c[j]-o.min)*b)+'px')}if(j>0&&j<k.size()-1){k.eq(j).css(r,d[j]-((d[j]-m[i][j])*b)+'px')}})},duration:o.duration,easing:o.easing})})});if(!o.sticky){container.bind("mouseleave",function(){var c=[];var d=[];k.removeClass('active').stop();for(i=0;i<k.size();i++){c[i]=k.eq(i).css(q).replace(/px/,'');d[i]=k.eq(i).css(r).replace(/px/,'')}var e={};e[q]=l;var f=l-c[0];k.eq(0).animate(e,{step:function(a){var b=f!=0?(a-c[0])/f:1;for(i=1;i<k.size();i++){k.eq(i).css(q,c[i]-((c[i]-l)*b)+'px');if(i<k.size()-1){k.eq(i).css(r,d[i]-((d[i]-((i*l)+(i*o.spacing)))*b)+'px')}}},duration:o.duration,easing:o.easing})})}})}})(jQuery);

/* MTVI */

mtvn.btg.config.ReportSettings.Omniture.enabled = false;
/*mtvn.btg.config.ReportSettings.Omniture.account ='ignore'; */
mtvn.btg.Controller.init();

//Audience Science Integration. 
//See script block in master.master for initialization of wl9929camp variables
function getASBannerConnect() {
	if (wl10248camp > 0) {
		return 1
	} else {
		return 0;
	}
}
function getASMPUConnect() {
	if (wl10249camp > 0) {
		return 1
	} else {
		return 0;
	}
}
// End
/* CAROUSEL */

function initCarousel() {
	var showsHtml = "";
	var carouselPrev = ('#carouselPrev');
	var carouselNext = ('#carouselNext');
	var charCarousel = $('#characterCarousel');
	charCarousel.wrap('<div id="characterCarouselClip"/>');
	var carouselItem = '';
	for (var i = 0; i < showsArray.length; i++) {
		carouselItem += '<li id="' + i + '"><a href="' + showsArray[i][1] + '" title="' + showsArray[i][0] + '" style="background-position:' + showsArray[i][2] + '">' + showsArray[i][0] + '</a></li>';
	}
	charCarousel.append(carouselItem);
	charCarousel.width(charCarousel.children('li').length * 129);
};

function miniPlayer(uri, sec) {
    var configUrl = "";
    var vidContainer = "videoplayer_small";
    var dartKeyValues = "";
    dartKeyValues += 'player=as3;url=/;page_sec0=' + sec + ';dcove=d;';
    var videoPlayer = '<div id="video_bug"></div><object id="embeddedPlayer" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="100%" height="100%" ><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><param name="flashVars" value="autoPlay=true&'
    videoPlayer += dartKeyValues
    videoPlayer += '" /><param name="wmode" value="transparent" /><param name="movie" value="http://media.mtvnservices.com/'
    videoPlayer += uri
    videoPlayer += '"  /><embed src="http://media.mtvnservices.com/'
    videoPlayer += uri
    videoPlayer += '" id="embeddedPlayer" name="embeddedPlayer" flashVars="autoPlay=true&'
    videoPlayer += dartKeyValues
    videoPlayer += '" width="100%" height="100%" bgcolor="#000000" wMode="transparent" type="application/x-shockwave-flash" allowFullScreen="true" allowScriptAccess="always" /></object>'
    $('#videoplayer_small').html('').append(videoPlayer);

}

function miniPlayerEndslate() {
    $('#videoplayer_small').append('<div id="small-end-slate"><span class="replay"></span></div>');
    $('#small-end-slate span').click(function () {
        var uri = player.getUri();
        player.playUri(uri);
        $('#small-end-slate').remove();
    });
}

function hideEndSlate() {
    $('#end-slate').hide();
}

