if(typeof(s_account) == 'undefined')
{
	var host_name = window.location.hostname;
	if (host_name.indexOf('test') > 0 || host_name.indexOf('demo') > 0 || host_name == 'superpages.localhost' || host_name == 'spdev.superpages.com' || host_name == 'sptest.superpages.com')
	{
		s_account = 'superpagesdev';
	}
	else
	{
		s_account = 'superpagescom';
	}
}

function omniTrackSECoupons(tevent, category, action, lid) {
	var s=s_gi(s_account);
	if (typeof(lid) != 'undefined') {
		s.linkTrackVars='products,prop41,eVar18,events';
		s.products=lid;
	} else {
		s.linkTrackVars='eVar18,events';
	}
	s.linkTrackEvents=tevent;
	s.eVar18=category;
	if (typeof(action) != 'undefined') 
		s.prop41='SECoupon:'+action;
	s.events=tevent;
	s.tl(this,'o','Link Name');
}

function getItemClicked(click_name, event)
{
    var s=s_gi(s_account);
    var omni_page_name = document.title;
    var event_name = "";
	var clickedTitle = $(event).children('a').attr('title');

    if(typeof(T) != 'undefined')
    {
    	citystate = T + ", " + S;
    }
    else
    {
    	citystate = "General";
    }

    // To avoid "s.pageName not found" error on header link clicks, Sarayu 2/3/2011
    //s.pageName = null;	// We're only tracking clicks, not page loads.
    
    // Clear the Omniture object in case the user clicks multiple items.
	s.prop9 = null;
	s.prop40 = null;
	s.prop41 = null;
	s.prop43 = null;
	s.eVar13 = null;
	s.linkTrackEvents = null;
    s.events = null;
    s.products = null;

	switch (click_name)
	{
		case 'more_category_link':
        {
        	s.prop40="FT:PopularCats:Flyout: " + clickedTitle;
            break;
        }
		case 'more_popular_categories':
        {
        	s.prop40="FT:PopularCats";
            break;
        }
		case 'footer_category_view_all':
        {
        	s.prop40="FT:PopularCats:Flyout:ViewAll";
            break;
        }
        case 'featuredbiz_video':
        {
        	event_name = "event30";
        	s.eVar13="HP:FeaturedBiz:Video";
        	s.prop43="HP:FeaturedBiz:Video:SPHP";
            break;
        }
        case 'featuredbiz_title':
        {
        	event_name = "event30";
        	s.eVar13="HP:FeaturedBiz:Business Title";
        	s.prop43="HP:FeaturedBiz:Business Title:SPHP";
            break;
        }
        case 'featuredbiz_reviews':
        {
        	event_name = "event30";
        	s.eVar13="HP:FeaturedBiz:view reviews";
        	s.prop43="HP:FeaturedBiz:view reviews:SPHP";
            break;
        }
        case 'socialFacebook':
        {
        	event_name = "event30";
        	s.eVar13="HP:Video:Social:Facebook";
        	s.prop43="HP:Video:Social:Facebook";
            break;
        }
        case 'socialTwitter':
        {
        	event_name = "event30";
        	s.eVar13="HP:Video:Social:Twitter";
        	s.prop43="HP:Video:Social:Twitter";
            break;
        }
        case 'socialGoogle':
        {
        	event_name = "event30";
        	s.eVar13="HP:Video:Social:Google Bookmarks";
        	s.prop43="HP:Video:Social:Google Bookmarks";
            break;
        }
        case 'socialWindows':
        {
        	event_name = "event30";
        	s.eVar13="HP:Video:Social:Windows Live";
        	s.prop43="HP:Video:Social:Windows Live";
            break;
        }
        case 'socialDelicio':
        {
        	event_name = "event30";
        	s.eVar13="HP:Video:Social:Del.icio.us";
        	s.prop43="HP:Video:Social:Del.icio.us";
            break;
        }
        case 'socialDigg':
        {
        	event_name = "event30";
        	s.eVar13="HP:Video:Social:Digg";
        	s.prop43="HP:Video:Social:Digg";
            break;
        }
        case 'socialYahoo':
        {
        	event_name = "event30";
        	s.eVar13="HP:Video:Social:Yahoo Buzz";
        	s.prop43="HP:Video:Social:Yahoo Buzz";
            break;
        }
        case 'socialStumble':
        {
        	event_name = "event30";
        	s.eVar13="HP:Video:Social:Stumble Upon";
        	s.prop43="HP:Video:Social:Stumble Upon";
            break;
        }
        case 'socialReddit':
        {
        	event_name = "event30";
        	s.eVar13="HP:Video:Social:Reddit";
        	s.prop43="HP:Video:Social:Reddit";
            break;
        }
        case 'mobile':
        {
        	event_name = "event30";
        	s.eVar13="HP:Mobile:Get it now";
        	s.prop43="HP:Mobile:Get it now";
            break;
        }
        case 'facebook':
        {
        	event_name = "event30";
        	s.eVar13="HP:FB:Join Us";
        	s.prop43="HP:FB:Join Us";
            break;
        }
        case 'twitter':
        {
        	event_name = "event30";
        	s.eVar13="HP:Twitter:Follow";
        	s.prop43="HP:Twitter:Follow:";
            break;
        }
        case 'superguarantee':
        {
        	event_name = "event30";
        	s.eVar13="HP:CSG:Get It Now";
        	s.prop43="HP:CSG:Get It Now";
            break;
        }
        case 'find_deals':
        {
        	event_name = "event30";
        	s.eVar13="HP:HP Coupon:Find Deals";
        	s.prop43="HP:Find Deals";
            break;
        }
        case 'coupons':
        {
        	event_name = "event30";
        	s.eVar13="HP:HP Coupons tab";
        	s.prop43="HP:HP Coupons tab:SPHP";
            break;
        }
        case 'coupons_title':
        {
        	event_name = "event30";
        	s.eVar13="HP:HP Coupon:Business Title";
        	s.prop43="HP:HP Coupon:Business Title";
        	s.products = "" + $(event).attr("lid");
            break;
        }
        case 'coupons_view':
        {
        	event_name = "event30";
        	s.eVar13="HP:HP Coupon:view coupon";
        	s.prop43="HP:HP Coupon:view coupon";
        	s.products = "" + $(event).attr("lid");
            break;
        }
        case 'coupons_more':
        {
        	event_name = "event30";
        	s.eVar13="HP:HP Coupon:more coupons";
        	s.prop43="HP:HP Coupon:more coupons";
            break;
        }
        case 'map_larger':
        {
        	event_name = "event30";
        	s.eVar13="HP:HP Coupon:View Larger Map";
        	s.prop43="HP:HP Coupon:View Larger Map";
            break;
        }
        case 'weather_find':
        {
        	event_name = "event30";
        	s.eVar13="HP:Weather:Find";
        	s.prop43="HP:Weather:Find";
            break;
        }
        case 'category_air_conditioning':
        {
        	event_name = "event30";
        	s.eVar13="HP:Popular Searches:Air Conditioning";
        	s.prop43="HP:Popular Searches:Air Conditioning";
            break;
        }
        case 'category_air_duct_cleaning':
        {
        	event_name = "event30";
        	s.eVar13="HP:Popular Searches:Air Duct Cleaning";
        	s.prop43="HP:Popular Searches:Air Duct Cleaning";
            break;
        }
        case 'category_bathroom_remodeling':
        {
        	event_name = "event30";
        	s.eVar13="HP:Popular Searches:Bathroom Remodeling";
        	s.prop43="HP:Popular Searches:Bathroom Remodeling";
            break;
        }
        case 'category_cleaning_services':
        {
        	event_name = "event30";
        	s.eVar13="HP:Popular Searches:Cleaning Services";
        	s.prop43="HP:Popular Searches:Cleaning Services";
            break;
        }
        case 'category_gardeners':
        {
        	event_name = "event30";
        	s.eVar13="HP:Popular Searches:Gardeners";
        	s.prop43="HP:Popular Searches:Gardeners";
            break;
        }
        case 'category_home_improvement':
        {
        	event_name = "event30";
        	s.eVar13="HP:Popular Searches:Home Improvement";
        	s.prop43="HP:Popular Searches:Home Improvement";
            break;
        }
        case 'category_janitorial_services':
        {
        	event_name = "event30";
        	s.eVar13="HP:Popular Searches:Janitorial Services";
        	s.prop43="HP:Popular Searches:Janitorial Services";
            break;
        }
        case 'category_kitchen_contractors':
        {
        	event_name = "event30";
        	s.eVar13="HP:Popular Searches:Kitchen Contractors";
        	s.prop43="HP:Popular Searches:Kitchen Contractors";
            break;
        }
        case 'category_landscaping':
        {
        	event_name = "event30";
        	s.eVar13="HP:Popular Searches:Landscaping";
        	s.prop43="HP:Popular Searches:Landscaping";
            break;
        }
        case 'category_lawn_mowing_services':
        {
        	event_name = "event30";
        	s.eVar13="HP:Popular Searches:Lawn Mowing Services";
        	s.prop43="HP:Popular Searches:Lawn Mowing Services";
            break;
        }
        case 'category_remodeling':
        {
        	event_name = "event30";
        	s.eVar13="HP:Popular Searches:Remodeling";
        	s.prop43="HP:Popular Searches:Remodeling";
            break;
        }
        case 'category_termite_control':
        {
        	event_name = "event30";
        	s.eVar13="HP:Popular Searches:Termite Control";
        	s.prop43="HP:Popular Searches:Termite Control";
            break;
        }
        case 'category_tree_trimming':
        {
        	event_name = "event30";
        	s.eVar13="HP:Popular Searches:Tree Trimming";
        	s.prop43="HP:Popular Searches:Tree Trimming";
            break;
        }
        case 'category_apartments':
        {
        	event_name = "event30";
        	s.eVar13="HP:Popular Searches:Apartments";
        	s.prop43="HP:Popular Searches:Apartments";
            break;
        }
        case 'category_attorneys':
        {
        	event_name = "event30";
        	s.eVar13="HP:Popular Searches:Attorneys";
        	s.prop43="HP:Popular Searches:Attorneys";
            break;
        }
        case 'category_auto_repair':
        {
        	event_name = "event30";
        	s.eVar13="HP:Popular Searches:Auto Repair";
        	s.prop43="HP:Popular Searches:Auto Repair";
            break;
        }
        case 'category_banks':
        {
        	event_name = "event30";
        	s.eVar13="HP:Popular Searches:Banks";
        	s.prop43="HP:Popular Searches:Banks";
            break;
        }
        case 'category_car_rental':
        {
        	event_name = "event30";
        	s.eVar13="HP:Popular Searches:Car Rental";
        	s.prop43="HP:Popular Searches:Car Rental";
            break;
        }
        case 'category_churches':
        {
        	event_name = "event30";
        	s.eVar13="HP:Popular Searches:Churches";
        	s.prop43="HP:Popular Searches:Churches";
            break;
        }
        case 'category_doctors':
        {
        	event_name = "event30";
        	s.eVar13="HP:Popular Searches:Doctors";
        	s.prop43="HP:Popular Searches:Doctors";
            break;
        }
        case 'category_golf_courses':
        {
        	event_name = "event30";
        	s.eVar13="HP:Popular Searches:Golf Courses";
        	s.prop43="HP:Popular Searches:Golf Courses";
            break;
        }
        case 'category_hotels':
        {
        	event_name = "event30";
        	s.eVar13="HP:Popular Searches:Hotels";
        	s.prop43="HP:Popular Searches:Hotels";
            break;
        }
        case 'category_insurance':
        {
        	event_name = "event30";
        	s.eVar13="HP:Popular Searches:Insurance";
        	s.prop43="HP:Popular Searches:Insurance";
            break;
        }
        case 'category_movie_theaters':
        {
        	event_name = "event30";
        	s.eVar13="HP:Popular Searches:Movie Theaters";
        	s.prop43="HP:Popular Searches:Movie Theaters";
            break;
        }
        case 'category_restaurants':
        {
        	event_name = "event30";
        	s.eVar13="HP:Popular Searches:Restaurants";
        	s.prop43="HP:Popular Searches:Restaurants";
            break;
        }
        case 'category_schools':
        {
        	event_name = "event30";
        	s.eVar13="HP:Popular Searches:Schools";
        	s.prop43="HP:Popular Searches:Schools";
            break;
        }
    }
     
    s.linkTrackVars='prop4,prop5,prop6,prop7,prop9,prop40,prop41,prop43,eVar4,eVar13,products';
    
    if(event_name != "")
    {
    	s.linkTrackVars += ',events';
    	s.linkTrackEvents = event_name;
        s.events = event_name;
    }
    
    s.eVar4=omni_page_name;
    s.tl(this,'o', click_name);
}

