﻿var omni = {};

$(function() {
    $('[data-omni-evar]').click(function() {
        var eVarArray = $(this).attr('data-omni-evar').split(',');
        for (var i in eVarArray) {
            var eVarKeyValuePair = eVarArray[i].split('=');
            var eVarKey = 'eVar' + eVarKeyValuePair[0];
            var eVarValue = eVarKeyValuePair[1];
            s[eVarKey] = eVarValue;

            if (s.linkTrackVars == 'None') {
                s.linkTrackVars = eVarKey;
            } else {
                s.linkTrackVars = s.linkTrackVars + ',' + eVarKey;
            }
        }
    });
    $('[data-omni-customlink]').click(function() {
        var omnitureData = $(this).attr('data-omni-customlink');
        s.tl(this, "o", omnitureData);
    });
    $('[data-omni-exitlink]').click(function() {
        var omnitureData = $(this).attr('data-omni-exitlink');
        s.tl(this, "e", omnitureData);
    });
});

//Please use the above functionality if sending simple custom/exit links or setting eVar values on click.
// example markup:
// <a href="#" data-omni-customlink="HP_L_32"/><a/>
// <a href="#" data-omni-exitlink="HP_Facebook_exit"/><a/>
// <a href="#" data-omni-evar="32=MyEvar1,30=MyEvar2"/><a/>
// <a href="#" data-omni-customlink="HP_L_32" data-omni-evar="32=MyEvar1"/><a/>

