//ontv flyout and tabs 
$(document).ready(function() {
    $("#MainMenu a[rel]").overlay({
        zIndex: '5000',
        oneInstance: false,
        effect: 'default',
        speed:'0',
        onLoad: function(){
            this.getTrigger().css("color", "black").toggleClass("close");
        },
        onClose: function(){
            this.getTrigger().css("color", "white").toggleClass("close");
        },
        closeAll : function(){
            $.each(instances, function(){
                this.close();
            });
        }
    });
    //  ontv flyout tabs
    $("#OntvTabList").tabs(".OntvTab", { event: 'click' });
//  ontv flyout columnizer
    $('.SplitList4').makeacolumnlists({ cols: 4, colWidth: 155, equalHeight: false, startN: 1 });
    $('.SplitList3').makeacolumnlists({ cols: 3, colWidth: 215, equalHeight: false, startN: 1 });
    $('.AllShowsList').makeacolumnlists({ cols: 3, colWidth: 140, equalHeight: false, startN: 1 });
    $('.RecipeGuideList').makeacolumnlists({ cols: 3, colWidth: 200, equalHeight: false, startN: 1 });
    $('.ErrorList').makeacolumnlists({ cols: 2, colWidth: 200, equalHeight: false, startN: 1 });
    $('.RecipeSubList').makeacolumnlists({ cols: 3, colWidth: 130, equalHeight: false, startN: 1 });
    $('.AdvancedSearchList').makeacolumnlists({ cols: 2, colWidth: 100, equalHeight: false, startN: 1 });
    $('.ColumnList2Corporate').makeacolumnlists({ cols: 2, colWidth: 165, equalHeight: false, startN: 1 });
    $('.Center2ColumnList').makeacolumnlists({ cols: 2, colWidth: 218, equalHeight: false, startN: 1 });
//  homepage rotator
    $("#RotatorNav ul").tabs(".RotatorContent > div",{
        event: 'mouseover',
		effect: 'fade',
		clickable:false,
		rotate: true
	}).slideshow({ autoplay:true, interval: 6000, clickable:false });
//	featured content tabs
	$("ul.TopFeaturedTabs").tabs("div.TopFeaturedContent > div",{});
//	featured content tabs video scroller
    $(".TopVideoScroller").scrollable({item: '.item', size: 2, keyboard: false}).circular().navigator().mousewheel().autoscroll({
        steps: 2,
        interval: 10000,
        autoplay: false
    });
//	featured videos
    $("#FeaturedVideos > ul.FeaturedVideos").tabs("div.Video > div");
//  recipe ideas
    $("#RecipeIdeas > ul.RecipeIdeas").tabs("div.Recipe > div");
//  from the community
    $("ul.FromTheCommunity").tabs("div.CommunityTabsContent > div");
//  mini schedule
    $("ul.MiniScheduleNav").tabs("div#MiniSchedule > ul.ScheduleList",{initialIndex:'2'});
//  host scroller
    $('.HostScrollable .HostItem').tooltip({
		position: 'top right',
		tip: '.HostScrollable .tooltips', effect: 'fade', delay: '1000',
		relative: true
	});
	$('#HostsFooter .HostScroller').scrollable({
		item: '.HostItem',
		absolute: false,
		size: 6,
		keyboard: false
	}).mousewheel().autoscroll({ autoplay: true, autopause: true, steps: 1, interval: 10000 });
    //daily dish scroller
    var api = $("#DishScroller").scrollable({
        items: '.item',
        size: 1,
        clickable: false,
        keyboard: false
    }).circular().autoscroll({ interval: 4000 }).mousewheel();
    var api = $("#DishScrollerRight").scrollable({
        items: '.item',
        size: 1,
        clickable: false,
        keyboard: false
    }).circular().autoscroll({ interval: 4000 }).mousewheel();
    //recipes glossary tooltip
    $('.RecipeDetail a.ActionItem').tooltip({
		    position: 'top right',
		    tip: '.RecipeDetail .GlossaryTip', effect: 'fade', delay: '1000',
		    relative: true
	    });
	//ontv episode tabby navigation
	$("ul.EpisodesNav").tabs("div.EpisodeContent > div.SeasonContent");
	$("div.SeasonContent").tabs("div.SeasonContent > .EpisodeItem", {tabs: 'h4', effect: 'slide'});
	// this initialises the scrollbars.
	$('.Scrollbars').jScrollPane({showArrows:true, scrollbarWidth: 14});

});
// initialises photo gallery
$(document).ready(function() {
		$("a.fancybox").fancybox({
			'overlayOpacity': 0.9,
			'zoomSpeedIn': 500,
			'zoomSpeedOut': 300,
			'frameWidth': 965,
			'frameHeight': 760,
			'iframeScrolling': 'no',
			'hideOnContentClick': false,
			'centerOnScroll': false,
			'callbackOnClose': callBackClose
		});
	});
	function callBackClose(){
	//enablet this to track clicks for Google analytics
		//pageTracker._trackEvent('Fancybox', 'Close')
	}

