/**************************************************************/
/*	 			 MAKE ADDITIONAL FUNCTIONS AFTER LINE 100	 				  */
/**************************************************************/

documentReadyListeners = new Array();

/**
 * Keeps an array of all registered document ready listeners. This
 * are invoked when the page is loaded by full page load or AJAX
 */
function documentReady(fnName){
	documentReadyListeners.push(fnName);
}

/**
 * Invokes all registered document ready listeners
 */
function invokeDocumentReadyListeners(firesifr){
	for(var i=0; i<documentReadyListeners.length; i++)
	{
		eval(documentReadyListeners[i] + "()");
	}	
}

/**
 * Define the global document ready handler
 */
jQuery(document).ready(function(){
    invokeDocumentReadyListeners(false);
});

function splitValue(value, token, index){
    var arr = value.split(token);
    return arr[index];
}

String.prototype.stripSpaces = function( ){ return this.replace( /\s/g, "" ); };

function whiteSpace(value){
    value = value.replace(/^\s*|\s*$/g, '');
    return value;
}

function removeSpaces(string) {
 return string.split(' ').join('');
}

function getParam(name){
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var result = regex.exec(window.location.href);
    if (result == null) 
        return "";
    else 
        return result[1];
}

function splitValue(value, token, index)
{
	 var arr = value.split(token);
 	 return arr[index];
} 

function vj_popup(url, width, height)
{
	 var params = 'width='+ width;
	 params += ', height='+ height;
	 params += ',menubar=yes';
	 params += ',toolbar=yes';
	 params += ',resizable=yes';
	 window.open(url,"", params);
}

function addCarousel(id, movieLocation, width, height, alt)
{
	var flashvars = {};
	var params = { };
	var attributes = {};
	
	flashvars.xmlpath = escape(jQuery("[id$='"+id+"']").attr("class"));
	flashvars.holdfor = "5";
	params.wmode = "opaque";
	
	var myMovie = movieLocation;
	var expressInstall = "/javascript/swfobject/expressInstall.swf";
	
	swfobject.embedSWF(myMovie, alt, width, height, "9.0.0", expressInstall, flashvars, params, attributes);
}

documentReady("attachPopupCode");
function attachPopupCode()
{
	jQuery(".shareLink").click( function() {
		vj_popup(jQuery(this).attr("href"), 400, 300);
		return false;
	}); 
}


function TextOnFocus(sender,text)
    {
        if (sender.value == text)
         { 
            sender.value='';
         }
         
    }
    function TextOnBlur(sender,text)
    {
        if (sender.value == '') 
        {
            sender.value=text; 
        }
    }

/**************************************************************/
/*				   	  	   EDIT BELOW THIS LINE											*/
/**************************************************************/

/**
 * Site Specific Functions Go Here:
 */

/*Cufon Replace*/

	Cufon.replace('h2:not(.no-cufon)');
	Cufon.replace('h3:not(.no-cufon)');
	Cufon.replace('.cufon:not(.no-cufon)', {	hover: true });
	Cufon.replace('.content .subNav li a:not(.no-cufon)', { hover: true });
	Cufon.replace('.content .findFranchise .searchBox label');
	//Cufon.replace('.content .franchisePortals .text a', { hover: true });
	//Cufon.replace('.content .portal .text a', { hover: true });
	
documentReady("equalHeights");
function equalHeights(){
    // Make each div as tall as the tallest div
    var maxHeight = 0;
		maxHeight = 0;
    $(".evenHeight").each(function() {
        if (jQuery(this).height() > maxHeight) { maxHeight = jQuery(this).height(); }
    }).height(maxHeight)
		;
    maxHeight = 0;
    
    $("body.aboutUs .portal").each(function() {
    if (jQuery(this).height() > maxHeight) { maxHeight = jQuery(this).height(); }
    }).height(maxHeight);
				
    maxHeight = 0;
}
	
documentReady("overlayImg");
function overlayImg() { 

    if($("a.gallery").length != 0)
    {
    $("a.gallery").overlay({   
      target: '#gallery',   
      expose: '#000'  
    }).gallery({speed:800, template: '<span>Image ${index} of ${total}</span>'}); 
  }
    
}
documentReady("subNav");
function subNav()
{
    $(".subNav li.active").each(function()
     {
        if($(this).children("ul").length != 0)
        {
            $(this).attr("class","subnav active");
        }
     });
     
     $(".subNav li.subnav.active li.on").each(function()
     {
       $(this).parent("ul").parent("li").attr("class","subnav");
			 Cufon.refresh();
     });
}

