﻿$(document).ready(function() {
	//ROLLOVERS
	$("img[rollover]").hover(swapRollovers,swapRollovers);
		
	//OTHER SITES MENU
	var os = $(".otherSitesDropdown");
	var osPosition = os.position();
	var ddl = $(".dropdown-list"); 
	var ddlHeight = ddl.height();
	$(".dropdown-list").css("top", (osPosition.top - (ddlHeight - 3)) + "px");
	
	$(".dropdown-menu").hover(
	    function() {
	        $(".dropdown-list").fadeIn(200);
	    },
	    function () {
            $(".dropdown-list").fadeOut(200);
        }
    );
    
    //Rounded Corners!
	$(".roundedCorner").corner();
	
	_myRecipeBox = new MyRecipeBox();
	
	$(".ask-popup a").hover(function() {
	    var offset = $(this).next("em").offset();
        $(this).next("em").animate({opacity: "show"}, "slow");
    }, function() {
        $(this).next("em").animate({opacity: "hide"}, "fast");
    });
	
});

//CONVERSION TAGS
function clhnpb_AddtoRecipeBox_1()
{
    $('#clhnpb_AddtoRecipeBox').html('<img height="1" width="1" src="http://view.atdmt.com/action/clhnpb_AddtoRecipeBox_1"/>');
}

function clhnpb_Printnewwebsite_1()
{
    $('#clhnpb_Printnewwebsite').html('<img height="1" width="1" src="http://view.atdmt.com/action/clhnpb_Printnewwebsite_1"/>');
}

function clhnpb_RateRecipe_1()
{
    $('#clhnpb_RateRecipe').html('<img height="1" width="1" src="http://view.atdmt.com/action/clhnpb_RateRecipe_1"/>');
}

//ROLLOVERS
function swapRollovers()
{
	var src = $(this).attr("src");
	var roSrc = $(this).attr("rollover");
	$(this).attr("src", roSrc);
	$(this).attr("rollover", src);
}

//HEADER SEARCH
function searchBtn_click(searchType)
{
	var searchTerm = $("#iSearchBoxCenter").val();
	var searchPage = '';
	switch(searchType)
	{
	    case 'entireSite':
	        searchPage = "/SearchResults.aspx#/Entire=1&Keyword=";
	        break;
	    case 'recipes':
	        searchPage = "/SearchResults.aspx#/Keyword=";
	        break;
	    case 'articles':
	        searchPage = "/SearchResultsArticles.aspx?Keyword=";
	        break;
	    case 'nutrition':
	        searchPage = "/SearchResultsNutrition.aspx?Keyword=";
	        break;
	    default:
	        searchPage = "/SearchResults.aspx#/Entire=1&Keyword=";
	        break;
	}
	document.location.href = searchPage + searchTerm;
}

//FIND RECIPES FORM
function findRecipes_click()
{
    if ($("#mealIdea").val() == "" && $("#prepTime").val() == "" && $("#cut").val() == "")
    {
        $(".shadowBoxMessage").css("visibility", "visible");
    }
    else
    {
        var queryString = "MealIdea=" + $("#mealIdea").val();
        queryString += "&PrepTime=" + $("#prepTime").val();
        queryString += "&Cut=" + $("#cut").val();
        document.location.href = "SearchResults.aspx#/" + queryString;
    }
}

function GetQueryVariable(variable)
{
    var query = window.location.search.substring(1);
    var vars = query.split('&');
    for (var i=0;i<vars.length;i++) 
    {
        var pair = vars[i].split('=');
        if (pair[0].toLowerCase() == variable.toLowerCase()) 
        {
            return pair[1];
        }
    }
    return "";
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') 
    window.onload = func;
  else 
  {
    window.onload = function() 
    {
      if (oldonload) 
        oldonload();
      func();
    }
  }
}

function lastGroup() {
    $('#RecipeGroup2').fadeOut('fast', function() {
        $('#RecipeGroup1').fadeIn('fast');
    });
}

function nextGroup() {
    $('#RecipeGroup1').fadeOut('fast', function() {
        $('#RecipeGroup2').fadeIn('fast');
    });
}