var oldValue = "";

function getItemChanged(event_name,selectedValue) {

    var s=s_gi(s_account);
    var omni_page_name = document.title;

    // See if this is the first click of the dropdown we need to ignore.
    if(oldValue == "")
    {
    	oldValue = selectedValue;
    }
    
    if(selectedValue == oldValue)
    {
    	return;
    }

    // Keep track of this change for next time.
    oldValue = selectedValue;
    
    if(typeof(T) != 'undefined')
    {
    	citystate = T + ", " + S;
    }
    else
    {
    	citystate = "General";
    }

    // To avoid "s.pageName not found" error on header link clicks, Sarayu 2/3/2011
	//s.pageName = null;	// We're only tracking clicks, not page loads.
    
   
    // Clear the Omniture object in case the user clicks multiple items.
	s.prop9 = null;
	s.prop40 = null;
	s.prop41 = null;
	s.prop43 = null;
	s.eVar13 = null;
	s.linkTrackEvents = null;
    s.events = null;
    s.products = null;
    
    switch (event_name){
        case 'coupon_category':
        {
        	event_name = "event30";
                s.eVar13="HP:Coupons:Popular Category";
                s.prop43="HP:Coupons:Popular category";
                s.prop9="HP:Coupons:"+selectedValue;
           break;
        }
    }

    s.linkTrackVars='prop4,prop5,prop6,prop7,prop9,prop40,prop41,prop43,eVar4,eVar13,events';
    s.linkTrackEvents="event30";
    s.eVar4=omni_page_name;
    s.events="event30";
    s.tl(this,'o', event_name);
}

$(document).ready(function()
{
	// Normal Omniture tracking.
    $('[class*="ot_"]').live('click',function()
    {
    	var classList = this.className.split(/\s+/);
    	
    	for (i = 0; i < classList.length; i++)
    	{
    	   if(classList[i].substr(0, 3) == "ot_")
    	   {
    	        getItemClicked(classList[i].substr(3), this);
    	   }
    	}
	});

    //Tracking changed category
    $('.ot_change').live('click',function()
    {
    	var selectedValue = $("select option:selected").html();
	    getItemChanged('coupon_category',selectedValue);
    });

    // Track Featured Business video sharing.
    $('.videoSocialLeft div').live('click',function()
    {
    	var event_name = $(this).attr("class");
	    getItemClicked(event_name, this);
    });
});

