/*
 * msc_event is an js object which contains some functions to output event data for omniture tracking.
 * second half of this script registers the mouse click events for omniture tracking.
 */
var msc_event = {
	user_id : '',
	voucher_id : '',
	category_id : '',
	account : '',
	listing_id : '',
	session_id : '',
	product_id : '',
	init : function(config){
		this.user_id = config.user_id;
		this.voucher_id = config.voucher_id;
		this.category_id = config.category_id;
		this.account = config.account;
                //session cookie id / ip address
		this.session_id = config.session_id;
                //product name
		this.product_id = config.product_id;
	},
	// listing views
        // onload, result page
	prodView : function(element){
		var s = s_gi(this.account);
		s.events = 'prodView,event1';
		s.products = ';'+this.listing_id+':'+this.category_id+';;;event1=rank';
                //alert('omni prodView event');
	},
	scOpen : function(){},scAdd : function(){},scView : function(){},scCheckout : function(){},purchase : function(){},
	// rank sum
	rank_sum : function(element){
		var s = s_gi(this.account);
		s.events = 'prodView,event1';
		s.products = ';'+this.listing_id+';;;event1=rank position;evar8=rank position,;'+this.listing_id+';;;event1=rank position;evar8 = rank position';
                //alert('omni rank_sum event');
	},
	// featured restaurants
	featured_rest : function(element, listing_id, product_id){
		listing_id = (listing_id) ? listing_id : this.listing_id;
		product_id = (product_id) ? product_id : this.product_id;
		var s = s_gi(this.account);
                //s.pageName = '';
		s.linkTrackVars = 'eVar15,eVar17,events,products';
		s.linkTrackEvents = 'event11,event2';
		s.eVar15 = listing_id;
		s.eVar17 = product_id;
		s.events = 'event2,event11:'+listing_id+'+'+this.session_id;
		s.products = ';'+listing_id;
		//s.tl(element, 'o', 'nztmenus:listing:feature');
                //alert('omni featured_rest event');
	},
	// featured vouchers
	featured_vouchers : function(element,listing_id){
                listing_id = (listing_id) ? listing_id : this.listing_id;
		var s = s_gi(this.account);
                //s.pageName = '';
		s.linkTrackVars = 'eVar15,eVar18,events,products';
		s.linkTrackEvents='event11,event3';
		s.eVar15=listing_id;
                s.eVar18=this.voucher_id;
		s.events='event3,event11:'+listing_id+'+'+this.session_id;
		s.products=';'+this.voucher_id;
		//s.tl(element, 'o','nztmenus:listing:featurevouch');
                //alert('omni featured_vouchers event');
	},
	sponsored : function(element,listing_id, product_id){
                listing_id = (listing_id) ? listing_id : this.listing_id;
                var s = s_gi(this.account);
                //s.pageName = '';
                s.linkTrackVars = 'eVar15,eVar17,events,products';
                s.linkTrackEvents = 'event4,event11';
                s.eVar15 = listing_id;
                s.eVar17 = product_id;
                s.events='event4,event11:'+listing_id+'+'+this.session_id;
                s.products=';'+listing_id;
                //s.tl(element, 'o', 'nztmenus:listing:related');
                //alert('omni sponsored event');
        },
	event5 : function(){},event6 : function(){},event7 : function(){},event8 : function(){},
        zero_results : function(){
                var s = s_gi(this.account);
                s.events='event9';
                //alert('omni zero_results event');
        },
        event10 : function(){},
	// email link is clicked
	email_link : function(element, listing_id, product_id){
		listing_id = (listing_id) ? listing_id : this.listing_id;
		product_id = (product_id) ? product_id : this.product_id;
		var s = s_gi(this.account);
                //s.pageName = '';
		s.linkTrackVars = 'eVar15,eVar17,events,products';
		s.linkTrackEvents = 'event12,event11';
		s.eVar15 = listing_id;
		s.eVar17 = product_id;
		s.events = 'event12,event11:'+listing_id+'+'+this.session_id;
		s.products = ';'+listing_id;
		//s.tl(element, 'o', 'nztmenus:listing:email');
                //alert('omni email_link event');
	},
	// website link is clicked
	website_link : function(element, listing_id, product_id){
		listing_id = (listing_id) ? listing_id : this.listing_id;
		product_id = (product_id) ? product_id : this.product_id;
		var s = s_gi(this.account);
                //s.pageName = '';
		s.linkTrackVars = 'eVar15,eVar17,events,products';
		s.linkTrackEvents = 'event11,event13';
		s.eVar15 = listing_id;
		s.eVar17 = product_id;
		s.events = 'event13,event11:'+listing_id+'+'+this.session_id;
		s.products = ';'+listing_id;
		//s.tl(element, 'o', 'nztmenus:listing:website');
                //alert('omni website_link event');
	},
        //page load
	info_page_views : function(element,listing_id,product_id){
                listing_id = (listing_id) ? listing_id : this.listing_id;
		product_id = (product_id) ? product_id : this.product_id;
                var s = s_gi(this.account);
                //s.pageName = '';
                s.eVar15 = listing_id;
                s.eVar17 = product_id;
                s.events = 'event14,event11:'+listing_id+'+'+this.session_id;
                s.products = ';'+listing_id;
                //alert('omni info_page_views event');
        },
	// phone link clicked
	phone_link : function(element, listing_id, product_id){
		listing_id = (listing_id) ? listing_id : this.listing_id;
		product_id = (product_id) ? product_id : this.product_id;
		var s = s_gi(this.account);
                //s.pageName = '';
		s.linkTrackVars = 'eVar15,eVar17,events,products';
		s.linkTrackEvents='event15,event11';
		s.eVar15=listing_id;
		s.eVar17=product_id;
		s.events='event15,event11:'+listing_id+'+'+this.session_id;
		s.products=';'+listing_id;
                //link doesn't leave the page, therefore omniture isn't automatically tracking it, enforce to track it
		s.tl(element, 'o','nztmenus:listing:phone');
                //alert('omni phone_link event');
	},
	// pdf link clicked
	menu_link : function(element, listing_id, product_id){
		listing_id = (listing_id) ? listing_id : this.listing_id;
		product_id = (product_id) ? product_id : this.product_id;
		var s = s_gi(this.account);
                //s.pageName = '';
		s.linkTrackVars = 'eVar15,eVar17,events,products';
		s.linkTrackEvents = 'event16,event11';
		s.eVar15 = listing_id;
		s.eVar17 = product_id;
		s.events = 'event16,event11:'+listing_id+'+'+this.session_id;
		s.products = ';'+listing_id;
		//s.tl(this, 'o', 'nztmenus:listing:menu');
                //alert('omni menu_link event');
	},
	// review submitted
	submit_review : function(element, listing_id, product_id){
		listing_id = (listing_id) ? listing_id : this.listing_id;
		product_id = (product_id) ? product_id : this.product_id;
		var s = s_gi(this.account);
                //s.pageName = '';
		s.linkTrackVars = 'eVar15,eVar17,events,products';
		s.linkTrackEvents='event17,event11';
		s.eVar15=listing_id;
		s.eVar17=product_id;
		s.events='event17,event11:'+listing_id+'+'+this.session_id;
		s.products=';'+listing_id;
		s.tl(element, 'o','nztmenus:listing:review');
                //alert('omni submit_review event');
	},
        coupon_click : function(element, listing_id, product_id){
                listing_id = (listing_id) ? listing_id : this.listing_id;
		product_id = (product_id) ? product_id : this.product_id;
		var s = s_gi(this.account);
                //s.pageName = '';
                s.eVar15 = listing_id;
                s.eVar17 = product_id;
                s.eVar18 = this.voucher_id;
                s.events = 'event18,event11:'+listing_id+'+'+this.session_id;
                s.products=';'+listing_id;
                //alert('omni coupon_click event');
        },
	// book link clicked
	book_link : function(element, listing_id, product_id){
		listing_id = (listing_id) ? listing_id : this.listing_id;
		product_id = (product_id) ? product_id : this.product_id;
		var s = s_gi(this.account);
                //s.pageName = '';
		s.linkTrackVars = 'eVar15,eVar17,events,products';
		s.linkTrackEvents='event19,event11';
		s.eVar15=listing_id;
		s.eVar17=product_id;
		s.events='event19,event11:'+listing_id+'+'+this.session_id;
		s.products=';'+listing_id;
		//s.tl(element, 'o','nztmenus:listing:book');
                //alert('omni book_link event');
	},
	event20 : function(element){},
	event21 : function(element){},
	event22 : function(element){}
}

