﻿var $g = {
    use_swfobject: true,
    js_root: '/_common/js/',
    jquery_root: '/_common/js/jquery/',
    flash_root: '/_common/flash/',
    service_root: '/_common/service/',
    is_ie6: false
};

ExhilarationMaster = function() { };

ExhilarationMaster.prototype.v_basket_service_add_path = '/experiences/addtobasket.aspx?VariantId=';
ExhilarationMaster.prototype.v_basket_service_rem_path = '/experiences/removefrombasket.aspx?basketItemId=';
ExhilarationMaster.prototype.v_dreamlist_service_add_path = '/experiences/addtodreamlist.aspx?VariantId=';
ExhilarationMaster.prototype.v_dreamlist_service_rem_path = '/experiences/removefromdreamlist.aspx?dreamListItemId=';
ExhilarationMaster.prototype.v_variant_id = null;

ExhilarationMaster.prototype.init = function(isHomepage) {
    if ($.browser.mozilla || ($.browser.msie && $.browser.version.substring(0, 1) >= 7)) {
        $g.use_swfobject = true;
    }
    else {
        if ($.browser.msie && ($.browser.version.substring(0, 1) <= 6)) {
            $g.use_swfobject = false;
            $g.is_ie6 = true;
        }
    }
    this.setheaderFlash(isHomepage);
    this.highlightexTab();
};

ExhilarationMaster.prototype.setheaderFlash = function(isHomepage) {
    if (!$.is_ie6 && $g.use_swfobject) {
        var flashvars = {};
        var params = { "wmode": "transparent" };
        var attributes = {};
        
        if (!isHomepage)
            swfobject.embedSWF("/_common/flash/ex_title.swf", "ex_title_inner", "605px", "198px", "9.0.0", false, flashvars, params, attributes);
        else
            swfobject.embedSWF("/_common/flash/ex_title_home.swf", "ex_title_inner", "605px", "198px", "9.0.0", false, flashvars, params, attributes);
    }
    else {
        if ($g.is_ie6) {
            $('.ex_title_inner_ie6').css('display', 'block');
        }
    }
};

ExhilarationMaster.prototype.highlightexTa1b = function() {
    if ($("ul.home_tabs > li > a[href^='" + window['current_url'] + "']").length > 0) {
        $("ul.home_tabs > li > a[href^='" + window['current_url'] + "']");
    }
};

ExhilarationMaster.prototype.highlightexTab = function() {
    if (!$g.is_ie6) {
        $('#home_tabs > li > a').each(function(i, item) {
            var href = $(this).attr('href');
            if (href != window['current_url']) {
                $(this).bind('mouseover', function() {
                    $(this).css('background', 'url(/_common/img/master/tab_bg_sprite_on.gif) top right')
                        .find('span').css('background', 'url(/_common/img/master/tab_bg_sprite_on.gif)');
                });

                $(this).bind('mouseout', function() {
                    $(this).css('background', 'url(/_common/img/master/tab_bg_sprite_off.gif) top right')
                        .find('span').css('background', 'url(/_common/img/master/tab_bg_sprite_off.gif)');
                });
            }
            else {
                $(this).css('background', 'url(/_common/img/master/tab_bg_sprite_on.gif) top right')
                .addClass('selected')
                .find('span').css('background', 'url(/_common/img/master/tab_bg_sprite_on.gif)');
            }
        });
    }
};

ExhilarationMaster.prototype.setbasketVariant = function() {
    this.v_variant_id = arguments[0];
};

ExhilarationMaster.prototype.addtoBasket = function() {
    var variantId = (arguments[0] == null ? this.v_variant_id : arguments[0]),
        s = this;
    $.post(this.v_basket_service_add_path + variantId, {}, function(data) {
        s.addtoBasket_success();
    });
};

ExhilarationMaster.prototype.addtoBasket_success = function() {
    var msg = 'Experience successfully added to your basket!<br /><br />Would you like to go to your basket now or continue browsing the experiences?<br /><br />';
    $.prompt(msg, {
        buttons: { 'Continue browsing': false, 'Go to my basket': true },
        callback: function() {
            if (arguments[0] == true) {
                window.location = '/basket/';
            }
        }
    });
};

ExhilarationMaster.prototype.removefromBasket = function() {
    var basketId = arguments[0], price = arguments[1];
    var msg = 'Are you sure you want to remove this from your basket?';
    $.prompt(msg, {
        buttons: { 'Yes, remove it': true, 'No, keep it': false },
        callback: function() {
            if (arguments[0] == true) {
                master.doremovefromBasket(basketId, price);
            }
        }
    });
};

ExhilarationMaster.prototype.doremovefromBasket = function() {
    var basketId = arguments[0], price = arguments[1], rem = this.v_basket_service_rem_path + basketId;
    var obj = $('#basket_item_' + basketId);
    if (obj.length > 0) obj.fadeOut(1000, function() {
        $.post(rem, null, function(data) {
            try {
                bk.checkBasket(price);
            } catch (d) {
                alert(d);
            }
        });
    });
};

ExhilarationMaster.prototype.addtoDreamlist = function() {
    var variantId = (arguments[0]),
        s = this;
    $.post(this.v_dreamlist_service_add_path + variantId, {}, function(data) {
        s.addtoDreamlist_success();
    });
};

ExhilarationMaster.prototype.addtoDreamlist_success = function() {
    var msg = 'Experience successfully added to your dream list!<br /><br />Would you like to go to your dream list now or continue browsing the experiences?<br /><br />';
    $.prompt(msg, {
        buttons: { 'Continue browsing': false, 'Go to my dreamlist': true },
        callback: function() {
            if (arguments[0] == true) {
                window.location = '/default.aspx?mode=dreamlist';
            }
        }
    });
};

ExhilarationMaster.prototype.removefromDreamlist = function() {
    var basketId = arguments[0];
    var msg = 'Are you sure you want to remove this from your dreamlist?';
    $.prompt(msg, {
        buttons: { 'Yes, remove it': true, 'No, keep it': false },
        callback: function() {
            if (arguments[0] == true) {
                master.doremovefromDreamlist(basketId);
            }
        }
    });
};

ExhilarationMaster.prototype.doremovefromDreamlist = function() {
    var basketId = arguments[0], rem = this.v_dreamlist_service_rem_path + basketId;
    var obj = $('#dreamlist_item_' + basketId);
    if (obj.length > 0) obj.fadeOut(2000, function() {
        $.post(rem, null, function(data) {
            try {
                dl.checkdreamList();
            } catch (d) {
                alert(d);
            }
        });
    });
};


