/* nbc learn js library
 * $Revision: 4965 $
 * $Id: nbclearn.js 4965 2010-06-03 17:21:47Z rcrathore $ 
 */
var tabSelected = 0;
var openCardUrlPrefix="";
var ChapterInitCueCard={};
window.onload = function() {
    siteInitialize();
}

$(function() {
	$('#dialog').jqm({modal:true});
	$('#dialog2').jqm({
		modal:true,
		closeClass:'jqmClose2',
		trigger: '.jqModal2'
	});
	$('#dialog3').jqm({
		modal:true,
		closeClass:'jqmClose3',
		trigger: '.jqModal3'
	});
	$('#dialog4').jqm({
		modal:true,
		closeClass:'jqmClose4',
		trigger: '.jqModal4'
	});
	
	/*Stop IE flicker*/
	if ($.browser.msie == true) {
		document.execCommand('BackgroundImageCache', false, true);
	}
	var origTab = tabSelected;
	if (origTab == 42 || origTab == 43 || origTab == 421) {
		tabSelected = 4;
	}
	var $tabs = $("#header").tabs ({
		selected: tabSelected,
		select: function(event, ui) {
		      if (ui.panel.id == 'original_video_tab')
		      {
		    	  $('#video_home').show();
		    	  $('#soto,#ftd_chapters,#oldsoto').hide();
		    	  return true;
		      }
		}
	});

	if (origTab == 42 || origTab == 421) {
		$('#soto').show();
  	  	$('#video_home,#ftd_chapters,#oldsoto').hide();
  	  	if (origTab == 421) {
  	  		goftdch("9");	
  	  	}
	}
	
	if (origTab == 43) {
		$('#oldsoto').show();
  	  	$('#video_home,#ftd_chapters,#soto').hide();
	}
	
	$('a[id^=gospecial]').click(function() {
	    $tabs.tabs('select', 4);
	    $('#soto').show();
  	  	$('#video_home,#ftd_chapters,#oldsoto').hide();
	    return false;
	});
	
	$('#gok12').click(function() {
	    $tabs.tabs('select', 1);
	    return false;
	});

	$('#gohed').click(function() {
	    $tabs.tabs('select', 2);
	    return false;
	});

	$('#goicue').click(function() {
	    $tabs.tabs('select', 3);
	    return false;
	});

	$('#govid').click(function() {
	    $tabs.tabs('select', 4);
	    return false;
	});
	
	$(".videolink").click(function() {
		$('#ftd_chapters,#oldsoto').hide();
		$('#video_home, #soto').toggle();
		return false;
	});
	$(".videohomelink").click(function() {
		$('#ftd_chapters,#soto,#oldsoto').hide();
		$('#video_home').show();
		return false;
	});
	$(".ftdhomelink").click(function() {
		$('#ftd_chapters,#video_home,#oldsoto').hide();
		$('#soto').show();
		return false;
	});
	
	$(".gooldsoto").click(function() {
		$tabs.tabs('select', 4);
		$('#ftd_chapters,#video_home,#soto').hide();
		$('#oldsoto').show();
		return false;
	});
	
	$("ul.sub_nav > li.selected > a").click(function() {
		return false;
	});
	
	 var so = new SWFObject("http://icue.nbcunifiles.com/icue/files/icue/facebook/SuperQuidget_noAutoPlay/Small_Quidget.swf", "Small_Quidget", "300px", "250px", "8", "#000000");
	 so.addParam("salign", "tl");
	 so.addParam("allowScriptAccess","always");
	 so.addVariable("htmlURL",document.URL);
	 so.write("Small_Quidget");

	 $("body > img[name=s_i_nbcuglobal]").wrap('<div class="s_i_nbcuglobal"></div>');
	/* SCatalyst Begin  */
        s.pageName=document.title;
        s.server="";
        s.channel="Home";
        s.pageType="";
        s.prop1="Guest";
        s.prop2="";
        s.prop3="Assets";
        s.prop4="";
        s.prop5="AutoOpen";
        s.prop10="Promo";
        s.prop14="Video";
        s.eVar1="Portal Home";
        s.events="";


        s.eVar3="Guest";
        s.eVar4="";

        s.eVar11="";
        s.eVar12="";
        s.eVar14="";

        s.eVar21="";
        s.eVar22="";
        s.eVar23="";
        s.eVar24="";
        s.eVar30="";
	var s_code=s.t();
	if(s_code)document.write(s_code);
         /* SCatalyst End */
});