/**
 * onload event to bind events to elements
 */
$(function(){

	// business interaction
	$('a.email_link, a.email').click(function(){
		msc_event.email_link(this, $(this).attr('xml:listing_id'), $(this).attr('xml:product_id'));
	});
	$('div.details > a.website_link, .details > a.url, ').click(function(){
		msc_event.website_link(this, $(this).attr('xml:listing_id'), $(this).attr('xml:product_id'));                
	});
        /*
	$('.bizname_link').click(function(){
		msc_event.info_page_views(this, $(this).attr('xml:listing_id'), $(this).attr('xml:product_id'));
	});
        */       
	$('.phone_link').click(function(){
		msc_event.phone_link(this, $(this).attr('xml:listing_id'), $(this).attr('xml:product_id'));
                return false;
	});
        
        //book now
	$('.book_link, div.details > .reservation').click(function(){
		msc_event.book_link(this, $(this).attr('xml:listing_id'),$(this).attr('xml:product_id'));
	});
        $('.coupon-text-template').click(function(){
		msc_event.coupon_click(this, $(this).attr('xml:listing_id'), $(this).attr('xml:product_id'));
	});
	// review submitted
	$('.review_submit_link').click(function(){
		msc_event.submit_review(this, $(this).attr('xml:listing_id'), $(this).attr('xml:product_id'));
	});
	// pdf menu link clicked
	$('.pdf_link, .menus .url .website_link').click(function(){
		msc_event.menu_link(this, $(this).attr('xml:listing_id'), $(this).attr('xml:product_id'));
	});
        $('#restaurant-carousel > ol > li').click(function(){
                msc_event.featured_rest(this, $(this).attr('xml:listing_id'), $(this).attr('xml:product_id'));
        });
        $('.sponsored_business_container > a').click(function(event){                
                msc_event.sponsored(this, $(this).attr('xml:listing_id'), $(this).attr('xml:product_id'));
        });
});