﻿
// Automatic sniffing of appropriate domain.
var ajaxPrefix = (document.domain == "internal.idstudios.net") ? 'http://internal.idstudios.net/lifestyle.com.au/' : "http://"+document.domain+"/";

// 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.lifestyle.com.au/e/' + videoID + '" />';
    e += '<embed src="http://www.lifestyle.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);
};

// 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 });
};

//// Reminder Tooltips
//function SetupTooltips() 
//{
//    $('.Reminder, .Record').cluetip({
//        cluetipClass: 'jtip',
//        closePosition: 'title',
//        cluezIndex: 999,
//        waitImage: false,
//        arrows: true,
//        dropShadow: false,
//        hoverIntent: false,
//        sticky: true,
//        mouseOutClose: true,
//        width: '200px',
//        leftOffset: 5,
//        attribute: 'href',
//        onShow: function() {
//            // Re-Initialise Reminder Modals
//            initReminderModals();
//        }
//    });
//};

//// Reminder Modals
//    // Any element with a class of 'ReminderModal' will launch a reminder based on its HREF
//    function initReminderModals() {
//        $(".ReminderModal").colorbox({
//            onOpen: function() { $("#colorbox").addClass("noFrame") },
//            onClosed: function() { $("#colorbox").removeClass("noFrame") },
//            width: "80%",
//            height: "100%",
//            iframe: true,
//            scrolling: false
//        });
//    };
//    
//    // Force Call Reminder (primarily for Flash)
//    function launchReminder(type, id) {
//        var modalUrl = ajaxPrefix + "modals/reminders/default.aspx?GuideID=" + id + "&Type=" + type;
//        $.fn.colorbox({
//            href: modalUrl,
//            onOpen: function() { $("#colorbox").addClass("noFrame") },
//            onClosed: function() { $("#colorbox").removeClass("noFrame") },	    
//            width: "80%",
//            height: "100%",
//            iframe: true,
//            scrolling: false
//        });
//    };

    // Ajax Video Modals(Grand Designs)
    function launchVideoPlayer(videoname, videoid) {
        var modalUrl = ajaxPrefix + "granddesigns/modals/video.aspx?VideoName=" + videoname + "&VideoID=" + videoid;
        //alert(modalUrl);
        $.fn.colorbox({
            href: modalUrl,
            onOpen: function() { $("#colorbox").addClass("noFrame") },
            onClosed: function() { $("#colorbox").removeClass("noFrame") },
            width: "700",
            height: "460",
            iframe: true,
            scrolling: false
        });

    };
// End Global Functions
//-----------------------------------------------------------------------



//-----------------------------------------------------------------------
// Start document.ready
    $(document).ready(function () {

        // 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.lifestylechannel.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.lifestylechannel.com.au/' + settings + ';ord=' + ord + '?" style="width:300px;height:250px;" frameborder="0" scrolling="no"></iframe>');
                
                  // Tower Banners
                 } else if  (settings.indexOf('125x700') > 0) {
                    $(this).html('<iframe src="http://ad.au.doubleclick.net/adi/mcn.lifestylechannel.com.au/' + settings + ';ord=' + ord + '?" style="width:125px;height:700px;" frameborder="0" scrolling="no"></iframe>');
                }

            });
        };
        $(window).load(function () { LoadAdverts() });

        // Navigation
        // Loop through first-level nav items
        $(".Nav-Menu > li").each(function () {
            // Check if list element contains a dropdown
            if ($(this).find(".Dropdown").size() > 0) {
                $(".Dropdown li:last-child").addClass("Last");

                // Show On Hover
                $(this).hover(function () {
                    $(this).addClass("Selected");
                    $(this).find(".Dropdown").css({ "visibility": "visible" });
                },
            function () {
                $(this).removeClass("Selected");
                $(this).find(".Dropdown").css({ "visibility": "hidden" })
            });
            };
        });

        // Setup Reminders Tooltips
//        SetupTooltips();

//        // Initialise Reminder Modals
//        initReminderModals();

    });
// End document.ready
//-----------------------------------------------------------------------

