// protege.js
$(function () {


	var params  = { 
		scale: 'noScale', 
		background: '0x000000', 
		salign: 't', 
		wmode:'transparent',
		allowFullScreen: 'true',
       allowScriptAccess: 'always'
	};
	var flashvars = { syndicate:"false" };
	swfobject.embedSWF("protege_red_pre.swf", "flashreplace", "1024", "910", "9.0.0","expressInstall.swf",flashvars,params,{name:"flashmovie",id:"flashmovie"});
	swffit.fit("flashmovie",1024,910); 
	
	/*recalibrate();
    setTimeout(recalibrate, 50);
    setTimeout(recalibrate, 100);
    setTimeout(recalibrate, 200);
    setTimeout(recalibrate, 300);
    setTimeout(recalibrate, 500);
    setTimeout(recalibrate, 1000);*/
	
	
    $(window).resize(function() {
        recalibrate();
        recalibrate();
    });
    
	setTimeout("getScrolltop()",1000);
    
	
	$("#dither").click(function(e) {
		$("#dither").css({ display: "none" });
		$("#popover2").css({ display: "none" });
		e.stopPropagation();
	});
	
	var myloc = window.location.href;
	if ((myloc!=null) && (myloc!="") && (myloc.indexOf("gallery")>-1)) {
	  showfblikebox();
	}
	
	if($.browser.mozilla) {
	  $("body").addClass("mozilla");
	}
	
	recalibrate();
});



function getScrolltop() {	
	var flashObj = document.getElementById("flashmovie");
	flashObj.returnScrollTop($(window).scrollTop());
}

var toph = 671;
function recalibrate() {
    var wwidth = Math.floor($(window).width());
    var left = (wwidth - 1024)/2;
    var wheight = Math.floor($(window).height()) + $(window).scrollTop();  
    var additional = 290.5;
    
    if ( $("body").hasClass("mozilla") ) { additional = 305.5; }
    
    var fblikebox = $("#fblikebox");
    likeleft = Math.floor((wwidth-241)/2 + additional);
    
    fblikebox.css("left",likeleft + "px");
/*    var passtop = wheight - 50;
	var flashObj = document.getElementById("flashmovie");
	flashObj.handleScroll(passtop);*/
   
    $("#bottom").attr("style","left:"+left+"px;top:"+toph+"px;display:block;");
}

function scrollStart_privacy_policy(event, id, scroll_window_id) {
	maxTop = 349;
	minTop = 0;
	scrollStart(event, id, scroll_window_id);
}

function scrollStart_california_privacy_policy(event, id, scroll_window_id) {
	maxTop = 349;
	minTop = 0;
	scrollStart(event, id, scroll_window_id);
}

function scrollStart_childrens_privacy_policy(event, id, scroll_window_id) {
	maxTop = 349;
	minTop = 0;
	scrollStart(event, id, scroll_window_id);
}


function popover2() {
	if($("#popover2").css("display") != "none") {
		$("#dither").css({ display: "none" });
		$("#popover2").css({ display: "none" });
	} else {
		
		$("#dither").css({ display: "block", height: $(document).height() }).fadeTo(350, 0.85);
		$("#popover2").css({ display: "block" }).fadeTo(350, 0.9);
		// In the case that the the login scrim was open prior, alter the depth
		var ditherIndex = $("#dither").css("z-index");
		$("#LoginBase").css("z-index", (ditherIndex - 1));
	}
}


function refit(height) {
	swffit.fit("flashmovie",1024,height);
	toph = height - 45;
	recalibrate();
	recalibrate();
}

function showfblikebox() {
  $("#fblikebox").show();
}

function hidefblikebox() {
  $("#fblikebox").hide();
}

