﻿// Adds NoMarginRight To The Last Item In Content 2,3,4,5 Items Area.

$(document).ready(function () {
    $('.Content2 .Item:nth-child(2n)').addClass('NoMarginRight');
    $('.Content3 .Item:nth-child(3n)').addClass('NoMarginRight');
    $('.Content4 .Item:nth-child(4n)').addClass('NoMarginRight');
    $('.Content5 .Item:nth-child(5n)').addClass('NoMarginRight');
	
	// Tooltips
    // Search Pod Hint Tooltips
        $('a.QuestionMark').cluetip({
            splitTitle: '|',
            showTitle: false
        });       
    // Login to Become a Fan Tooltip
        $("a.NotLoggedIn").cluetip({
            width: 195,
            splitTitle: 'Become A Fan: ',
            activation: 'click',
            showTitle: false,
            cluetipClass: 'tools',
            dropShadow: true,
            sticky: true,
            closeText: '<span class="Accessibility">close [x]</span>',
            positionBy: 'auto',
            topOffset: '-50',
            leftOffset: '-197',
            waitImage: false
        });
    // 'Add To Cookbook' Tooltip
        $('a.AddToCookBookLink, a.FavouriteLink').click(function () {
            $(this).addClass("Loading");
        });
        $('a.AddToCookBookLink, a.FavouriteLink').cluetip({
            ajaxCache: false,
            width: 195,
            activation: 'click',
            showTitle: false,
            cluetipClass: 'add-to-cookbook',
            dropShadow: true,
            //mouseOutClose: true,
            onShow: function(ct, c) {
                $('a.FavouriteLink').removeClass('Loading')
            },
            sticky: true,
            closeText: '<span class="Accessibility">close [x]</span>',
            positionBy: 'auto',
            topOffset: '-100',
            leftOffset: '-197',
            waitImage: false
        });

        // Pseudo Select Box for Chef Search
        $(".Select select").change(function () {
            var currentItem = $(this).find("option:selected").text();
            $(this).parent().find(".SelectText").text(currentItem);
            if (currentItem == "Select a TV Show") {
                $('#ChefSearchContainer').attr("target", "");
            } else {
                $('#ChefSearchContainer').attr("target", "_blank");
            }
        });
	
 });
 // End document.ready

// GoBlank (Method)
function GoBlank(f, txt) {
    if (f.value == txt) {
        f.value = ''
    }
};

// Search Pod Tab Switch
function SearchTab(id) {
    $('#RecipesSearchContainer').removeClass().addClass(id);
    $('.SearchArea').hide();
    $("." + id + "Area").show();
};

// ADVERTISEMENTS
function LoadAdverts() {

    $('.Advertisement').each(function (i) {
        // Get Settings
        var ord = new Date().getTime();
        var settings = $(this).html().replace('<!--', '').replace('-->', '').replace(' ', '');

        // Leaderboard (Option)
        if (settings.indexOf('728x90') > 0) {
            $(this).html('<iframe src="http://ad.au.doubleclick.net/adi/mcn.lifestylefood.com.au/' + settings + ';ord=' + ord + '?" style="width:728px;height:90px;" frameborder="0" scrolling="no"></iframe>');

            // Med Rec (Option)
        } else if (settings.indexOf('300x250') > 0) {
            $(this).html('<iframe src="http://ad.au.doubleclick.net/adi/mcn.lifestylefood.com.au/' + settings + ';ord=' + ord + '?" style="width:300px;height:250px;" frameborder="0" scrolling="no"></iframe>');

            // Tower Banners
        } else if (settings.indexOf('120x600') > 0) {
            $(this).html('<iframe src="http://ad.au.doubleclick.net/adi/mcn.lifestylefood.com.au/' + settings + ';ord=' + ord + '?" style="width:120px;height:600px;" frameborder="0" scrolling="no"></iframe>');
        }
    });
};
// Video Player (Embed)
function ChookTV(videoID, w, h) {
    var e = '<div>';
    e += '<object width="'+w+'" height="'+h+'">';
    e += '<param name="allowfullscreen" value="false" /><param name="allowscriptaccess" value="always" /><param name="wmode" value="transparent" />';
    e += '<param name="movie" value="http://www.lifestylefood.com.au/e/'+videoID+'" />';
    e += '<embed src="http://www.lifestylefood.com.au/e/' + videoID + '" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" wmode="transparent" width="' + w + '" height="' + h + '"></embed></object>';
    e += '</div>';
    document.write(e);
};

$(window).load(function () { LoadAdverts() });

// Popup Window
function PopupWindow(PopupURL, PopupName, PopupWidth, PopupHeight) {
	objWindow = window.open(PopupURL, PopupName,"width="+PopupWidth+",height="+PopupHeight+",resizable=no,status=no, scrollbars=yes,location=no,menubar=no,toolbar=no");
	if (window.focus) {
		objWindow.focus();
	}
	return false;
}

var ajaxPrefix = "http://www.lifestylefood.com.au/";

// Become a Fan (Method)
function BecomeAFan(e, type, id) {
    $(e).load(ajaxPrefix + 'includes/tools/Favourite.ashx', { ContentType: type, ContentID: id });
};

// RemoveFan (Method)
function RemoveFan(id) {
    $(e).load(ajaxPrefix + 'includes/tools/Favourite.ashx', { FavouriteID: id });
};


// Save to Cookbook
function SaveToCookbook(cookbookID, name, recipeID) {

    $.post(ajaxPrefix + 'recipes/add-to-cookbook.aspx', { CookbookID: cookbookID, CookbookName: name, RecipeID: recipeID }, function (data) {
        $('#AddToCookbook').html(data);
    })

};
