var JSON = {};
JSON.parse = function (str) {
	if (str === "") str = '""';
	eval("var p=" + str + ";");
	return p;
};


function initModuleProperties() {
	// Grab the CMS properties and make them available for JS via (module's parent element).moduleProperties
	$(".module>script").each(function(){
		var json = $(this).html();
		json = JSON.parse(json);
		this.parentNode.moduleProperties = json;
	});
}


$(function(){
	initModuleProperties();

	if (window.opera) {
		$("body").addClass("opera");
	};
});

function userSignout() {
	var carpetBombingTemplate = "BLUE=;expires=Thu, 01-Jan-70 00:00:01 GMT;domain=${domain};path=/;";
	var domains = location.hostname.split(".");
	for (var i = 0, ii = domains.length; i < ii; i++) {
		document.cookie = carpetBombingTemplate.replace("${domain}", "." + domains.slice(i).join("."));
	}
	location = "/";
}


function hideOverlay() {
	//Hide the overlay Ad
	document.getElementById("ad-overlay").style.display = "none";
}


/*
* jQuery Backstretch 1.0
* http://srobbin.com/jquery-plugins/jquery-backstretch/
*
* Add a dynamically-resized background image to the page
*
* Copyright (c) 2009 Scott Robbin (srobbin.com)
* Dual licensed under the MIT and GPL licenses.
*
* Customized for Disney.
*
*/

(function($) {

  $.backstretch = function(src, options, callback) {
    var settings = {
          hideUntilReady: false, // Hide the image until it's finished loading
          speed: 0 // fadeIn speed for background after image loads (e.g. "fast" or 500)
        },
        imgRatio;
    
    // Extend the settings with those the user has provided
    if(options && typeof options == "object") $.extend(settings, options);
    
    // Initialize
    $(document).ready(_init);
  
    // For chaining
    return this;
    
    function _init() {

		var src = $("body").css("background-image").replace(/"/g,"").replace(/url\(|\)$/ig, "");
		
        var commonCSS = {left: 0, top: 0},
            wrap = $("<div />").attr("id", "backstretch-wrap")
                               .css( $.extend(commonCSS, {position: "absolute", zIndex: -1}) ),
            container = $("<div />").attr("id", "backstretch")
                                    .css( $.extend(commonCSS, {position: "fixed", overflow: "hidden", zIndex: -1}) )
                                    .appendTo(wrap),
            img = $("<img />")
            	.bind("load", function() { 
                	  img = this
                	  // setTimeout (1) required to fix IE behavior
                	  setTimeout ( function() { 
                		  var self = $(img);
                		  window.originalBgWidth = self.width();
                		  window.originalBgHeight = self.height();
							
                		  imgRatio = self.width() / self.height();
                		  _adjustBG(function() {
                			  if( settings.hideUntilReady )
                				  self.fadeIn(settings.speed, function(){
                					  // Callback, if necessary
                					  if(typeof callback == "function") callback();
                				  });
                		  });
                	  }, 1);                                  
			
			                              }).attr("src", src);
        
        if(settings.hideUntilReady) img.hide();
        img.appendTo(container);
          
        $("body").prepend(wrap);

        // Adjust the background size when the window is resized (but is bigger than the original background image in the CSS - if smaller, turn off the modified image)
        $(window).resize(_adjustBG);

      
    }
    
    function _adjustBG(callback) {

		if (window.originalBgWidth < $(window).width()) {

			$("#backstretch").css("visibility","visible");

		  var bgWidth = $(window).width(),
			  bgHeight = bgWidth / imgRatio;
		  
		  if(bgHeight < $(window).height()) {
			bgHeight = $(window).height();
			bgWidth = bgHeight * imgRatio;
		  }

		  $("#backstretch img").width( bgWidth ).height( bgHeight );

		  
		  if (typeof callback == "function") callback();
    
		}
		
		else {			
			$("#backstretch").css("visibility","hidden"); 
			}
		
	}
  };

})(jQuery);

$.backstretch();