﻿var ajaxPrefix = "http://www.lifestylefood.com.au/";
//var ajaxPrefix = "http://internal.idstudios.net/lifestylefood.com.au/";

//-----------------------------------------------------------------------
// Start document.ready
$(document).ready(function() {

    // Advertisements
    $('.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>');
        }

    });

    // Apply Input Field Hint/Clear
    $("input.hint, .hint input").hint();

// 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
        });

});
// End document.ready
//-----------------------------------------------------------------------



// Start Global Functions
//-----------------------------------------------------------------------

// Search Pod Tab Switch
    function SearchTab(id) {
        $('#RecipesSearchContainer').removeClass().addClass(id);
        $('.SearchArea').hide();
        $("." + id + "Area").show();
    };

// 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);
    };

// GoBlank (Method)
    function GoBlank(f,txt) {
        if (f.value == txt) {
            f.value = ''
        }
    };

// 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 });
    };

// Input Field Hint/Clear
    $.fn.hint = function(blurClass) {
        if (!blurClass) blurClass = 'blur';
        return this.each(function() {
            var $input = $(this),
            title = $input.attr('title'),
            $form = $(this.form),
            $win = $(window);

            function remove() {
                if (this.value === title && $input.hasClass(blurClass)) {
                    $input.val('').removeClass(blurClass);
                }
            }
            // only apply logic if the element has the attribute
            if (title) {
                // on blur, set value to title attr if text is blank
                $input.blur(function() {
                    if (this.value === '') {
                        $input.val(title).addClass(blurClass);
                    }
                }).focus(remove).blur(); // now change all inputs to title

                // clear the pre-defined text when form is submitted
                $form.submit(remove);
                $win.unload(remove); // handles Firefox's autocomplete
            }
        });
    };

// 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);      
        })

    };

// End Global Functions
//-----------------------------------------------------------------------