//TV SCHEDULE SETUP AND RUN
//function to get param by name from query string
function getParam(n){
  n = n.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+n+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if(results == null)
	 return "";
  else
	 return results[1];
}

//-- SCHEDULE INITIALIZATION
function initOnTvSchedule() {
	//do check when page loads for query or cookie
	var s = 0;
	if (getParam('t')) {
		s = getParam('t');
	} else if ($.cookie('scheduleRegion')) {
		s = $.cookie('scheduleRegion');
	}
	//init tv schedule plugin
	schedule = $('#TVSchedule').tvschedule(".ScheduleContainer", {
		timezone: s, startY: parseInt($("#ShowOnNowPosition").text())
	});
	function updateAnchors() {
		$("#scheduleAnchors a").each(function() {
			if ($(this).hasClass("Selected")) {
				$(this).removeClass("Selected");
			}
		});
	}
	$("#schedulePrimetime").click(function(e) {
		updateAnchors()
		$(this).addClass("Selected");
		schedule.move(schedule.currXPos, 40, 0);
		pageTracker._trackEvent('Schedule', 'TOD', 'Primetime');
		e.preventDefault();
	});
	$("#scheduleDaytime").click(function(e) {
		updateAnchors()
		$(this).addClass("Selected");
		schedule.move(schedule.currXPos, 26, 0);
		pageTracker._trackEvent('Schedule', 'TOD', 'Daytime');
		e.preventDefault();
	});
	$("#scheduleMorning").click(function(e) {
		updateAnchors()
		$(this).addClass("Selected");
		schedule.move(schedule.currXPos, 14, 0);
		pageTracker._trackEvent('Schedule', 'TOD', 'Morning');
		e.preventDefault();
	});
	//setup calendar
	var currCalDay = 7;
	$("#ScheduleCalendar .ScheduleCalendarDay a").each(function(i) {
		$(this).click(function(e) {
			//toggle old day class
			$(".ScheduleCalendarDays .selected").toggleClass("selected");
			//toggle new day class
			$(".CalendarDays .ScheduleCalendarDay:eq(" + i + ")").toggleClass("selected");
			//update schedule's new day class
			schedule.updateHighlight(i);
			//update schedule position
			schedule.move(i - 1, schedule.currYPos, 0);
			pageTracker._trackEvent('Schedule', 'Calendar', i);
			e.preventDefault();
		});
	});
	//remove first select list value
	$("#t option:first").remove();
	//update select selected value accordingly
	$("#t option").each(function() {
		if ($(this).val() == s) {
			$(this).attr("selected", "selected");
		}
	});
	//when user changes select option update page by submitting form
	$("#t:input").change(function() {
		if ($("#t").val() != "select") {
			$.cookie('scheduleRegion', $("#t").val(), { path: '/', expires: 365 * 2 });
			pageTracker._trackEvent('Schedule', 'Timezone', $("#t").val());
			$("#timezone").submit();
		}
	});
	// create custom drop down (this function is in global_functions.js
	createDropDown($("#t").attr("id"));
	$("#t").css("display", "none");
}