(function() {

    omni.mylnlogin = {
        refreshheader: function() {
            var s = s_gi(getGurrentOmnitureAccount());
            s.linkTrackVars = 'events';
            setEvent('event8');
            s.linkTrackEvents = 'event8';
            s.tl(this, 'o', 'Sign In');
        }
    };

    omni.artist = {
        details: function() {
            setAutoCompleteValues();
            setCollapsedEventClickHandler();
            setAddToFavouritesClickHandler();
            setBuyTicketClickHandler();
        }
    };
    omni.festival = {
        details: function() {
            setAutoCompleteValues();
            setCollapsedEventClickHandler();
            setAddToFavouritesClickHandler();
            setBuyTicketClickHandler();
        },
        // Festivals Landing
        landing: function() {
            //First Featured List
            $('#colSpan.jsOmnitureFestivals #firstFeatureList div.content div.item div.jsTicket div.price-link a.arwL').click(function() {
                var s = s_gi(getGurrentOmnitureAccount());
                var event = 'F_' + $(this).attr('title');
                s.tl(this, "o", event);
            });

            //Second Featured List
            $('#colSpan.jsOmnitureFestivals #secondFeatureList div.content div.item div.jsTicket div.price-link a.arwL').click(function() {
                var s = s_gi(getGurrentOmnitureAccount());
                var event = 'F_' + $(this).attr('title');
                s.tl(this, "o", event);
            });
        }
    };
    omni.event = {
        details: function() {
            setAutoCompleteValues();
            setCollapsedEventClickHandler();
            setAddToFavouritesClickHandler();
            setBuyTicketClickHandler();
        },
        //Concerts and Events Landing
        landing: function() {
            //First Featured List
            $('#colSpan.jsOmnitureEvents #firstFeatureList div.content div.item div.jsTicket div.price-link a.arwL').click(function() {
                var s = s_gi(getGurrentOmnitureAccount());
                var event = 'CE_' + $(this).attr('title');
                s.tl(this, "o", event);
            });

            //Second Featured List
            $('#colSpan.jsOmnitureEvents #secondFeatureList div.content div.item div.jsTicket div.price-link a.arwL').click(function() {
                var s = s_gi(getGurrentOmnitureAccount());
                var event = 'CE_' + $(this).attr('title');
                s.tl(this, "o", event);
            });
        },
        allevents: function() {
            setAdvSearchValues();
            setBuyTicketClickHandler();
        }
    };
    omni.venue = {
        details: function() {
            setAutoCompleteValues();
            setCollapsedEventClickHandler();
            setAddToFavouritesClickHandler();
            setWhereToStayClickHandler();
            setBuyTicketClickHandler();
        }
    };

    omni.home = {
        landing: function() {
            $('#topSeoNews #jsScrollNewsLinks li a').live('click', function() {
                var s = s_gi(getGurrentOmnitureAccount());
                var event = "HP_LN_" + $(this).text();
                s.tl(this, "o", event);
            });

            $('#social a').click(function() {
                var itemName = $(this).attr('title');
                var s = s_gi(getGurrentOmnitureAccount());
                var event = "HP_SN_" + itemName;
                s.tl(this, "o", event);
            });

            $('#myLnBenefits a').click(function() {
                var s = s_gi(getGurrentOmnitureAccount());
                var event = "HP_MYLN_Benefits";
                s.tl(this, "o", event);
            });


            $('a.buyWithConfidence').click(function() {
                var s = s_gi(getGurrentOmnitureAccount());
                var event = "HP_Buy with Confidence";
                s.tl(this, "o", event);
            });


        }
    };

    omni.site = {
        master: function() {
            $('div#header div.content div#menu #classicMenu a').click(function() {
                var s = s_gi(getGurrentOmnitureAccount());
                var event = 'CS_' + getSiteSection();
                s.tl(this, "o", event);
            });
            $('div#nav ul.navList li a').click(function() {
                var s = s_gi(getGurrentOmnitureAccount());
                var menuItem = '_LN | ' + $(this).text()
                var event = 'NAV_' + getSiteSection() + '_' + menuItem
                s.tl(this, "o", event);
            });
            $('div#nav ul.navList li div ul li a.arwL').click(function() {
                var s = s_gi(getGurrentOmnitureAccount());
                var navName = $(this).parent().parent().parent().parent().prev().text();
                var linkName = $(this).text();
                var event = 'NAV_' + getSiteSection() + '_' + navName + '_' + linkName
                s.tl(this, "o", event);
            });
            $('div#foot .size .box ul li a').click(function() {
                var s = s_gi(getGurrentOmnitureAccount());
                var event = 'HP_FL_' + $(this).attr('title');
                s.tl(this, "o", event);
            });

            $('#bar div.add a').click(function() {
                var s = s_gi(getGurrentOmnitureAccount());
                var event = $(this).parent().attr('id') + '_' + $(this).attr('title');
                s.tl(this, "o", event);
            });


            $('#jsLoginBox form').bind('successfulLogin', omni.mylnlogin.refreshheader);
        }
    };

    omni.expandedSeatingMap = {
        event: function() {
            $('.omni_addToFav_event').live('mouseup', function() {
                if ($('body').attr('class') == 'event' || $('body').attr('class') == 'festival' || $('body').attr('class') == 'artist') {
                    var venueName = ' - ' + $('#onmi_venue').val();
                    transmitAddToFavouritesOmniture(this, venueName);
                }
            });
            $('.omni_whereToStay_event').live('mouseup', function() {
                if ($('body').attr('class') == 'event' || $('body').attr('class') == 'artist') {
                    var venueName = $('#onmi_venue').val();
                    transmitWhereToStayOmniture(venueName);
                }
            });
        },
        venue: function() {
            $('.omni_addToFav_event').live('mouseup', function() {
                if ($('body').attr('class') == 'venue') {
                    var artistName = ' - ' + $('#omni_artist').val();
                    transmitAddToFavouritesOmniture(this, artistName);
                }
            });
            $('.omni_whereToStay_event').live('mouseup', function() {
                if ($('body').attr('class') == 'venue') {
                    var venueName = $('#onmi_venue').val();
                    transmitWhereToStayOmniture(venueName);
                }
            });
        }
    };

    omni.search = {
        results: function() {
            setCustSearchValues();
        },
        noResults: function() {
            setCustSearchValues();
        }
    };



    function transmitVipBuyTicketClick() {

        $('.callToAction').click(function() {
           
            var s = s_gi(getGurrentOmnitureAccount());
            s.tl(this, "o", "VIP_Buy");
        });
    }

    function transmitBespokeEventClick() {

        $('#ContactButton').click(function() {
            var s = s_gi(getGurrentOmnitureAccount());
            s.tl(this, 'o', "VIP_Contact Us");
        });
    }

    omni.vip = {
        bespokeEvents: function() {
            transmitBespokeEventClick();
        },
        buyTicket: function() {
            transmitVipBuyTicketClick();
        }
    };


    omni.facebook = {
        // If set on an Artist 		s.prop17=pageName
        // If set on an Event		s.prop17= pageName + Venue
        // If set on an Festival	s.prop17=pageName + Venue
        // If set on a Venue		s.prop17=pageName + Artist
        like: function(value) {
            var s = s_gi(getGurrentOmnitureAccount());
            s.linkTrackVars = 'prop17,eVar24,events';
            s.linkTrackEvents = 'event14';
            s.prop17 = s.pageName + ' | ' + value;
            s.eVar24 = s.prop17;
            setEvent('event14');
            s.tl(this, 'o', s.prop17);
        }
    };

    function setAddToFavouritesClickHandler() {
        $('.omni_addToFav').click(function() {
            transmitAddToFavouritesOmniture(this, '');
        });
    };

    function transmitAddToFavouritesOmniture(link, content) {
        var s = s_gi(getGurrentOmnitureAccount());
        s.linkTrackVars = 'eVar20';
        s.eVar20 = "Add to Favourite - " + s.pageName + content;
        var linkName = $(link).text();
        s.tl(this, 'o', linkName);
    };

    function setWhereToStayClickHandler() {
        $('.omni_whereToStay').click(function() {
            transmitWhereToStayOmniture('')
        });
    };

    function setBuyTicketClickHandler() {
        $('.buyTickets').live('click', function() {
            var s = s_gi(getGurrentOmnitureAccount());
            var ticketType = $(this).attr('title');
            s.linkTrackVars = 'eVar13,events';
            s.linkTrackEvents = 'event2,event4';
            s.eVar13 = ticketType;
            setEvent("event2")
            setEvent("event4")
            var linkName = $(this).text();
            s.tl(this, 'e', linkName);
        });
    };

    function setEvent(eventName) {
        if (s.events.indexOf(eventName) == -1) {
            if (s.events) {
                s.events = s.events + ",";
            }
            s.events = s.events + eventName;
        }
    };

    function transmitWhereToStayOmniture(content) {
        var s = s_gi(getGurrentOmnitureAccount());

        if (content == '') {
            content = s.pageName;
        }

        var event = "WTS_" + content;
        s.tl(this, "o", event);
    };

    function setCustSearchValues() {
        var query = getParameterByName("q");
        var type = "Cust";
        setCommonValues(query, type)
    }
    function setAdvSearchValues() {
        var query = getParameterByName("Filter.Location");
        var type = "Adv Search";
        setCommonValues(query, type)
    }
    function setAutoCompleteValues() {
        var query = getParameterByName("omq");
        if (query != '') {
            var result = $('#eadpVdpHead h1').html();
            var type = "Auto";
            s.eVar15 = query.length;
            s.eVar18 = query;
            setCommonValues(result, type)
        }
    }
    function setCommonValues(query, type) {
        var previousPage = $.cookie('lnpn');
        var term = query + " - " + type
        s.prop12 = term;
        s.eVar4 = term;
        s.eVar19 = type + " - " + previousPage;
        if (s.events.indexOf("event5") == -1) {
            if (s.events) {
                s.events = s.events + ",";
            }
            s.events = s.events + "event5";
        }
    }
    function getParameterByName(name) {
        name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regexS = "[\\?&]" + name + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(window.location.href);
        if (results == null)
            return "";
        else
            return decodeURIComponent(results[1].replace(/\+/g, " "));
    }
    function setCollapsedEventClickHandler() {
        $(".tbl_r").click(function() {
            var s = s_gi(getGurrentOmnitureAccount());
            var context = $('body').attr('class');

            if (context == 'venue' || context == 'festival') {
                var venueId = $('#eadpVdpHead h1').attr('id');
                var venueName = $('#eadpVdpHead h1').text();

                if (context == 'venue') {
                    s.prop7 = venueId + " | " + venueName;
                }
                else {
                    s.prop9 = venueId + " | " + venueName;
                }
            }

            var eventId = $(this).attr('id').replace('id', '');
            var eventName = $(this).find('.col3 span:eq(0)').text();
            s.prop8 = eventId + " | " + eventName;

            var artistId = $(this).find('.col3 span:eq(1)').attr('id');
            var headline = $(this).find('.col3 span:eq(1)').text().split(",");
            var artistName = headline[0];
            if (artistName == "") {
                artistName = eventName;
            }

            if (context != 'festival') {
                s.prop6 = artistId + " | " + artistName;
            }

            s.events = "event12,prodView,event3";
            s.t();
        });
    }
})();

