/* nbc learn js library
 * $Revision: 7834 $
 * $Id: nbclearn.js 7834 2011-05-06 15:08:06Z rcrathore $ 
 */
var tabSelected = 0;
var openCardUrlPrefix="";
var ChapterInitCueCard={};
var addthis_config = {
		services_compact: 'email,favorites,myspace,twitter,facebook,google,stumbleupon,digg,newsvine,aim,myaol,delicious,more',
		ui_language: 'en'
};
addthis_share = {
		url: "",
		title : ""
};
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'
	});
	
	$(".videolink").click(function() {
		$('#chemnow,#chemnow_chapters,#ftd_chapters,#soto,#nfl,#oldsoto,#climate').hide();
		$('#video_home').show();
		return false;
	});
	
	$(".videohomelink").click(function() {
		$('#chemnow_chapters,#ftd_chapters,#soto,#oldsoto,#nfl,#climate').hide();
		$('#video_home').show();
		return false;
	});
	
	$(".ftdhomelink").click(function() {
		$('#chemnow_chapters,#ftd_chapters,#video_home,#oldsoto,#nfl,#climate').hide();
		$('#soto').show();
		return false;
	});
	
	$(".chemnowhomelink").click(function() {
		$('#soto,#ftd_chapters,#chemnow_chapters,#video_home,#oldsoto,#nfl,#climate').hide();
		$('#chemnow').show();
		return false;
	});
	
	$("ul.sub_nav > li.selected > a").click(function() {
		return false;
	});
	
	/*Stop IE flicker*/
	if ($.browser.msie == true) {
		document.execCommand('BackgroundImageCache', false, true);
	}
	var origTab = tabSelected;
	if (origTab == 32 || origTab == 33 || origTab == 321 || origTab == 34 
			|| origTab == 35 || (origTab >= 351 && origTab <= 399) || origTab == 36) {
		
		tabSelected = 3;
	}
	var $tabs = $("#header").tabs ({
		selected: tabSelected,
		select: function(event, ui) {
		      if (ui.panel.id == 'original_video_tab')
		      {
		    	  $('#video_home').show();
		    	  $('#soto,#ftd_chapters,#oldsoto,#nfl,#chemnow,#chemnow_chapters,#climate').hide();
		    	  return true;
		      }
		}
	});

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

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

	$('#govid').click(function() {
	    $tabs.tabs('select', 3);
	    return false;
	});
	
	$('a[id^=gospecial]').click(function() {
	    $tabs.tabs('select', 3);
	    $('#soto').show();
  	  	$('#video_home,#ftd_chapters,#oldsoto,#chemnow,#chemnow_chapters,#climate').hide();
	    return false;
	});
	
	$(".gooldsoto").click(function() {
		$tabs.tabs('select', 3);
		$('#ftd_chapters,#video_home,#soto,#nfl,#climate').hide();
		$('#oldsoto').show();
		return false;
	});
	
	$(".gonfl").click(function() {
		$tabs.tabs('select', 3);
		$('#ftd_chapters,#video_home,#soto,#oldsoto,#chemnow,#chemnow_chapters,#climate').hide();
		$('#nfl').show();
		addThis('nfl', 'NBC Learn- Science of the NFL');
		return false;
	});
	
	$(".goclimate").click(function() {
		$tabs.tabs('select', 3);
		$('#nfl,#ftd_chapters,#video_home,#soto,#oldsoto,#chemnow,#chemnow_chapters').hide();
		$('#climate').show();
		addThis('changingplanet', 'NBC Learn- Changing Planet');
		return false;
	});
	
	$(".goftd").click(function() {
	    $tabs.tabs('select', 3);
	    $('#soto').show();
  	  	$('#video_home,#ftd_chapters,#oldsoto,#nfl,#chemnow,#chemnow_chapters,#climate').hide();
	    return false;
	});
	
	$(".gochemnow").click(function() {
	    $tabs.tabs('select', 3);
	    $('#soto,#video_home,#ftd_chapters,#chemnow_chapters,#oldsoto,#nfl,#climate').hide();
	    $('#chemnow').show();
  	    addThis('chemistry', 'NBC Learn- Chemistry Now');
	    return false;
	});
	
	if (origTab == 32 || origTab == 321) {
		$('#soto').show();
  	  	$('#video_home,#ftd_chapters,#oldsoto,#nfl,#chemnow,#chemnow_chapters,#climate').hide();
  	  	if (origTab == 321) {
  	  		goftdch("9");	
  	  	}
	}
	
	if (origTab == 33) {
		$('#oldsoto').show();
  	  	$('#video_home,#ftd_chapters,#soto,#nfl,#chemnow,#chemnow_chapters,#climate').hide();
	}
	
	if (origTab == 34) {
		$('#nfl').show();
  	  	$('#video_home,#ftd_chapters,#soto,#oldsoto,#chemnow,#chemnow_chapters,#climate').hide();
  	    addThis('nfl', 'NBC Learn- Science of the NFL');
	}
	
	if (origTab == 35 || (origTab >= 351 && origTab <= 399)) {
		$('#chemnow').show();
		$('#nfl,#video_home,#ftd_chapters,#soto,#oldsoto,#chemnow_chapters,#climate').hide();
		addThis('chemistry', 'NBC Learn- Chemistry Now');
		if (origTab >= 351) {
			gochemnowch("" + (origTab -351));
		}
	}
	
	if (origTab == 36) {
		$tabs.tabs('select', 3);
		$('#nfl,#ftd_chapters,#video_home,#soto,#oldsoto,#chemnow,#chemnow_chapters').hide();
		$('#climate').show();
		addThis('changingplanet', 'NBC Learn- Changing Planet');
		return false;
	}
	
	 $("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 */
});