function flipDivs(hideClass, showClass, swap) {
    $('.' + hideClass).hide();
    $('.' + showClass).fadeIn('fast');
//    if (swap)
//    {
//        $(sifrSwap);
//    }
}

function hideDivHoverOut(hideClass) {
    var t = window.setTimeout(function() {
        $('.' + hideClass).hide();
    }, 200);
    $('.' + hideClass).hover(
        function() {
            window.clearTimeout(t);
        },
        function() {
            $('.' + hideClass).fadeOut('fast');
        }
     );
}

function reviewsLinkClick() {
    if ($('#SeeReviewsLink').html() == 'See Reviews')
    {
        $('#SeeReviewsLink').html('Hide Reviews');
        $('#CutInfo').hide();
        $('#Reviews').fadeIn('fast');
    }
    else
    {
        $('#SeeReviewsLink').html('See Reviews');
        $('#Reviews').hide();
        $('#CutInfo').fadeIn('fast');
    }
}

 function nextPage(fromDiv, toDiv) { 
    fromDiv = '#' + fromDiv; 
    toDiv = '#' + toDiv; 
    $(fromDiv).fadeOut('fast', function() { 
        $(toDiv).fadeIn('fast'); 
    }); 
}

function searchKeyUp(evt)
{
    // If it’s Mozilla/FF use evt; else use window.event
    evt = evt ? evt : event;

    var keyCode = evt.keyCode;

    if(keyCode == 13)
    {
        // do this if it IS the enter key
        searchBtn_click();
        return false;
    }
}

function CenterOnFocus() 
{
	if($("#iSearchBoxCenter").val() == "Search Recipes")
	{
		$("#iSearchBoxCenter").val(""); 			
	}
};
	
function CenterOnBlur() {
	if($("#iSearchBoxCenter").val() == "")
	{
		$("#iSearchBoxCenter").val("Search Recipes");
	}		
};		

function printMouseOver() {
    $("#printDropDown").show();
};

function printMouseOut() {
    $("#printDropDown").hide();
};

function searchMouseOver() {
    $("#searchBoxDropDown").show();
};

function searchMouseOut() {
    $("#searchBoxDropDown").hide();
}

function CookingMethod_onChange(x)
{
    //alert($(x).val());
    $('.cutsizetime').hide();
    $('#span' + $(x).val()).show();
}

function PorkBlogRSSRetrieve()
{
    Pork.RSS.BlogRSSRetrieve(PorkBlogRSSRetrieve_callback);   
}
function PorkBlogRSSRetrieve_callback(res)
{
    
    $('#BlogContent').html(res.value);
}

function TwitterFeedRetrieve()
{   
    Pork.PorkAjax.TwitterFeedRetrieve(TwitterFeedRetrieve_callback);
}
function TwitterFeedRetrieve_callback(res)
{
    if (res.error)
        alert(res.error.Message);
    else
    {
        $('#divTwitterFeed').html(res.value);            
    }
}

function InitializeAdvancedCategories()
{
    $('#OccasionsOptions').hide();
    $('#PopularMealTypesOptions').hide();
    $('#TypesOfDishesOptions').hide();
    $('#NutritionOptions').hide();
    $('#CookingMethodsOptions').hide();
}

function ExpandAdvancedCategory(advancedCategoryID,advancedLinkID)
{
    $('#' + advancedCategoryID).show();
    $('#' + advancedLinkID).removeClass('AdvancedLinkDown').addClass('AdvancedLinkUp');
    $("#" + advancedLinkID).attr("href", "javascript:CollapseAdvancedCategory('" + advancedCategoryID + "','" + advancedLinkID + "');");
}

function CollapseAdvancedCategory(advancedCategoryID,advancedLinkID)
{
    $('#' + advancedCategoryID).hide();
    $('#' + advancedLinkID).removeClass('AdvancedLinkUp').addClass('AdvancedLinkDown');
    $("#" + advancedLinkID).attr("href", "javascript:ExpandAdvancedCategory('" + advancedCategoryID + "','" + advancedLinkID + "');");
}