function toggleTeacherBar(contentType)
{
	$('.teacherbar-button', window.parent.document).removeClass('active');
	if(contentType == 'pd')
		$('#content-pdtab', window.parent.document).addClass('active');
	else if(contentType == 'standards')
		$('#content-standardstab', window.parent.document).addClass('active');
	else if(contentType == 'favorites')
		$('#content-favoritestab', window.parent.document).addClass('active');
}

function loadLink(linkID, data, callback)
{
	if(typeof data == 'undefined') data = {};
	params = typeof data.params == 'undefined' ? {} : data.params;
	queryString = "";
	for (x in params)
	{
		if(queryString == '') queryString += "?";
		else queryString += "&";
		queryString += x;
		queryString += "=";
		if ( $.browser.msie && parseInt($.browser.version, 10) == 7) 
	    { 
	    	queryString += encodeURIComponent(encodeURIComponent(params[x]).replace(/%20/g, ' ')); 
	    }
	    else
	    {
	    	queryString += encodeURIComponent(params[x].replace(/%20/g, '+'));
	    } 
	}    
	SUBMIT_LOAD = typeof data.submitLoad == 'undefined' ? true : data.submitLoad;
	window.location.hash = "/" + linkID + queryString;
	
}


function loadUrl(contentUrl, data, callback)
{
	if(typeof data == 'undefined') data = {};
	data["contentUrl"] = contentUrl;
	loadContent(data, callback);
}

function loadContent(data, callback)
{
    var ifr = document.getElementById("content-frame");
	contentUrl = typeof data.contentUrl == 'undefined' || data.contentUrl == '' || data.contentUrl == null ? ifr.contentWindow.location : data.contentUrl;
	
	var theHeight = $("div#content-loadarea").height() < 710 ? 710 : $("div#content-loadarea").height();   
	$('div#content-loadarea').css({height: theHeight});

	if(data.authStatus == 'UNAUTHENTICATED' )
	{
		if($('#content-teacherbar').css('visibility') == 'visible')
			$('#content-teacherbar').animate({'opacity': 0}, 500, 'linear', function() {$('#content-teacherbar').css('visibility','hidden');} );
		loadLink("home");
	}
	else{
		$(".fader").show().animate({'opacity': 0.9}, 500, 'linear', function() {
		
			ifr.contentWindow.location.replace(contentUrl);
			
		});
		scroll(0,0); //scroll back to top
		if(callback) callback();
	}
}

function loadContentReady(data)
{
	resizeContent(data.showTeacherBar);
	toggleTeacherBar(data.contentType);
}

function resizeContent(showTeacherBar)
{	
	if(showTeacherBar && $('#content-teacherbar', window.parent.document).css('visibility') == 'hidden') 
	{
		$('#content-teacherbar', window.parent.document).css({'opacity': 0, 'visibility':'visible'}).animate({'opacity': 1}, 500, 'linear');
	}
	theHeight = $('#content-body').height() < 710 ? 710 : $('#content-body').height();
	$("div#content-loadarea", window.parent.document).animate({height: theHeight});
	$(".fader", window.parent.document).animate({'opacity': 0}, 500, function () {$(this).hide();} );
}
function openFancyBox(site, name){
	if(name = "productDemo"){
		$("a#productDemo").fancybox({
			width:660,
			height:404,
			titleShow: false,
			href: site,
			scrolling: 'no'
		});
		readyFancy("productDemo");
	}
	else if(name = "quickTour"){
		$("a#quickTour").fancybox({
			width:860,
			height:407,
			titleShow: false,
			href: site,
			scrolling: 'no'
				
		});
		readyFancy("quickTour");
	}
}

function readyFancy(name){
	$("a#"+ name).trigger("click");
}