// JavaScript Document
$(document).ready(rollOverNav);
function rollOverNav (){
	$(".mainNav ul ul").hide();
	$('.mainNav > ul > li').hoverIntent(function(){
			$(this).children("ul").addClass("mouseOn");
			showActiveNavElement();
		},function(){
			$(this).children("ul").removeClass("mouseOn");
			hideInactiveNavElements();
		}
	);
}
function hideInactiveNavElements(){
	$(".mainNav ul ul.expanded:not(.mouseOn)")
		.stop().removeClass("expanded").slideUp(function(){
		  $(this).removeAttr("style").hide();
		});
}
function showActiveNavElement(){
	$(".mainNav ul ul.mouseOn").slideDown().addClass("slidingDown").addClass("expanded").slideDown(function(){
				$(this).removeClass("slidingDown");							
	});
}

//Overlay
$(document).ready(addOverlay);
function addOverlay(){
    addVirtualOverlay2();
    addPizzaOverlay2();
    addBarbecueOverlay2();

    // setup triggers 
    $(".overlayLink").each(function(i) {

        $(this).overlay({

            // common configuration for each overlay 
            oneInstance: false,
            closeOnClick: false

        });
    });
}	   
     
function addVirtualOverlay2()
		{
		    $(function() { 
                var api = $("#overlay").overlay({oneInstance: false, api:true}); 
             
                // define function that opens the overlay 
                window.openOverlay = function() { 
                    var wrap = api.getContent().find("div.wrap");
                    if (wrap.is(":empty")) 
                    { 
                        wrap.load("/virtual.html"); 
                    } 
                    api.load(); 
                } 
            });
		}

    function addPizzaOverlay2()
	{
	    $(function() { 
            var api = $("#pizzaOverlay").overlay({oneInstance: false, api:true}); 
         
            // define function that opens the overlay 
            window.openPizzaOverlay = function() { 
                var wrap = api.getContent().find("div.pizzaWrap");
                
                if (wrap.is(":empty")) 
                { 
                    wrap.load("/three_wise_men.html"); 
                } 
                api.load(); 
            } 
        });
    }

    function addBarbecueOverlay2() {
        $(function() {
        var api = $("#barbecueOverlay").overlay({ oneInstance: false, api: true });

            // define function that opens the overlay 
            window.openPizzaOverlay = function() {
            var wrap = api.getContent().find("div.BarbecueWrap");

                if (wrap.is(":empty")) {
                    wrap.load("/pizza.html");
                }
                api.load();
            }
        });
    }
    
    
    function openAllPizza(name, divName) {              
        $("a[rel]").each(function() { 
            if($(this).attr("id") == name)
            {   
                var wrap = $(this).overlay().getContent().find(divName);
                if (wrap.is(":empty")) 
                { 
                    wrap.load($(this).overlay().getTrigger().attr("href")); 
                } 
                $(this).overlay().load(); 
            }
        });
    } 

	function addVirtualOverlay()
	{
	    if($("div.wrap") != null && $("div.wrap") != undefined && $("div.wrap").length > 0)
        {
	        openAllPizza("virtualBakery", "div.wrap");
        }else
        {
            openOverlay();
        }
	}
		

    
    function addPizzaOverlay()
	{
	    if($("div.pizzaWrap") != null && $("div.pizzaWrap") != undefined && $("div.pizzaWrap").length > 0)
        {
	        openAllPizza("Pizza", "div.pizzaWrap");
		}else
		{
		    openPizzaOverlay();              
	    }
	}

	function addBarbecueOverlay() 
	{
	    if ($("div.BarbecueWrap") != null && $("div.BarbecueWrap") != undefined && $("div.BarbecueWrap").length > 0) 
	    {
	        openAllPizza("Barbecue", "div.BarbecueWrap");
	    } else 
	    {
	        openBarbecueOverlay();
	    }
	}
    
    function OpenVirtualBakery()
	{
	   addVirtualOverlay();
    }	
    function OpenPizza()
	{
	   addPizzaOverlay();
    }
    function OpenBarbecue() 
    {
        addBarbecueOverlay();
    }

    //EDM print

    documentReady("edmPrint");

    function edmPrint() 
    {
        $(".printEDM").click(function(e) {
            $.ajax({
                type: "POST",
                url: "/sportingpulse/ajaxPrintEDM.aspx",
                success: function(text) {
                }
            });
        });
    }
