﻿/// <reference path="jquery-1.3.1-vsdoc.js" />
// Namespace declaration
var ln = {};

$(function() { ln.init(); });

(function() {
    ln = {

        /* SHARED FUNCTIONS */

        // Initialization
        init: function() {
            // Standards compliant target="_blank"
            $('a[rel="external"]').click(ln.utility.relExternal);

            // Date picker
            // v 2.3
            $('#searchMoreOptions .moreFromLabel .calendar').click(function() { $('#searchMoreOptions input#moreSearchFrom').datepicker('show'); });
            $('#searchMoreOptions .moreToLabel .calendar').click(function() { $('#searchMoreOptions input#moreSearchTo').datepicker('show'); });
            $('#searchMoreOptions input#moreSearchFrom').datepicker();
            $('#searchMoreOptions input#moreSearchTo').datepicker();
            $('#seachFind .moreFromLabel .calendar').click(function() { $('#seachFind input#moreSearchFrom1').datepicker('show'); });
            $('#seachFind .moreToLabel .calendar').click(function() { $('#seachFind input#moreSearchTo1').datepicker('show'); });
            $('#seachFind input#moreSearchFrom1').datepicker();
            $('#seachFind input#moreSearchTo1').datepicker();

            ln.utility.setDatePickerLocale($("#culture_selector #language").val())

            // Esc key functionality
            $(document).keypress(function(e) {
                if (e.keyCode == 27) $('#culture_selector,#my_live_nation').fadeOut('slow');
            });

            // Modal background
            $('#script_background').click(function() {
                $('#culture_selector,#my_live_nation,#script_background').fadeOut('slow');
                tb_remove();
            });

            // v.2.3
            ln.utility.roundedButtons();
            ln.utility.moreOptionsShowHide();

            ln.cultureSelector.init();
            ln.search.init();
            ln.utility.autocomplete();
            omniture.init();
        },

        // General functions
        utility: {
            relExternal: function() {
                window.open(this.href);
                return false;
            },
            showModalBackground: function() {
                $('#script_background').css({
                    'height': document.body.clientHeight,
                    'opacity': '0.5'
                });
                $('#script_background').fadeIn('slow');
            },
            getSite: function(siteID) {
                return $.grep(ln.sites, function(n) { return n.ID == siteID; })[0];
            },
            setDatePickerLocale: function(culture) {
                var pickerCulture = culture.split("-")[0];
                $.datepicker.setDefaults($.datepicker.regional[pickerCulture]);
            },
            // v.2.3
            // make Rounded Buttons Clickable
            roundedButtons: function() {
                $('.RoundedButtonEnding').each(function() {
                    $(this).css('cursor', 'pointer');
                    $(this).click(function() {
                        // get index in wrap of input ends
                        var index = $('.RoundedButtonEnding', $(this).parent()).index(this);
                        // get associated input, same index in wrap of inputs
                        var input = $('input.RoundedButton:eq(' + index + ')', $(this).parent());
                        input.trigger('click');

                        return false;
                    });
                });
            },

            moreOptionsShowHide: function() {
                $('#moreOptionsending').css('cursor', 'pointer');

                $('#moreOptions, #moreOptionsending, #searchMoreOptionsClose').click(function() {

                    omniture.moreOptionsOmnitureFunction(this);

                    if ($('#navWrap form').hasClass('active')) {
                        ln.utility.moreOptionsHide();
                    }
                    else {
                        ln.utility.moreOptionsShow();
                    }

                    return false;
                });

                // close more options when clicked on main search input
                $('#q').click(function() {
                    ln.utility.moreOptionsHide();
                });

                // open "more options box" if some1 used it on previous page
                if ($('#moreSearchCity').val()) {
                    ln.utility.moreOptionsShow();
                }
            },

            moreOptionsShow: function() {
                $('#navWrap form').addClass('active');
                $('#searchMoreOptions').slideDown();
            },

            moreOptionsHide: function() {
                $('#navWrap form').removeClass('active');
                //$('#searchMoreOptions').fadeOut();
                $('#searchMoreOptions').slideUp();
            },

            autocomplete: function() {
                // Autocomplete
                var searchWidth = $('#searchBar fieldset').width() - 10;
                $('#q').autocomplete('/search/autocomplete', {
                    dataType: 'json',
                    parse: function(data) {
                        var rows = new Array();
                        for (var i = 0; i < data.length; i++) {
                            rows[i] = { data: data[i], value: data[i].Name, result: data[i].Name };
                        }
                        return rows;
                    },
                    formatItem: function(item) {
                        return '<div class="type">' + item.Type + '</div>' + '<div>' + item.Name + '</div>';
                    },
                    scrollHeight: 'auto',
                    width: searchWidth + 'px',
                    selectFirst: false,
                    cacheLength: 0
                }).result(function() {
                    $.cookie("OmnitureSearchCookieProp12", $('#q').val() + " - Auto");
                    $.cookie("OmnitureSearchCookieEvar15", document.originalSerachTerm);
                    document.autocompleteCache = arguments[1];
                    location = arguments[1].Url;
                });

                $('#searchBar').submit(function() {
                    var v = $('#q').val();
                    if (document.autocompleteCache && (v == document.autocompleteCache.Name)) {
                        location = document.autocompleteCache.Url;
                        return false;
                    }
                });
            },

            popuptitle: function() {
                $('.popuptitle').each(function() {
                    // create popup
                    var link = $('a', this);
                    var popup = $('<div class="jsPopupBox"><div class="jsPopupBody">' + link.attr('title') + '</div><div class="jsPopupArrow"></div></div>');
                    popup.css({
                        display: 'none',
                        position: 'absolute',
                        zIndex: 99999,
                        width: '221px',
                        paddingBottom: '10px',
                        left: 0,
                        top: 0
                    });
                    $('.jsPopupBody', popup).css({
                        background: '#fff',
                        border: 'solid 1px #b2b2b2',
                        padding: '5px 10px',
                        fontSize: '10px',
                        lineHeight: '160%'
                    });
                    $('.jsPopupArrow', popup).css({
                        width: '21px',
                        height: '11px',
                        position: 'absolute',
                        bottom: '0px',
                        left: '100px',
                        background: 'url(http://media.livenationinternational.com/Felix1/images/v.2.3/triangle-down.png) no-repeat'
                    });
                    $(this).css({
                        position: 'relative'
                    });
                    $(link).attr('title', '');
                    $(this).append(popup);

                    // remove overflow
                    $('#content').css('overflow', 'visible');

                    $(link).mouseover(ln.utility.popupLinkMouseOver).mouseout(ln.utility.popupLinkMouseOut);
                    popup.mouseover(ln.utility.popupLinkMouseOver).mouseout(ln.utility.popupLinkMouseOut);
                });
            },
            popupLinkMouseOver: function() {
                var parent = $(this).parent().get(0);
                var popup = $('.jsPopupBox', parent);

                if (parent.hideDelayTimer)
                    clearTimeout(parent.hideDelayTimer);

                // if its acutally animating than dont animate again
                if ($('.jsPopupBox:animated', parent).size())
                    return false;

                // if its showen than dont show again
                if ($('.jsPopupBox:visible', parent).size())
                    return false;

                $(popup).css({
                    display: 'block',
                    top: -(popup.height())
                }).animate({
                    top: '-=10px',
                    opacity: 1
                }, 200);

                return false;
            },
            popupLinkMouseOut: function() {
                var parent = $(this).parent().get(0); ;
                var popup = $('.jsPopupBox', parent);

                if (parent.hideDelayTimer)
                    clearTimeout(parent.hideDelayTimer);

                var actualIndex = $('.popuptitle').index(parent);

                // hide all other popups what
                // :animated - are not actualy animating (means they are hiding)
                /*
                NOT FINISHED
                $('.popuptitle').each(function(i) {
                $(this).css('opacity', 0);
                });
                */
                parent.hideDelayTimer = setTimeout(function() {
                    popup.animate({
                        top: '-=10px',
                        opacity: 0
                    }, 200, function() {
                        popup.css('display', 'none');
                    });
                }, 300);

                return false;
            },
            SearchTableClickableLines: function() {
                // makes lines in search results tabel clickable
                $('.EventResults table tbody tr, #VenueResults table tbody tr, #ArtistResults table tbody tr, .FestivalResult table tbody tr').each(function() {
                    var link = $('a:first', this).attr('href');
                    $(this).css('cursor', 'pointer');
                    $(this).click(function() {
                        window.location = link;
                    });
                    var bg = $(this).css('background-color');
                    $(this).attr('originalGB', bg);
                    
                    $(this).hover(function() {
                        $(this).css('background', '#F4F5EF');
                    }, function() {
                        bg = $(this).attr('originalGB');
                        $(this).css('background', bg);
                    });
                });
            }
        },

        // Culture selector
        cultureSelector: {
            init: function() {
                $('#country').change(ln.cultureSelector.getCulturesForSite);
                $('.culture_selector a').click(function() {
                    tb_show('CultureSelectorPopup', '#TB_inline?height=270&width=220&inlineId=CultureSelectorPopup&modal=true', false);
                    $('#TB_window').addClass('culture_selector_overlay');
                    $('#TB_overlay').addClass('tb_transparent');
                    $('#TB_overlay').click(tb_remove)
                    return false;
                });
                $('#culture_selector .cancel').click(function() {
                    tb_remove();
                    $('#culture_selector').fadeOut('slow');
                    return false;
                });
                $('#culture_selector .submit input').click(function() {
                    var siteID = $('#country').val();
                    var site = ln.utility.getSite(siteID);
                    var culture = $('#language').val();
                    ln.cultureSelector.setOmnitureSiteChange(site.Domain);
                    var loc = 'http://' + site.Domain + '/';
                    if (site.IsActive) {
                        loc = loc + 'culture/set/' + culture + '?refferer=' + escape(window.location.pathname + window.location.search);
                        window.location = loc;
                    } else {
                        window.open(loc);
                    }
                    return false;
                });
            },
            setOmnitureSiteChange: function(domain) {
                var s = s_gi(getGurrentOmnitureAccount());
                s.tl(this, 'o', 'SiteSelectorExit:' + domain);
            },
            getCulturesForSite: function() {
                var siteID = $('#country').val();
                var site = ln.utility.getSite(siteID);
                var language = $('#language');
                language.empty();
                language.parent().hide();
                if (site.IsActive) {
                    language.parent().show();
                    $.getJSON('/Culture/GetCulturesForSite/' + siteID, function(result) {
                        if (result.length == 0) {
                            language.attr('disabled', 'disabled');
                        } else {
                            var options = '';
                            for (var i = 0; i < result.length; i++) {
                                options += '<option value="' + result[i].ID + '" ' + (result[i].ID == result[i].Default ? 'selected="selected"' : '') + '>' + result[i].Name + '</option>';
                            }

                            language.html(options);
                            language.removeAttr('disabled');
                        }
                    });
                }
            }
        },

        // Search
        search: {
            init: function() {
                /* main search input */
                var searchBox = $('#q');
                searchBox.focus(function() {
                    if (searchBox.val() == ln.strings.searchBox)
                        searchBox.val('');
                });

                searchBox.blur(function() {
                    if (searchBox.val() == '')
                        searchBox.val(ln.strings.searchBox);
                });
                searchBox.blur();

                /* updated qtip source fixed safari bug */
                var searchButton = $('#masterSearch');

                searchButton.click(function() {
                    if (searchBox.val() == '' || searchBox.val() == ln.strings.searchBox) {

                        searchBox.qtip('api').show();

                        searchBox.focus();
                        return false;
                    }
                    searchBox.val($.trim(searchBox.val()));
//                    omniture.customSearchClickOmnitureFunction();
                });

                searchBox.qtip({
                    content: $('#searchBar .help').html(),
                    show: false,
                    hide: 'blur',
                    position: {
                        corner: {
                            target: 'topLeft',
                            tooltip: 'bottomLeft'
                        }
                    },
                    style: {
                        width: 'auto',
                        color: 'white',
                        fontWeight: 'bold',
                        fontSize: '10px',
                        background: '#f00',
                        padding: '0 10px',
                        border: {
                            width: 1,
                            radius: 5,
                            color: '#f00'
                        },
                        tip: {
                            corner: 'bottomLeft'
                        }
                    }
                });


                /* more options search input */
                var searchBoxMoreOptions = $('#moreSearchCity');
                searchBoxMoreOptions.focus(function() {
                    if (searchBoxMoreOptions.val() == ln.strings.searchBoxMoreOptions)
                        searchBoxMoreOptions.val('');
                });

                searchBoxMoreOptions.blur(function() {
                    if (searchBoxMoreOptions.val() == '')
                        searchBoxMoreOptions.val(ln.strings.searchBoxMoreOptions);
                });
                searchBoxMoreOptions.blur();

                /* updated qtip source fixed safari bug */
                var searchButton = $('#moreSearchSubmit');

                searchButton.click(function() {
                    if (searchBoxMoreOptions.val() == '' || searchBoxMoreOptions.val() == ln.strings.searchBoxMoreOptions) {

                        searchBoxMoreOptions.qtip('api').show();

                        searchBoxMoreOptions.focus();
                        return false;
                    }
                    searchBoxMoreOptions.val($.trim(searchBoxMoreOptions.val()));
//                    omniture.facSearchClickOmnitureFunction();
                });

                searchBoxMoreOptions.qtip({
                    content: $('#searchMoreOptions .moreCityOrPostCodeLabel .help').html(),
                    show: false,
                    hide: 'blur',
                    position: {
                        corner: {
                            target: 'topLeft',
                            tooltip: 'bottomLeft'
                        }
                    },
                    style: {
                        width: 'auto',
                        color: 'white',
                        fontWeight: 'bold',
                        fontSize: '10px',
                        background: '#f00',
                        padding: '0 10px',
                        border: {
                            width: 1,
                            radius: 5,
                            color: '#f00'
                        },
                        tip: {
                            corner: 'bottomLeft'
                        }
                    }
                });


                /* no search results - search input */
                if ($('#moreSearchCity1').size()) {
                    var searchBoxNoResults = $('#moreSearchCity1');
                    searchBoxNoResults.focus(function() {
                        if (searchBoxNoResults.val() == ln.strings.searchBoxNoResults)
                            searchBoxNoResults.val('');
                    });

                    searchBoxNoResults.blur(function() {
                        if (searchBoxNoResults.val() == '')
                            searchBoxNoResults.val(ln.strings.searchBoxNoResults);
                    });
                    searchBoxNoResults.blur();

                    /* updated qtip source fixed safari bug */
                    var searchButton = $('#moreSearchSubmit1');

                    searchButton.click(function() {
                        if (searchBoxNoResults.val() == '' || searchBoxNoResults.val() == ln.strings.searchBoxNoResults) {

                            searchBoxNoResults.qtip('api').show();

                            searchBoxNoResults.focus();
                            return false;
                        }
                        searchBoxNoResults.val($.trim(searchBoxNoResults.val()));
                    });

                    searchBoxNoResults.qtip({
                        content: $('#seachFind .moreCityOrPostCodeLabel .help').html(),
                        show: false,
                        hide: 'blur',
                        position: {
                            corner: {
                                target: 'topLeft',
                                tooltip: 'bottomLeft'
                            }
                        },
                        style: {
                            width: 'auto',
                            color: 'white',
                            fontWeight: 'bold',
                            fontSize: '10px',
                            background: '#f00',
                            padding: '0 10px',
                            border: {
                                width: 1,
                                radius: 5,
                                color: '#f00'
                            },
                            tip: {
                                corner: 'bottomLeft'
                            }
                        }
                    });
                }

                // expand/collapse search results
                $('.resultsHeader').click(function() {
                    $(this).siblings('table').toggle();
                    $(this).siblings('.resultsFooter').toggle();
                    e = $(this).find('img');
                    if (e.attr('src').match(/clamshell_arrow.png/)) {
                        e.attr('src', e.attr('src').replace('clamshell_arrow.png', 'clamshell_arrow_down.png'));
                        e.attr('alt', e.attr('alt').replace('Click to Expand', 'Click to Collapse'));
                        e.attr('title', e.attr('title').replace('Click to Expand', 'Click to Collapse'));
                    } else {
                        e.attr('src', e.attr('src').replace('clamshell_arrow_down.png', 'clamshell_arrow.png'));
                        e.attr('alt', e.attr('alt').replace('Click to Collapse', 'Click to Expand'));
                        e.attr('title', e.attr('title').replace('Click to Collapse', 'Click to Expand'));
                    }
                });

                // remove expand/collapse box click functionality from paging
                $('.resultsHeader .paging').click(function(event) {
                    event.stopImmediatePropagation();
                });

                $('.SearchResults div td a').each(function() {
                    $(this).click(function() {
                        omniture.searchLinkOmnitureFunction(this);
                    })
                });
            }
        },


        // Search Result page
        SearchResults: {
            init: function() {
                ln.utility.SearchTableClickableLines();
            }
        },


        // Concert finder
        concertFinder: {},

        // Additional information popup
        AdditionalInformationPopUp: {
            init: function() {
                var popupStatus = 0;
                $('.TwoDSeatingLink').click(function() {
                    positionPopUp();
                    loadPopup();
                });

                function loadPopup() {
                    //loads popup only if it is disabled
                    if (popupStatus == 0) {
                        $('#backgroundPopup').css({
                            'opacity': '0.7'
                        });
                        $('#backgroundPopup').fadeIn('slow');
                        $('#VenuePopUp').fadeIn('slow');
                        popupStatus = 1;
                    }
                }

                function disablePopup() {
                    //disables popup only if it is enabled
                    if (popupStatus == 1) {
                        $('#backgroundPopup').fadeOut('slow');
                        $('#VenuePopUp').fadeOut('slow');
                        popupStatus = 0;
                    }
                }

                //centering popup
                function positionPopUp() {
                    $('#VenuePopUp').css({
                        'display': 'block',
                        'top': '155px',
                        'left': '203px',
                        'position': 'absolute'
                    });
                    $('#backgroundPopup').css({
                        'height': '100%'
                    });
                }

                $('#ClosePopup').click(function() {
                    disablePopup();
                });

                //Click out event!
                $('#backgroundPopup').click(function() {
                    disablePopup();
                });

                //Press Escape event!
                $(document).keypress(function(e) {
                    if (e.keyCode == 27 & popupStatus == 1) {
                        disablePopup();
                    }
                });
            }
        },

        // Reviews
        reviews: {
            ratingsDisplayed: function(totalReviewsCount, avgRating, ratingsOnlyReviewCount, recommendPercentage, productID) {
                if (totalReviewsCount > 0) $('#BVReviewsContainer').show();
            }
        },

        // Store
        store: {
            init: function() {
                $('#select_artists').change(function() {
                    var selectedOption = this.options[this.selectedIndex];
                    if (selectedOption.value)
                        window.open(selectedOption.value, '_blank', '');
                    return false;
                });
            }
        },

        heroPlayer: {
            autoplay: true,
            HeroPLyaerTimeout: 7000,
            actualHeroPage: 1,

            init: function() {
                // v2.3 - new hero player js
                var heroPlayer = this;

                if ($('#heroPlayerv23').size()) {
                    $('#heroPlayerv23 li:not(.active)').css({
                        display: 'block',
                        opacity: 0
                    });

                    // makes whole image clickable
                    $('#heroPlayerv23 li').css('cursor', 'pointer').click(function() {
                        document.location = $('a.buy', $(this)).attr('href');
                    });

                    if ($('#heroPlayerv23 li').size() > 1) {
                        $('#heroPlayerv23 #jsleft, #heroPlayerv23 #jsright').show();
                    }
                    $('#heroPlayerv23 #jsleft').click(function() {
                        if ($('#heroPlayerv23 li:animated').size())
                            return false;
                        //if((actualHeroPage <= 1) || ($('#heroPlayerv23 li:animated').size()))
                        if (heroPlayer.actualHeroPage <= 1) {
                            //return false;
                            heroPlayer.actualHeroPage = $('#heroPlayerv23 li').size() + 1;
                        }
                        heroPlayer.actualHeroPage--;
                        $('#heroPlayerv23 li').dequeue().stop();
                        $('#heroPlayerv23 li.active').animate({
                            opacity: 0
                        }, 500);
                        $('#heroPlayerv23 li').removeClass('active');
                        $('#heroPlayerv23 li:eq(' + (heroPlayer.actualHeroPage - 1) + ')').addClass('active');
                        $('#heroPlayerv23 li.active').animate({
                            opacity: 1
                        }, 500);
                        return false;
                    });
                    $('#heroPlayerv23 #jsright').click(function() {
                        if ($('#heroPlayerv23 li:animated').size())
                            return false;
                        if (heroPlayer.actualHeroPage >= $('#heroPlayerv23 li').size()) {
                            //return false;
                            heroPlayer.actualHeroPage = 0;
                        }
                        heroPlayer.actualHeroPage++;
                        $('#heroPlayerv23 li').dequeue().stop();
                        $('#heroPlayerv23 li.active').animate({
                            opacity: 0
                        }, 500);
                        $('#heroPlayerv23 li').removeClass('active');
                        $('#heroPlayerv23 li:eq(' + (heroPlayer.actualHeroPage - 1) + ')').addClass('active');
                        $('#heroPlayerv23 li.active').animate({
                            opacity: 1
                        }, 500);
                        return false;
                    });
                    var intervalFunction = function() { heroPlayer.heroPlayerAutoplay(); };

                    var timeOut = function() {
                        document.HeroPlayerTimer = intervalFunction;
                        setInterval(intervalFunction, heroPlayer.HeroPLyaerTimeout);
                    }

                    // if there is more than 1 item in hero player than start it
                    // start delay while all page is loaded + time for facebook component
                    if ($('#heroPlayerv23 li').size() > 1)
                        setTimeout(timeOut, 2000);

                    $('#heroPlayerv23').hover(function() {
                        if (document.HeroPlayerTimer) {
                            clearInterval(document.HeroPlayerTimer);
                            document.HeroPlayerTimer = null;
                        }
                        heroPlayer.autoplay = false;
                    }, function() {
                        if ($('#heroPlayerv23 li').size() > 1) {
                            clearInterval(document.HeroPlayerTimer);
                            document.HeroPlayerTimer = setInterval(heroPlayer.heroPlayerAutoplay, heroPlayer.HeroPLyaerTimeout);
                        }
                        heroPlayer.autoplay = true;
                    });
                }
            },

            heroPlayerAutoplay: function() {
                if (this.autoplay) {
                    $('#heroPlayerv23 li').dequeue().stop();
                    var old = this.actualHeroPage;
                    this.actualHeroPage++;
                    if (this.actualHeroPage > $('#heroPlayerv23 li').size())
                        this.actualHeroPage = 1;
                    $('#heroPlayerv23 li').removeClass('active');
                    $('#heroPlayerv23 li:eq(' + (this.actualHeroPage - 1) + ')').addClass('active');

                    $('#heroPlayerv23 li:eq(' + (old - 1) + ')').animate({
                        opacity: 0
                    }, 400);
                    $('#heroPlayerv23 li.active').animate({
                        opacity: 1
                    }, 400);
                }
            },

            initVIP: function() {
                $('#heroPlayer ul.player').cycle({
                    pager: '#heroPlayer .nav'
                });
            }
        },


        showHideNews: {
            init: function() {
                // add arrow buttons
                $('#news li:not(.seeAll)').each(function(i) {
                    $(this).append('<div class="newsOpenArrow"/>');
                });
                // apply new style
                $('#news li:not(.seeAll)').css({
                    paddingRight: '40px'
                });
                // hide body content but not first one
                $('#news li:not(.seeAll)  p:not(:first)').slideUp();
                $('#news li:not(.seeAll) .newsOpenArrow:first').addClass('active');
                // make arrows clickable
                $('#news li:not(.seeAll) .newsOpenArrow').click(function() {
                    if ($(this).hasClass('active')) {
                        $(this).removeClass('active');
                        $('p', $(this).parent()).slideUp();
                    }
                    else {
                        $(this).addClass('active');
                        $('p', $(this).parent()).slideDown();
                    }
                });
            }
        },

        /* PAGE-SPECIFIC FUNCTIONS */

        // Home
        homeLanding: {
            init: function() {
                ln.heroPlayer.init();
                ln.showHideNews.init();
                $('#featuredEvents div.fEvent2 a.img.hasVideo').click(ln.homeLanding.featuredConcertVideo);
                $('#tabs ul#tabsNav li').click(ln.homeLanding.tabHideShow);
            },
            featuredConcertVideo: function() {
                var item = $(this).closest('.fEvent2');
                var index = item.parent().children().index(item) - 1;
                var key = $(this).attr("rel");
                var title = $(this).attr("title");
                tb_show(title, '/home/featuredevents?title=test&height=260&width=300&key=' + key + '&pos=' + index, false);
                return false;
            },
            tabHideShow: function(ev) {
                var tab = $(ev.target);
                if (!tab.is('li')) tab = tab.parents('li').eq(0);
                if (!tab.hasClass('active')) {
                    var listID = tab.find('h4 a').attr('rel');
                    var list = $('.' + listID);
                    $('#tabs ul#tabsNav li').removeClass('active');
                    tab.addClass('active');
                    $('#tabs div.tabBodyBorder').hide();
                    list.fadeIn();
                }
                return false;
            }
        },


        // Artist Details
        ArtistDetail: {
            init: function() {
                ln.utility.SearchTableClickableLines();
            }
        },


        // Venue Details
        VenueDetail: {
            init: function() {
                ln.utility.SearchTableClickableLines();
            }
        },


        //Event Details
        EventDetail: {
            init: function() {
                $('.showAllArtists').click(function() {
                    $('#showArtists').html($('#artistsAtThisEvent').html());
                    tb_show("", "#TB_inline?height=500&width=300&inlineId=showArtists", false);
                    return false;
                });

                $('.ticket_link span.jq_purchase_link').hover(function() {
                    $(".ticket_link .TicketTip").text($('a', $(this)).attr("rel")).show();
                    // $('a', $(this)).attr("title", "");
                }, function() {
                    if ($(".ticket_link .TicketTip").text())
                        $('a', $(this)).attr("rel", $(".TicketTip").text());
                    $(".ticket_link .TicketTip").empty().hide();
                });

                $('.tickets:not(.special) li.ticket').hover(function() {
                    if ($('a', $(this))) {
                        $(".tickets:not(.special) .TicketTip").text($('a', $(this)).attr("rel")).show();
                        // $('a', $(this)).attr("title", "");
                    }
                }, function() {
                    if ($(".tickets:not(.special) .TicketTip").text())
                        $('a', $(this)).attr("rel", $(".TicketTip").text());
                    $(".tickets:not(.special) .TicketTip").empty().hide();
                });

                $('.tickets.special li.ticket').hover(function() {
                    if ($('a', $(this))) {
                        $(".tickets.special .TicketTip").text($('a', $(this)).attr("rel")).show();
                        // $('a', $(this)).attr("title", "");
                    }
                }, function() {
                    if ($(".tickets.special .TicketTip").text())
                        $('a', $(this)).attr("rel", $(".TicketTip").text());
                    $(".tickets.special .TicketTip").empty().hide();
                });

                ln.utility.SearchTableClickableLines();
            }
        },

        //Event All
        EventAll: {
            init: function() {
                ln.utility.SearchTableClickableLines();
            }
        },

        //Festival Details
        FestivalDetail: {
            init: function() {
                $(document).ready(ln.FestivalDetail.infoHideShow);
                $('#Additional').change(ln.FestivalDetail.infoHideShow);
                $('a[rel="external"]').click(ln.utility.relExternal);


                $('.showAllArtists').click(function() {
                    $('#showArtists').html($('#artistsAtThisEvent').html());
                    tb_show("", "#TB_inline?height=500&width=300&inlineId=showArtists", false);
                    return false;
                });

                $('.ticket_link span.jq_purchase_link').hover(function() {
                    $(".ticket_link .TicketTip").text($('a', $(this)).attr("rel")).show();
                    // $('a', $(this)).attr("title", "");
                }, function() {
                    if ($(".ticket_link .TicketTip").text())
                        $('a', $(this)).attr("rel", $(".TicketTip").text());
                    $(".ticket_link .TicketTip").empty().hide();
                });

                $('.tickets:not(.special) li.ticket').hover(function() {
                    if ($('a', $(this))) {
                        $(".tickets:not(.special) .TicketTip").text($('a', $(this)).attr("rel")).show();
                        // $('a', $(this)).attr("title", "");
                    }
                }, function() {
                    if ($(".tickets:not(.special) .TicketTip").text())
                        $('a', $(this)).attr("rel", $(".TicketTip").text());
                    $(".tickets:not(.special) .TicketTip").empty().hide();
                });

                $('.tickets.special li.ticket').hover(function() {
                    if ($('a', $(this))) {
                        $(".tickets.special .TicketTip").text($('a', $(this)).attr("rel")).show();
                        // $('a', $(this)).attr("title", "");
                    }
                }, function() {
                    if ($(".tickets.special .TicketTip").text())
                        $('a', $(this)).attr("rel", $(".TicketTip").text());
                    $(".tickets.special .TicketTip").empty().hide();
                });

                ln.utility.SearchTableClickableLines();
            },

            infoHideShow: function() {
                var listIndex = 'li#informationContent' + $('#Additional').attr('selectedIndex');
                var listContainer = $('#information_display > li');
                listContainer.hide().filter(listIndex).show();
            }
        },

        //  Additional Detail Pages
        AdditionalDetail: {
            init: function() {
                $(document).ready(ln.FestivalDetail.infoHideShow);
                $('#Additional').change(ln.FestivalDetail.infoHideShow);
                $('a[rel="external"]').click(ln.utility.relExternal);

                $('.tickets li.ticket').hover(function() {
                    $(".TicketTip").text($(this).attr("rel")).show();
                }, function() {
                    $(".TicketTip").empty().hide();
                });
            },

            infoHideShow: function() {
                var listIndex = 'li#informationContent' + $('#Additional').attr('selectedIndex');
                var listContainer = $('#information_display > li');
                listContainer.hide().filter(listIndex).show();
            }
        },

        // VIP
        vipLanding: {
            init: function() {
                ln.heroPlayer.initVIP();
                $('.tabbedEventList ul.head li').click(ln.homeLanding.tabHideShow);
            }
        },
        Nickname: {
            init: function() {
                ln.Registration.hints();
                $('#Nickname').blur(ln.Registration.checkNickname);
            }
        },
        Registration: {
            init: function() {
                ln.Registration.hints();
            },

            checkNickname: function() {
                if (($('#Nickname').val() != "") && (document.Nickname != $('#Nickname').val())) {
                    document.Nickname = $('#Nickname').val();
                    $.getJSON('/Account/NicknameExists?nickname=' + $('#Nickname').val(), function(result) {
                        if (!result.length == 0) {
                            $("#jsNickname").html("");
                            if ($("#jsNickname .nickname-exists").size() == 0) {
                                $("#jsNickname").append("<span class=\"field-validation-error\ nickname-exists\">" + result + "</span>");
                            }
                        } else {
                            $(".nickname-exists").remove();
                        }
                    });
                }
            },

            hints: function() {
                $('.toolTip').each(function(i) {
                    var p = $(this).parent();
                    if ($('input', p).size())
                        var i = $('input:first', p);
                    else if ($('select', p).size())
                        var i = $('select:last', p);
                    var width = 240;

                    // safari bug
                    if (navigator.userAgent.toLowerCase().indexOf("safari") != -1)
                        var top = '-28';
                    else
                        var top = '-12';

                    p.append('<div class="jsToolTip"><div class="jsArrow"/><div class="jsLeftTopCorner"/><div class="jsTopBorder"/><div class="jsRightTopCorner"/><div class="jsLeftBorder"/><div class="jsContent"/><div class="jsRightBorder"/><div class="jsLeftBottomCorner"/><div class="jsBottomBorder"/><div class="jsRightBottomCorner"/></div>');
                    $('.jsContent', p).html($(this).html());
                    $('.jsContent', p).css({ width: width - 13 - 13 - 10 + 'px', paddingRight: '10px', paddingBottom: '9px' });
                    var height = $('.jsContent', p).height() + 13 + 13 + 10;
                    p.css({
                        position: 'relative'
                    });


                    /*
                    IE hacks, cause bugged IE incorectly display floatted elements
                    */
                    var LeftPosition = i.position().left + i.width() + 20;

                    if (jQuery.browser.msie && $('span.label', p).size()) {
                        if ($('select', p).size() <= 1) {
                            LeftPosition = LeftPosition - $('span.label', p).width() - 20;

                            if ($('span.label', p).position().left != 0)
                                LeftPosition -= $('span.label', p).position().left;
                        }
                    }

                    $('.jsToolTip', p).css({
                        display: 'none',
                        position: 'absolute',
                        width: width + 'px',
                        Height: height + 'px',
                        top: top + 'px',
                        left: LeftPosition,
                        margin: '0', padding: '0',
                        zIndex: 99999
                    });
                    $('.jsArrow', p).css({
                        position: 'absolute',
                        width: '11px', height: '21px',
                        top: '10px', left: '-10px',
                        background: 'url(http://media.livenationinternational.com/Felix1/images/v.2.3/triangle-left.png) no-repeat',
                        fontSize: 0
                    });
                    $('.jsToolTip .jsLeftTopCorner', p).css({
                        float: 'left',
                        width: '10px', height: '12px',
                        borderTop: 'solid 1px #ccc', borderLeft: 'solid 1px #ccc',
                        background: '#fff',
                        fontSize: 0
                    });
                    $('.jsToolTip .jsTopBorder', p).css({
                        float: 'left',
                        width: width - 11 - 13 + 'px', height: '12px',
                        borderTop: 'solid 1px #ccc',
                        background: '#fff',
                        fontSize: 0
                    });
                    $('.jsToolTip .jsRightTopCorner', p).css({
                        float: 'left',
                        width: '13px', height: '13px',
                        background: 'url(http://media.livenationinternational.com/Felix1/images/v.2.3/box1_dropshadow/box1_right-top.png) no-repeat',
                        fontSize: 0
                    });
                    $('.jsToolTip .jsRightBorder', p).css({
                        float: 'left',
                        width: '13px', height: height - 13 - 13 + 'px',
                        background: 'url(http://media.livenationinternational.com/Felix1/images/v.2.3/box1_dropshadow/box1_right.png) repeat-y',
                        fontSize: 0
                    });
                    $('.jsToolTip .jsRightBottomCorner', p).css({
                        float: 'left',
                        width: '13px', height: '13px',
                        background: 'url(http://media.livenationinternational.com/Felix1/images/v.2.3/box1_dropshadow/box1_bottom-right.png) no-repeat',
                        fontSize: 0
                    });
                    $('.jsToolTip .jsBottomBorder', p).css({
                        float: 'left',
                        width: width - 13 - 13 + 'px', height: '13px',
                        background: 'url(http://media.livenationinternational.com/Felix1/images/v.2.3/box1_dropshadow/box1_bottom.png) repeat-x',
                        fontSize: 0
                    });
                    $('.jsToolTip .jsLeftBottomCorner', p).css({
                        float: 'left',
                        width: '13px', height: '13px',
                        background: 'url(http://media.livenationinternational.com/Felix1/images/v.2.3/box1_dropshadow/box1_bottom-left.png) no-repeat',
                        fontSize: 0,
                        clear: 'both'
                    });
                    $('.jsToolTip .jsLeftBorder', p).css({
                        float: 'left',
                        width: '12px', height: height - 13 - 13 + 'px',
                        borderLeft: 'solid 1px #ccc',
                        background: '#fff',
                        fontSize: 0
                    });
                    $('.jsToolTip .jsContent', p).css({
                        float: 'left',
                        background: '#fff'
                    });

                    $('input:first', p).focus(function() {
                        $('.jsToolTip', p).css('display', 'block');
                    }).blur(function() {
                        $('.jsToolTip', p).css('display', 'none');
                    });


                    $('select', p).focus(function() {
                        $('.jsToolTip', p).css('display', 'block');
                    }).blur(function() {
                        $('.jsToolTip', p).css('display', 'none');
                    });

                });
            },

            login: function() {
                ln.Registration.init();

                //$('form#registration input:first').focus();

                RegisterValue = $('#RegisterButton').text();
                SignInValue = $('#registration input.RoundedButton').val();
                ln.Registration.loginShowHidePassword();

                $('form#registration input[type=radio]').click(function() {
                    ln.Registration.loginShowHidePassword();
                });
                $('#registration #Password').click(function() {
                    return false;
                });
            },

            edit: function() {
                ln.Registration.init();
                ln.Registration.DateCheck();

                //$('form#registration input:first').focus();
            },

            stepTwo: function() {
                ln.Registration.init();

                //$('form#registration input:eq(1)').focus();
            },

            stepThree: function() {
                ln.Registration.init();
                ln.Registration.DateCheck();
                $('#Nickname').blur(ln.Registration.checkNickname);
                ln.Registration.checkNickname();
                //$('form#registration input:eq(0)').focus();
            },

            changeEmail: function() {
                ln.Registration.init();
            },

            loginShowHidePassword: function() {
                if ($('input[name=IsAccountHolder]:checked').val() == "True") {
                    $('#registration input.RoundedButton').val(SignInValue);
                    $('#registration #Password').show();
                    $('#registration .rememberMe').show();
                    $('#hidePasswordError').show();
                } else {
                    $('#registration input.RoundedButton').val(RegisterValue);
                    $('#registration #Password').hide();
                    $('#registration .rememberMe').hide();
                    $('#hidePasswordError').hide();
                }
            },

            DateCheck: function() {
                $('#Month').change(function() {
                    var y = $('#Year').val();
                    var m = $('#Month').val();
                    // disable submit
                    $('#registration .RoundedButton').attr('disabled', true);
                    $.get('/Account/GetDays?year=' + y + '&month=' + m, function(data) {
                        var o = $('#Day');
                        data = data * 1;
                        var dayvalue = o.val();
                        if (dayvalue > data * 1) {
                            dayvalue = 1;
                        }
                        ln.Registration.RegenerateDays(data);
                        o.val(dayvalue);
                        // enabled submit
                        $('#registration .RoundedButton').removeAttr('disabled');
                    });
                });
            },

            RegenerateDays: function(days) {
                var o = $('#Day');
                var selected = o.val();
                o.html('');
                for (i = 1; i <= days; i++)
                    o.append('<option value=' + i + '>' + i + '</option>');
            }
        }

    }; // End of namespace

})();

