//Universal Tracking
$(document).ready(function() {
    var pageTitle = document.title;
    $(function() {
        //All downloads
        $('a').click(function() {
            var file = $(this).attr('href').split("/");
            var temp = file.length - 1;
            file = file[temp].split(".");
            var fileType = file[file.length - 1];
            var fileName = file[file.length - 2];

            if (fileType == 'pdf' || fileType == 'jad' || fileType == 'zip') {
                pageTracker._trackEvent('File Download: ' + fileType, 'Download', 'File name: ' + fileName + '');
                pageTracker._trackPageview('/Downloads/' + fileName + '.' + fileType);
            }
        });
        //Form Submitted
        $('form').live('submit', function() {
            var formName = $(this).attr('action');
            pageTracker._trackEvent('Form', 'Submit', 'Form Name: ' + formName + '');
        });
        //main nav
        $("#mainNav a").click(function() {
            var linkName = $(this).text();
            pageTracker._trackEvent('Main Nav', 'Click Event', 'Link: ' + linkName + '');
        });
        //customer Nav
        $("#potentialCustomerNav a").click(function() {
            var linkName = $(this).text();
            pageTracker._trackEvent('Auxilary Nav', 'Click Event', 'Auxilary Nav Link: ' + linkName + '');
        });
        $("#currentCustomerNav a").click(function() {
            var linkName = $(this).text();
            pageTracker._trackEvent('Auxilary Nav', 'Click Event', 'Auxilary Nav Link: ' + linkName + '');
        });
        //footer
        $(".siteMap a").click(function() {
            var linkName = $(this).text();
            pageTracker._trackEvent('Footer Nav', 'Click Event', 'Footer Nav Link: ' + linkName + '');
        });
        //side callouts
        $(".auxRail a").click(function() {
            var linkName = $(this).children("img").attr("alt");
            pageTracker._trackEvent('Side Ads', 'Click Event', 'Side Ad Name: ' + linkName + '');
        });

        // home page tracking
        // Main burst
        $("#mainBurstRotator a").click(function() {
            var linkName = $("img", this).attr("alt");
            pageTracker._trackEvent('Home Page: Main Burst', 'Click Event', 'Home Page : Main Burst Ad Name: ' + linkName + '');
        });
        // Acquisition Bursts
        $("#acquisitionBursts .column").click(function() {
            var linkCopy = $(this).children("h2").text();
            pageTracker._trackEvent('Home Page: Acquisition Burst', 'Click Event', 'Home Page : Acquisition Burst Heading: ' + linkCopy + '');
        });
        // Enter Lounge Link
        $(".enterLounge").click(function() {
            var linkCopy = $(this).text();
            pageTracker._trackEvent('Home Page: Enter Lounge', 'Click Event', 'Link Copy: ' + linkCopy + '');
        });

        // Installation Videos
        // accordian triggers
        $("#installVidNav .accordian a.accordianTrigger").toggle(
			function() {
			    var chapter = $(this).text();
			    pageTracker._trackEvent('How-to Videos: Accordion', 'Click Event', 'Section Open: ' + chapter + '');
			},
			function() {
			    var chapter = $(this).text();
			    pageTracker._trackEvent('How-to Videos: Accordion', 'Click Event', 'Section Closed: ' + chapter + '');
			}
			);
        // accordian links
        $("#installVidNav .accordian li div a").click(function() {
            linkLabel = $(this).text();
            pageTracker._trackEvent('How-to Videos: Accordion', 'Click Event', 'Video Link: ' + linkLabel + '');
        });
        // link list
        $(".productDescription a").click(function() {
            chapter = $(this).parent().parent().find("h3").text();
            linkLabel = $(this).text();
            pageTracker._trackEvent('How-to Videos: Full List', 'Click Event', 'Video Chapter: ' + chapter + ' Video Link: ' + linkLabel + '');
        });
		//Promotion POP and Country
		
		$('.RADcontent > a > img').live('click', function() {
			var title = $(this).attr('title');
			pageTracker._trackEvent(''+pageTitle+'', 'Click Event', 'Carousel Logo: ' + title + '');
    	});
		//Promotion  Polaris 2010
		$('.RADbottomWrapper > a > img.RADbuyNow').live('click', function() {
			pageTracker._trackEvent(''+pageTitle+'', 'Click Event', 'Enter Now Button');
    	});
    	$('.RADrectButtonWrapper > a#RADprintLink').live('click', function() {
			var title = $(this).attr('href');
			pageTracker._trackEvent(''+pageTitle+'', 'Click Event', 'Learn More linked to: ' + title + '');
    	});
		
        // Help page
        // FAQ accordian
        $(".help h3 a.accordianTrigger").toggle(
			function() {
			    label = $(this).text();
			    pageTracker._trackEvent('Help FAQ: Accordion', 'Click Event', 'Section Open: ' + label + '');
			},
			function() {
			    label = $(this).text();
			    pageTracker._trackEvent('Help FAQ: Accordion', 'Click Event', 'Section Closed: ' + label + '');
			}
			);

        // Discover Sirius
        // Steps
        $(".largeBurst").click(function() {
            dcO = $(".title", this).text();
            pageTracker._trackEvent('Discover Sirius: Steps', 'Click Event', 'Step Label:  ' + dcO + '');
        });
        // Fast Track
        $(".trackLink").click(function() {
            linkLable = $(this).text();
            pageTracker._trackEvent('Discover Sirius: Fast Track', 'Click Event', 'Fast Track Link:  ' + linkLable + '');
        });

        // Channel Guide			
        $("a.continueOn").click(function() {
            var channelGrp = $(this).parent().parent().parent().parent().find("h1").text();
            var channelName = $(this).parent().parent().find("h3").text();
            pageTracker._trackEvent('Channel Overview', 'Click Event', 'Channel Group: ' + channelGrp + ' Channel Name: ' + channelName + '');
        });
        // Product Selector
        $(".productboximg a").click(function() {
            var pn = $(this).parent().parent().find(".productboxname").text();
            pageTracker._trackEvent('Product Detail Launch Box ', 'Click Event', 'Product Name: ' + pn + '');
        });
        $(".productboxname a").click(function() {
            var pn = $(this).text();
            pageTracker._trackEvent('Product Detail Launch Box ', 'Click Event', 'Product Name: ' + pn + '');
        });
        $(".productboxbuy a").click(function() {
            var pn = $(this).parent().parent().find(".productboxname").text();
            pageTracker._trackEvent('Product Detail Launch Box - Buy Now ', 'Click Event', 'Product Name: ' + pn + '');
        });
        // Product Detail Lightbox
        // see ajax_product_detail.aspx for tracking       
        //Product List View
        $("a.productTitle").click(function() {
            var productGrp = $(this).parent().parent().parent().parent().parent().find("h2").text();
            var productName = $(this).text();
            pageTracker._trackEvent('Product List View', 'Click Event', 'Product Group: ' + productGrp + ' Product Title: ' + productName + '');
        });
        $(".learnmore a").click(function() {
            var productGrp = $(this).parent().parent().parent().parent().parent().find("h2").text();
            var productName = $(this).parent().parent().find("a.productTitle").text();
            pageTracker._trackEvent('Product List View', 'Click Event', 'Product Group: ' + productGrp + ' Product Title: ' + productName + '');
        });
        // Product Detail View
        $(".buyOptions a.buyNow").click(function() {
            var pn = $("#mainColumn h1").text();
            pageTracker._trackEvent('Product Detail - Buy Now', 'Click Event', 'Product Title: ' + pn + '');
        });
        $(".buyOptions a.findNear").click(function() {
            var pn = $("#mainColumn h1").text();
            pageTracker._trackEvent('Product Detail - Find Near', 'Click Event', 'Product Title: ' + pn + '');
        });        
        //Welcome Kit promotion
        $("a", '.welcomeKitWrapper').click(function() {
            var welcomeKitTitle = $(this).parent().prev('h3').text();
            var welcomeKitLink = $(this).attr('href');
            pageTracker._trackEvent('Welcome Kit', 'Click Event', 'Welcome Kit Group: ' + welcomeKitTitle + ' Welcome Kit Link: ' + welcomeKitLink + '');
        });
        //Father's Day 2010
        $('.previewEmail').click(function() {
            var emailValue = $('#whichEmail > input').attr("value")
            pageTracker._trackEvent("Promotions : Father's Day", "Click Event", 'Selected Email:  ' + emailValue + '');

        })
        $('.sendEmail').click(function() {
            var emailValue = $('#whichEmail > input').attr("value")
            pageTracker._trackEvent("Promotions : Father's Day", "Click Event", 'Selected Email:  ' + emailValue + '');

        })
		//Drive Better Forever Page
		$('#shoponlinenow').click(function() {

			var title = $(this).attr('href');
			pageTracker._trackEvent(''+pageTitle+'', 'Click Event', 'shop online now: ' + title + '');
		});
		$('#fullofferdetails').click(function() {

			var title = $(this).attr('href');
			pageTracker._trackEvent(''+pageTitle+'', 'Click Event', 'shop online now: ' + title + '');
			
		});
        // Auto tag all outbound links
        $("a[target='_blank']").click(function() {
            var linkURL = $(this).attr("href");
            pageTracker._trackEvent('Outbound Link', 'Click Event', 'URL: ' + linkURL + '');
            return;
        });
    });
});

// tracking functions
// Retention Bursts
function retentionTrack(rn, rt, rl)
{
	pageTracker._trackEvent('Home Page: Retention Burst','Click Event','Title: ' + rn + ' | Heading: ' + rt +' | Link: ' + rl +'');
}
function latestDealTrack(ldc)
{
	pageTracker._trackEvent('Home Page: Latest Deal','Click Event','Copy: ' + ldc +'');
}