function addThis(pageId, pageTitle) {
	
	var addthisUrl = window.location.protocol + "//" + document.domain +  
	  (window.location.port ? (":" + parseInt(window.location.port)) : '') + 
	  "/" + pageId;
	
	addthis.update('share', 'url', addthisUrl);
	addthis.update('share', 'title', pageTitle);
	
	try {
		addthis.button('.shareme_button_' + pageId, addthis_config, addthis_share);
	} catch (err) {/* ignored */}
}

/* 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() {}
function ftdch(divId) {
	$("div[id^=ftd1div]").hide();
	$("div[id^=ftd2div]").hide();
	$("#ftd_chapters ul.image_items_v2").hide();

	$("div#ftd1div" + divId).show();
	$("div#ftd2div" + divId).show();
	$("ul.ftd3ul" + divId).show();
	return false;
}
function goftdch(divId) {
	$('#video_home,#soto').hide(); 
	$('#ftd_chapters').show();
	ftdch(divId);
}
function selectImg(toolbox_id, path, title)
{
  var a = document.createElement('a');
  a.setAttribute('class', 'addthis_button');
  a.setAttribute('addthis:url', path);
  a.setAttribute('addthis:title', title);
  a.setAttribute("onmouseover", "return addthis_open(this, '', '" + path + "','" + title + "')");
  a.setAttribute("onclick", "return addthis_sendto()");
  a.setAttribute("onmouseout", "addthis_close()");
  a.innerHTML = '';
  $('#' + toolbox_id).html('').append(a);
}
function chemnowch(divId) {
	$("div[id^=chemnow1div]").hide();
	$("div[id^=chemnow2div]").hide();
	$("#chemnow_chapters ul.image_items_v3").hide();

	$("div#chemnow1div" + divId).show();
	$("div#chemnow2div" + divId).show();
	$("ul.chemnow3ul" + divId).show();
	try {
		var addthisUrl = window.location.protocol + "//" + document.domain +  
		  (window.location.port ? (":" + parseInt(window.location.port)) : '') + 
		  "/chemistrynow/week" + (parseInt(divId) + 1);
		
		var pageTitle = "NBC Learn- Chemistry Now Week-" + (parseInt(divId) + 1);
		
		addthis.update('share', 'url', addthisUrl);
		addthis.update('share', 'title', pageTitle);
		   
		try {
			addthis.button('#addthis_chemistrychapters', addthis_config, addthis_share);
		} catch (err) {/* ignored */}
		
	} catch (err) {/* ignored */}
	
	return false;
}
function gochemnowch(divId) {
	$('#video_home,#chemnow,#soto,#ftd_chapters').hide(); 
	$('#chemnow_chapters').show();
	chemnowch(divId);
}
