// center: function () {
//    
//            var scrollX = Dom.getDocumentScrollLeft(),
//                scrollY = Dom.getDocumentScrollTop(),
//    
//                viewPortWidth = Dom.getClientWidth(),
//                viewPortHeight = Dom.getClientHeight(),
//                elementWidth = this.element.offsetWidth,
//                elementHeight = this.element.offsetHeight,
//                x = (viewPortWidth / 2) - (elementWidth / 2) + scrollX,
//                y = (viewPortHeight / 2) - (elementHeight / 2) + scrollY;
//            
//            this.cfg.setProperty("xy", [parseInt(x, 10), parseInt(y, 10)]);
//            
//            this.cfg.refireEvent("iframe");
//    
//        },


YAHOO.namespace("SaucyPlateClient");  

YAHOO.SaucyPlateClient.RecipePreviewScripts = function()
{
    var $E = YAHOO.util.Event;
    var $D = YAHOO.util.Dom;
    var previewPanel;
    var container;
    var servicePath;
    var creatingPanel;
    var loading = false;
    
    return {
        init:function()
        {

            var recipePreview = $D.get("recipe-preview-container");
            if(recipePreview)
            {
                servicePath = "../";
                container = recipePreview;
                $E.addListener(recipePreview, 'click', YAHOO.SaucyPlateClient.RecipePreviewScripts.recipeClickHandler);
          
                creatingPanel= new YAHOO.widget.Panel("creatingPanel", { width:"170px", fixedcenter: true, modal:false, close:false, visible:false, draggable:false } );
                creatingPanel.setBody("Creating Recipe Preview <img src=\"../images/spinner.gif\"/>");
                creatingPanel.render(document.body);
            }
            
        },
        hideShowCreatePanel:function(show)
        {
            if(show)
            {
                loading = true;
                creatingPanel.show();
            }
            else
            {   
                loading = false;
                creatingPanel.hide();
            }  
        },
        getPanel:function()
        {
        
            if(!previewPanel)
            {
                previewPanel= new YAHOO.widget.Panel("previewPanel", { width:"400px", x:5, y:5, fixedcenter: false, modal:false, close:true, visible:false, draggable:false } );
                previewPanel.setBody("Preview Recipe");
                previewPanel.render(document.body);
                previewPanel.body.style.textAlign = "left";
                previewPanel.show();
            }
            else
            {
                previewPanel.setBody("");
                previewPanel.show();
            }
            return previewPanel;
        
        },
        getHeight:function(elm)
        {
            var elm = $D.get(elm);
            var h=elm.style.height;
            if(h=='auto')
            {
                elm.style.zoom=1;
                h=elm.clientHeight;
            }
            return h;
        },
        recipeClickHandler:function(e)
        {
            var elTarget = $E.getTarget(e);
            
            while (elTarget.id != container.id)
            {
                if(elTarget.nodeName.toUpperCase() == "DIV")
                {
                    if(elTarget.className == "div-recipe-preview")
                    {
                      
                      $E.preventDefault(e);
                      var recipeTest = /rp-(.+)/;
                      //var recipeTest = /Recipes\/(.+).aspx/;

                        
                        if(recipeTest.test(elTarget.id))
                        {
                            var idRegEx = recipeTest.exec(elTarget.id);
                            var recipeId = idRegEx[1];
                            YAHOO.SaucyPlateClient.RecipePreviewScripts.showPreview(recipeId);
                        }
                    }
                    break;
                }
                else
                {
                    elTarget = elTarget.parentNode;
                }
            }
            
        },
        showPreview:function(recipeId)
        {
            
             if(!loading)
             {
             YAHOO.SaucyPlateClient.RecipePreviewScripts.hideShowCreatePanel(true);
             var request = YAHOO.util.Connect.asyncRequest('GET', servicePath + "Blank.aspx?rid=" + recipeId, 
               {
			        success: function(o){
			        
			            var st = $D.getDocumentScrollTop() + 10;
			        
	                    YAHOO.SaucyPlateClient.RecipePreviewScripts.getPanel().cfg.setProperty("y", st);
	                    YAHOO.SaucyPlateClient.RecipePreviewScripts.getPanel().setBody(o.responseText);
	                    YAHOO.SaucyPlateClient.RecipePreviewScripts.hideShowCreatePanel(false);    
			        },
			        failure: function(o){
				            alert("We're sorry.  We could not create your recipe preview.  Please try again.");
				            YAHOO.SaucyPlateClient.RecipePreviewScripts.hideShowCreatePanel(false); 
			        },
			        scope: this
		        }); 
		       }
		       else
		       {
		       //alert('already loading');
		       } 
 
        }
    }
    
}();