/* triggered at page load */
function siteInitialize()
{
    /* prevents dotted outline around clicked elements in firefox */
    window.onclick = function(theEvent)
    {
            theTagName = theEvent.target.tagName;
            doBlur = true;
            if (theTagName == "INPUT") doBlur = false;
            if (theTagName == "SELECT") doBlur = false;
            if (theTagName == "TEXTAREA") doBlur = false;
            if (theTagName == "OPTION") doBlur = false;
            if (theTagName == "EMBED") doBlur = false;

            if (doBlur) {
                    theEvent.target.focus = theEvent.target.blur();
            }
    }
}
function updateFlashContainerHeight(state)
{
	var flashPlayer_mc = CueCardManager.thisMovie('nbclearn');
	if (state == "expanded")
	{
		var scrollOffset = 0;
		if (document.body && typeof document.body.scrollTop != "undefined")
		{
			scrollOffset += document.body.scrollTop;
			if (document.body.parentNode && typeof document.body.parentNode.scrollTop != "undefined") { 
				scrollOffset += document.body.parentNode.scrollTop;
			}
		} else if (typeof window.pageYOffset != "undefined") { 
			scrollOffset +=  window.pageYOffset;
		}
		$("#flashContainer").css( { height : "100%" } );
		$("#flashContainer").css( { width : "100%" } );
		flashPlayer_mc.height = $(window).height() + scrollOffset;
	} else {
		$("#flashContainer").css( { height : "2px" } );
		flashPlayer_mc.height = "2";
	}
}
function scrollUp() {
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
		window.scroll(0,25);
	}
	return true; 
}
function initCard() {}
var CueCardManager = {
		isInitialized:false,
		thisMovie:function(movieName)
		{
			  var movie ;
			  try {
				  if (navigator.appName.indexOf("Microsoft Internet")==-1)
				  {
				    if (document.embeds && document.embeds[movieName]) {
				      	movie = document.embeds[movieName]; 
				    }
				  }
				  if (navigator.appName.indexOf("Microsoft") != -1) 
				  {
					movie = window[movieName]
				 } else {
					movie = document[movieName]
				 }
			  } catch (ex) {
			  	/* alert(ex) ; */
			  }
			return movie ;
		},
		openCard:function(cardID, modeid)
		{		
			if (this.isInitialized) {
				scrollUp();
				updateFlashContainerHeight('expanded');
				this.thisMovie('nbclearn').newCard(cardID, "noGuestMode");
				this.expandFlashMovie();
			}
		},
		closeFlashArea:function(reloadPage, cueCardId, playlistid, playlistname)
		{
			flashVisible = false;
			updateFlashContainerHeight();
			if(reloadPage != undefined && (reloadPage == true || reloadPage == "true") && isPlaylistActive)
			{
				try {
					moveItemInPlaylist(cueCardId, playlistid, playlistname);
				} catch(error) {
					/*silencing the exception*/
				}
			}
		},
		markCueCardAsFavorite:function(cueCardId, fave)
		{
			try {
				doMarkCueCardAsFavorite(cueCardId, fave);
			} catch(error) {
				/*silencing the exception*/
			}
		},
		expandFlashMovie:function()
		{
			flashVisible = true;
			updateFlashContainerHeight('expanded');
		},
		tagChanged:function(tagText, weight)
		{
				try {
					doTagChanged(tagText, weight);
				} catch(error) {
					/*silencing the exception*/
				}
		},
		openStateStandardsForCueCard:function(clipid) {
		},
		singleCardReady:function()
		{
			this.isInitialized = true ;
			if (ChapterInitCueCard && ChapterInitCueCard.cuecardid) {
				 CueCardManager.openCard(openCardUrlPrefix + ChapterInitCueCard.cuecardid);
			} 
			
		}
};
function updateFlashContainerHeightForInstaller(state) {}
function initInstallerCard() {}