var omniture = {};

(function() {
    omniture = {

        init: function() {
            $(".jq_purchase_link a").click(function() { omniture.buyNowOmnitureFunction(this); });
            $("#faveButton").click(function() { omniture.addToFavouritesOmnitureFunction(this); });
            $("#deactivateAccount").click(function() { omniture.deactivateAccountOmnitureFunction(this); });
        },

        buyNowOmnitureFunction: function(obj) {
            try {
                var s = s_gi(getGurrentOmnitureAccount());

                s.linkTrackVars = "events,prop23";
                s.linkTrackEvents = "event2,event18";
                s.events += ",event2,event18";

                s.tl(obj, "e", "Buy Now");
            }
            catch (e) {
                //nothing... we don't want to have errors as a result of tracking.
            }
        },

        addToFavouritesOmnitureFunction: function(obj) {
            try {
                var s = s_gi(getGurrentOmnitureAccount());

                s.linkTrackVars = "eVar20";
                s.linkTrackEvents = "none";
                var eventname = "Add to Favourite - " + s.pageName;
                s.eVar20 = eventname;

                s.tl(obj, "o", eventname);
            }
            catch (e) {
                //nothing... we don't want to have errors as a result of tracking.
            }
        },

        deactivateAccountOmnitureFunction: function(obj) {
            try {
                var s = s_gi(getGurrentOmnitureAccount());

                s.linkTrackVars = "events";
                s.linkTrackEvents = "event10";
                s.events += ",event10";

                s.tl(obj, "o", s.pageName);
            }
            catch (e) {
                //nothing... we don't want to have errors as a result of tracking.
            }
        },

        moreOptionsOmnitureFunction: function(obj) {
            try {
                var s = s_gi(getGurrentOmnitureAccount());

                s.linkTrackVars = "eVar13";
                s.linkTrackEvents = "none";
                var eventname = 'moreoptions_' + s.pageName;
                s.eVar13 = eventname;

                s.tl(obj, "e", eventname);
            }
            catch (e) {
                //nothing... we don't want to have errors as a result of tracking.
            }
        },

//        autoSearchClickOmnitureFunction: function(obj) {
//            try {
//                var s = s_gi(getGurrentOmnitureAccount());

//                s.linkTrackVars = "eVar19";
//                s.linkTrackEvents = "none";
//                var eventname = "Auto - " + s.pageName;
//                s.eVar19 = eventname;

//                s.tl(obj, "o", eventname);
//            }
//            catch (e) {
//                //nothing... we don't want to have errors as a result of tracking.
//            }
//        },

//        customSearchClickOmnitureFunction: function(obj) {
//            try {
//                var s = s_gi(getGurrentOmnitureAccount());

//                s.linkTrackVars = "eVar19";
//                s.linkTrackEvents = "none";
//                var eventname = "Custom - " + s.pageName;
//                s.eVar19 = eventname;

//                s.tl(obj, "o", eventname);
//            }
//            catch (e) {
//                //nothing... we don't want to have errors as a result of tracking.
//            }
//        },

//        facSearchClickOmnitureFunction: function(obj) {
//            try {
//                var s = s_gi(getGurrentOmnitureAccount());

//                s.linkTrackVars = "eVar19";
//                s.linkTrackEvents = "none";
//                var eventname = "FaC - " + s.pageName;
//                s.eVar19 = eventname;

//                s.tl(obj, "o", eventname);
//            }
//            catch (e) {
//                //nothing... we don't want to have errors as a result of tracking.
//            }
//        },

        searchLinkOmnitureFunction: function(obj) {
            try {
                var s = s_gi(getGurrentOmnitureAccount());
                var evarValue;

                if ($(obj).attr("href").indexOf('festival') > -1)
                    evarValue = "Festival Matches";
                else if ($(obj).attr("href").indexOf('artist') > -1)
                    evarValue = "Aritst Matches";
                else if ($(obj).attr("href").indexOf('venue') > -1)
                    evarValue = "Venue Matches";
                else
                    evarValue = "Suggested Matches";

                s.linkTrackVars = "eVar16";
                s.linkTrackEvents = "none";
                s.eVar16 = evarValue;

                s.tl(obj, "o", "Buy Now");
            }
            catch (e) {
                //nothing... we don't want to have errors as a result of tracking.
            }
        },

        findConcertOmnitureFunction: function(obj) {
            try {
                var s = s_gi(getGurrentOmnitureAccount());
                s.eVar32 = "Find a concert";
                var tempeVar32 = s.getValOnce(s.eVar32, "omniture_eVar32", 0);

                if (!tempeVar32)
                    return;

                s.linkTrackVars = "eVar32";
                s.linkTrackEvents = "none";
                s.tl(obj, "o", "Find a concert");
            }
            catch (e) {
                //nothing... we don't want to have errors as a result of tracking.
            }
        }
    };
})();
