﻿// VIDEO EMBEDS
var domain = (document.domain == "internal.idstudios.net") ? 'http://internal.idstudios.net/natgeotv.com.au/' : "http://"+document.domain+"/";
// Video Player (Embed)
function ChookTV(videoID, w, h, manual) {
	var e = '<div>';
	e += '<object width="' + w + '" height="' + h + '">';
	e += '<param name="allowfullscreen" value="false" /><param name="allowscriptaccess" value="always" /><param name="wmode" value="opaque" />';
	e += '<param name="movie" value="'+domain+'e/' + videoID + '" />';
	e += '<embed src="'+domain+'e/' + videoID + '" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" wmode="opaque" width="' + w + '" height="' + h + '"></embed></object>';
	e += '</div>';
	if(manual == true) return e;
	else document.write(e);
};
function swapVideo(div, videoID) {
	var vp = $('#'+div);
	vp.html(ChookTV(videoID, vp.width(), vp.height(), true));
}


// When the document loads do everything inside here ...
$(document).ready(function () {
	
	var ie6 = false;
	if (navigator.userAgent.match(/msie/i))
	{
		var version = navigator.userAgent.match(/msie [^\r\n][^\r\n][^\r\n]/i);
		version = Number(version[0].substring(5, 6));
		if (version < 7) ie6 = true;
	}
	var ie7 = false;
	if (navigator.userAgent.match(/msie/i))
	{
		var version = navigator.userAgent.match(/msie [^\r\n][^\r\n][^\r\n]/i);
		version = Number(version[0].substring(5, 6));
		if (version < 8) ie7 = true;
	}
	var ie = false;
	if (navigator.userAgent.match(/msie/i))
	{
		ie = true;
	}
	var iOS = false;
	if (navigator.userAgent.match(/ipad/i) || navigator.userAgent.match(/iphone/i))
	{
		iOS = true;
	}
	
	//NAVIGATION DROPDOWN
	var lastSub = null;
	$("nav li").mouseenter(function()
	{
		lastSub = null;
		$(this).children(".DropdownNav").show();
		$(this).children(".DropdownNav").css({opacity:0});
		$(this).children(".DropdownNav").stop().animate({opacity:1}, 1000, "easeOutExpo");
	    
	});
	$("nav li").mouseleave(function()
	{
		 $(this).children(".DropdownNav").hide();
		//lastSub = this;
	   // $(this).children(".DropdownNav").stop().animate({opacity:0}, 500, "easeOutExpo", hideSub);
	});
	function hideSub()
	{
		if (lastSub) $(lastSub).children(".DropdownNav").hide();
	}
	
	//NAVIGATION DROPDOWN
	var lastSub = null;
	$(".ShowNavigation li").mouseenter(function()
	{
		lastSub = null;
		$(this).children(".DropdownNav").show();
		$(this).children(".DropdownNav").css({opacity:0});
		$(this).children(".DropdownNav").stop().animate({opacity:1}, 1000, "easeOutExpo");
	    
	});
	$(".ShowNavigation li").mouseleave(function()
	{
		 $(this).children(".DropdownNav").hide();
		//lastSub = this;
	   // $(this).children(".DropdownNav").stop().animate({opacity:0}, 500, "easeOutExpo", hideSub);
	});
	function hideSub()
	{
		if (lastSub) $(lastSub).children(".DropdownNav").hide();
	}

	
	// BUTTON ROLLOVERS
	var rolloverExceptions = ["Curious"];
	if (!ie6 && !iOS && !ie)
	{
		$(".Button").each(function()
		{
			if (!excludeButtton(this))
			{
				$(this).append('<span class="Rollover"></span>');
				$(this).children("span.Rollover").hide();
				$(this).children("span.Rollover").width($(this).width() - 2);
				$(this).children("span.Rollover").height($(this).height() - 2);
				$(this).mouseenter(ButtonOver);
				$(this).mouseleave(ButtonOut);
			}
		});
	}
	function excludeButtton(button)
	{
		var has = false;
		for (var i = 0; i < rolloverExceptions.length; i ++)
		{
			if ($(button).hasClass(rolloverExceptions[i])) has = true;
		}
		return has;
	}
	function ButtonOver()
	{
		$(this).children("span.Rollover").show();
	}
	function ButtonOut()
	{
		$(this).children("span.Rollover").hide();
	}
	
	// FANCYBOX
	$('.Fancybox').find("a").fancybox({
		'scrolling'		: 'no',
		'titleShow'		: true,
		'titlePosition'	: 'inside',
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'easingIn'      : 'easeOutBack',
		'easingOut'     : 'easeInBack',
		'speedIn'     	: 500,
		'speedOut'     	: 500
	});
	
	// SEARCH
	var initialValue = "I am looking for...";
	$(".SearchBox").val(initialValue);
	$(".SearchBox").focus(function()
	{
		if ($(this).val() == initialValue)
		{
			$(this).val("");
		}
	});
	$(".SearchBox").blur(function()
	{
		if ($(this).val() == "")
		{
			$(this).val(initialValue);
		}
	});

    // ADVERTISEMENTS
    function LoadAdverts() {

        $('._Advertisement').each(function (i) {
            // Get Settings
            var ord = new Date().getTime();
            var settings = $(this).html().replace('<!--', '').replace('-->', '').replace(' ', '');

            // Leaderboard (Option)
            if (settings.indexOf('728x90') > 0) {
                $(this).html('<iframe src="//fcsrv.adimise.com/serve.aspx?siteid=1095&adposition=3&ifr=1&random=' + ord + '?" style="width:728px;height:90px;" frameborder="0" scrolling="no"></iframe>');

                // Med Rec (Option)
            } else if (settings.indexOf('300x250') > 0) {
                $(this).html('<iframe src="//fcsrv.adimise.com/serve.aspx?siteid=1095&adposition=4&ifr=1&random=' + ord + '?" style="width:300px;height:250px;" frameborder="0" scrolling="no"></iframe>');
            }

        });
    };
    $(window).load(function () { LoadAdverts() });

    //Channel Tabs On Home Page
    // When a link is clicked
	if (navigator.userAgent.match(/msie/i)) $(".ChannelContent").height(270); // ie hack for the height
    $("a.Tab").click(function () {

        // switch all tabs off
        $(".Active").removeClass("Active");

        // switch this tab on
        $(this).addClass("Active");

        // slide all content up
		var Channel_show = $(this).attr("name");
        $(".ChannelContent").each(function()
		{
			if ($(this).attr("id") != Channel_show)
			{
				if (!ie6 && !ie7)
				{
					$(this).stop().animate({opacity:0}, 500, "easeOutExpo");
				}
				else
				{
					$(this).hide();
				}
			}
		});

        // slide this content up
		if (!ie6 && !ie7) $("#" + Channel_show).css({opacity:0});
		$("#" + Channel_show).show();
      	if (!ie6 && !ie7) $("#" + Channel_show).stop().animate({opacity:1}, 500, "easeOutExpo");
    });

    // Adds NoMarginRight To The Last Item In Content 2,3,4,5 Items Area.
    $('.Content2 .Item:nth-child(2n)').addClass('NoMarginRight');
    $('.Content3 .Item:nth-child(3n)').addClass('NoMarginRight');
    $('.Content4 .Item:nth-child(4n)').addClass('NoMarginRight');
    $('.Content5 .Item:nth-child(5n)').addClass('NoMarginRight');

    // Removes Border Of Last Pod In Right Column
    $('#RightColumn .Pod').last().addClass('NoBorderBottom');

    //Quick Find Toggle
	var qfInitialHeight = $(".QuickFindContent").innerHeight();
    $(".QuickFindButton").click(function () {
       	if (ie6)
		{
			$(".QuickFindButton").hide();
		}
		else
		{
			$(".QuickFindButton").stop().animate({opacity:0}, 500, "easeOutExpo", hideQuickFind);
		}
        $(".QuickFindContent").slideDown(400, "easeOutExpo");
	   //$(".QuickFindContent").stop().animate({height:qfInitialHeight}, 400, "easeOutExpo");
    });
    $(".QuickFindButtonInner").click(function () {
        $(".QuickFindContent").slideUp(400, "easeOutExpo");
		 /*$(".QuickFindContent").stop().animate({height:0}, 400, "easeOutExpo", function()
		 {
			$(".QuickFindButton").show(); 
		 });*/
		if (ie6)
		{
			$(".QuickFindButton").show();
		}
		else
		{
			$(".QuickFindButton").css({opacity:0});
			$(".QuickFindButton").show();
			$(".QuickFindButton").stop().animate({opacity:1}, 500, "easeOutExpo");
		}
       	
    });
	function hideQuickFind()
	{
		$(".QuickFindButton").hide();
	}

    // Calculate Quick Link Button Position
    $(document).ready(function () {
        $('.QuickFindButton').css("left", (($(window).width() - $('.QuickFindButton').width()) / 2));
    });
    $(window).resize(function () {
        $('.QuickFindButton').css("left", (($(window).width() - $('.QuickFindButton').width()) / 2));
    });

    // Adds NoMarginRight To The Last Left In Quick Find Area.
    $('.QuickFindContentArea .Top .Left:nth-child(3n)').addClass('NoMarginRight');
    $('.QuickFindContentArea .Bottom .Left:nth-child(3n)').addClass('NoMarginRight');

    // Nat Geo Snap Pod.
    // Switch From Split Images To One Full Image
    $(".Full").click(function () {
        $("#Full").show();
        $("#Split").hide();
    });
    // Switch From One Full Image To Split Images
	
	
	//$("#SnapSwitch").addClass("Full");
    $("#SnapSwitch").click(function () {
        if ($(this).hasClass("Full"))
		{
			$(this).removeClass("Full");
			$("#Split").css({opacity:0, "z-index":10});
			$("#Full").css({"z-index":0});
			$("#Split").show();
			if (!ie6)
			{
				$("#Split").stop().animate({opacity:1}, 500, "easeOutExpo");
				$("#Full").stop().animate({opacity:0}, 500, "easeOutExpo");
			}
			else
			{
				$("#Full").hide();
			}
			
			var snapFull = window['snapFull'];
			var currentPos = snapFull.currentPos;
			var newPos = Math.floor(currentPos / 4);
			var snapSplit = window['snapSplit'];
			snapSplit.moveIt(newPos);
		}
		else
		{
			$(this).addClass("Full");
			$("#Full").css({opacity:0, "z-index":10});
			$("#Split").css({"z-index":0});
			$("#Full").show();
			if (!ie6)
			{
				$("#Full").stop().animate({opacity:1}, 500, "easeOutExpo");
				$("#Split").stop().animate({opacity:0}, 500, "easeOutExpo");
			}
			else
			{
				$("#Split").hide();
			}
			var snapSplit = window['snapSplit'];
			var currentPos = snapSplit.currentPos;
			var newPos = currentPos * 4;
			var snapFull = window['snapFull'];
			if (Math.abs(newPos - snapFull.currentPos) >= 4) snapFull.moveIt(newPos);
		}
    });
    
    //Twitter Feed Pod.
    $(".TwitterContent li.Item:last").addClass("Last");
        
    // Show Pages 
    // Show Navigation 
    // First A(tag) Border Turned Off
    $('.InnerFeature .InnerFeatureContent .ShowNavigationArea .ShowNavigation .Navigation li').first().addClass('NoBorderLeft');
    $('.UpcomingEpisodesArea.Pod .Content1 .Item').last().addClass('NoBorderBottom');
    $('.RelatedArticlesArea.Pod .Content1 .Item').last().addClass('NoBorderBottom');
    $('.RelatedShowsArea.Pod .Content1 .Item').last().addClass('NoBorderBottom');

    // Win Pages 
    $('#Current.CompetitionsArea.Content1 li.Item').last().addClass('NoBorderBottom');
    $('#Previous.CompetitionsArea.Content1 li.Item').last().addClass('NoBorderBottom');
    
    // TV Guide
    $('#TVPods.Content3 .Item:nth-child(3n)').removeClass('NoMarginRight');
    $('#TVPods.Content3 .Item:nth-child(4n)').addClass('NoMarginRight');
    $('#TVPods .Content1 li.Item:nth-child(3n)').addClass('NoBorderBottom');
    
    //Videos Page 
    $('.VideosAreaContent .VideosNavigation li .Border2').last().removeClass('Border2');
    
    // BREADCRUMBS
    $('.Breadcrumbs a').last().addClass('Bold');
    
    // ARTICLES
    $('.RelatedTags li').first().addClass('NoPaddingLeft');
    
    //COMMUNITY
    $('.ExplorersPage .Content1 .Item').last().addClass('NoBorderBottom');

});

// Reminders
function SetReminder(GuideID, TypeID) {
    alert('Request for ' + TypeID + ' reminder for ' + GuideID);
}