YAHOO.util.Event.onDOMReady(YAHOO.SaucyPlateClient.RecipePreviewScripts.init);YAHOO.namespace("SaucyPlateClient");  

YAHOO.SaucyPlateClient.ShoppingListHelper = function()
{
    var $E = YAHOO.util.Event;
    var $D = YAHOO.util.Dom;
    var isRunning = false;
    var savingPanel = null;

    return {
        init:function()
        {
            Nifty("div#recipe-side-nav", "normal");
            $E.addListener('add-to-list', "click", YAHOO.SaucyPlateClient.ShoppingListHelper.AddToListHander);
            $E.addListener('add-to-my-plate', "click", YAHOO.SaucyPlateClient.ShoppingListHelper.AddToMyFavoriteHandler);
            
        },
        getPlanel:function()
        {
            if(savingPanel == null)
            {
	            savingPanel= new YAHOO.widget.Panel("savingPanel", { width:"400px", fixedcenter: true, modal:true, visible:false, draggable:false, close:false } );
	            savingPanel.setBody("<div class=\"loading-div\">Saving to Shopping List&nbsp;<img src=\"../images/spinner.gif\" alt=\"Saving to Shopping List\" /></div>");
	            savingPanel.render(document.body);
            }
            return savingPanel;
        },
        startSaving:function(message)
        {
             if(message)
             {
                YAHOO.SaucyPlateClient.ShoppingListHelper.getPlanel().setBody("<div class=\"loading-div\">" + message + "&nbsp;<img src=\"../images/spinner.gif\" alt=\"" + message + "\" /></div>");
             }
             YAHOO.SaucyPlateClient.ShoppingListHelper.getPlanel().show();
        },
        hideSpinner:function()
        {
             YAHOO.SaucyPlateClient.ShoppingListHelper.getPlanel().hide();
        },
        onSaveSuccess:function()
        {
            isRunning = false;
            setTimeout("YAHOO.SaucyPlateClient.ShoppingListHelper.hideSpinner();", 500);
        },
        AddToListHander:function(e)
        {
            if(isRunning == false)
            {
                isRunning = true;
                $E.preventDefault(e);
                YAHOO.SaucyPlateClient.ShoppingListHelper.startSaving("Saving To Shopping List");                                         
                SaucyPlate.WebServices.ShoppingListServices.AddRecipeToShoppingList($get('ctl00_mainContent_addToListControl_refId').value, $get("ctl00_mainContent_addToListControl_addToType").value, false, YAHOO.SaucyPlateClient.ShoppingListHelper.onSaveSuccess, YAHOO.SaucyPlateClient.ShoppingListHelper.onError, YAHOO.SaucyPlateClient.ShoppingListHelper.onError);
            }
        },
        AddToMyFavoriteHandler:function(e)
        {
            $E.preventDefault(e);
            YAHOO.SaucyPlateClient.ShoppingListHelper.startSaving("Saving To My Plate");                                         
            SaucyPlate.WebServices.ShoppingListServices.AddToMyPlate($get('ctl00_mainContent_addToListControl_refId').value, $get("ctl00_mainContent_addToListControl_addToType").value, YAHOO.SaucyPlateClient.ShoppingListHelper.onSaveSuccess, YAHOO.SaucyPlateClient.ShoppingListHelper.onError, YAHOO.SaucyPlateClient.ShoppingListHelper.onError);
        },
        onError:function(e)
        {
            alert("We're sorry.  An error occurred while trying to save your shopping list.  Please refresh your page and try again.");
            isRunning = false;
            YAHOO.SaucyPlateClient.ShoppingListHelper.hideSpinner();
        }
    }
}();

YAHOO.util.Event.onDOMReady(YAHOO.SaucyPlateClient.ShoppingListHelper.init);