// Script setting up functionality tracking.

jQuery(document).ready(function(){ 
    
	// Exit click tracking
	jQuery('a').filter(function() { 
		return this.hostname && this.hostname !== location.hostname && this.href.indexOf('http') == 0;
	}).click(function() {
		pageTracker._trackEvent('Exit click', window.location.pathname, jQuery(this).attr('href'));
	});
	
	// Toolbar tracking
	jQuery('div[id=c_globalmenu] a').click(function() {
        pageTracker._trackEvent('Toolbar', jQuery(this).attr('href')); 
    });
    
	// Select country dropdown tracking
    jQuery('div[id*=_SiteSelector_divSiteList]').children('a').click(function() {
        pageTracker._trackEvent('Country', jQuery(this).attr('title')); 
    });
    
	// Change font size function tracking
    jQuery('div.c_footerfontlinks').children('a').click(function() {
        pageTracker._trackEvent('Function', 'Font', jQuery(this).attr('title')); 
    });
    
	// Print function tracking
    if (jQuery('a[id*=_hlPrint]').length) { 
        jQuery('a[id*=_hlPrint]').click(function() { 
            if(jQuery(this).attr('id').indexOf('ctrActionList') != -1)
            {
                pageTracker._trackEvent('Function', 'Print', 'Article');
            }
            else
            {
                pageTracker._trackEvent('Function', 'Print', 'Product');
            }            
        });
    }
    
	// Send to a friend tracking
    if (jQuery('a[id*=_lbuSendMailToFriend]').length) { 
        jQuery('a[id*=_lbuSendMailToFriend]').click(function() { 
            if(jQuery(this).attr('id').indexOf('ctrActionList') != -1)
            {
                pageTracker._trackEvent('Function', 'Send to friend', 'Article');
            }
            else
            {
                pageTracker._trackEvent('Function', 'Send to friend', 'Product');
            } 
        });
    }
    
	// Social bookmark tracking
    if (jQuery('a[id*=_lbSocialBookmarker]').length) { 
        jQuery('a[id*=_lbSocialBookmarker]').click(function() { 
            if(jQuery(this).attr('id').indexOf('ctrActionList') != -1)
            {
                pageTracker._trackEvent('Function', 'Social Bookmark', 'Open/Close Article');
            }
            else
            {
                pageTracker._trackEvent('Function', 'Social Bookmark', 'Open/Close Product');
            } 
        });
    }
    	
    jQuery('ul.socialbookmarks').children('li').children('a').click(function() {
        pageTracker._trackEvent('Function', 'Social Bookmark', jQuery(this).attr('title')); 
    });
    
    if (jQuery('a[id*=_ctrSlideDownPanel_lbClose]').length) { 
        jQuery('a[id*=_ctrSlideDownPanel_lbClose]').click(function() { 
            if(jQuery(this).attr('id').indexOf('ctrActionList') != -1)
            {
                pageTracker._trackEvent('Function', 'Social Bookmark', 'Close Article');
            }
            else
            {
                pageTracker._trackEvent('Function', 'Social Bookmark', 'Close Product');
            } 
        });
    }
    
	// Small map tracking
	if (jQuery('div.c_mapsmall').length) {
		var smallmap_pagetype = 'Product';
		
		if (jQuery('a[id*=_ctrMapSmall_linkMap]').length) {
			smallmap_pagetype = 'Article';
		}
		
		if (jQuery('a[id*=_linkOpenForecast]').length) { 
			smallmap_weather = 'yes';
			jQuery('a[id*=_linkOpenForecast]').click(function() { 
				pageTracker._trackEvent('Function', 'Small Map', 'Weather link ' + smallmap_pagetype );
			});
		}
		
		if (jQuery('a[id*=_hlWeatherSymbol]').length) { 
			smallmap_weather = 'yes';
			jQuery('a[id*=_hlWeatherSymbol]').click(function() {
				pageTracker._trackEvent('Function', 'Small Map', 'Weather icon ' + smallmap_pagetype);
			});
		}
		
		if (jQuery('a[id*=_linkOpenSnowReport]').length) { 
			smallmap_snow = 'yes';
			jQuery('a[id*=_linkOpenSnowReport]').click(function() { 
				pageTracker._trackEvent('Function', 'Small Map', 'Snow report ' + smallmap_pagetype);
			});
		}
		
		if (jQuery('a[id*=_linkMap]').length) { 
			jQuery('a[id*=_linkMap]').click(function() { 
				pageTracker._trackEvent('Function', 'Small Map', 'Map image ' + smallmap_pagetype);
			});
		}
		
		if (jQuery('a[id*=_btnMapLink_linkBlueArrowButton]').length) { 
			jQuery('a[id*=_btnMapLink_linkBlueArrowButton]').click(function() { 
				pageTracker._trackEvent('Function', 'Small Map', 'Map button ' + smallmap_pagetype);
			});
		}
	}
    
	// Slideshow page function tracking
    if (jQuery('a[id*=slideshowbuttonlink]').length) { 
        jQuery('a[id*=slideshowbuttonlink]').click(function() { 
            pageTracker._trackEvent('Function', 'Slideshow', 'Play/Stop');
        });
    }
    
	if (jQuery('div.slidecontrols2').length) { 
		jQuery('div.slidecontrols2').children('a').click(function() {
			pageTracker._trackEvent('Function', 'Slideshow', jQuery(this).attr('title'));
		});
	}
	
	// Article open/close function tracking
	if (jQuery('a.collapsearticle').length) {
		jQuery('a.collapsearticle').click(function() {
			if(jQuery('#collapsearticleopen').is(':visible'))
			{
				pageTracker._trackEvent('Function', 'Open/close article', 'Close');
			}
			else
			{
				pageTracker._trackEvent('Function', 'Open/close article', 'Open');
			}
		});
	}
	
	// Newsletter tracking
	if (jQuery('input[id*=_btnNewsletterSubscribe]').length) { 
			jQuery('input[id*=_btnNewsletterSubscribe]').click(function() { 
            var newsletter_name = 'Empty';
			var newsletter_email = 'Empty';
			
			if (jQuery('input[id*=_NewsletterName]').val().length) {
				newsletter_name = 'OK';
			}
			
			if (jQuery('input[id*=_NewsletterEmai]').val().length) {
				newsletter_email = 'OK';
			}
			
			if(jQuery(this).attr('id').indexOf('_newsletter_') != -1)
			{
				pageTracker._trackEvent('Newsletter', 'Footer', newsletter_name + '/' + newsletter_email);
			}
			else
			{
				pageTracker._trackEvent('Newsletter', 'Page', newsletter_name + '/' + newsletter_email);
			}
        });
    }

	// Directory control tracking
	if (jQuery('div.c_directorycontrol').length) {
		if (jQuery('div.c_directoryareas').length) {
			jQuery('div.c_directoryareas a').click(function() {
				pageTracker._trackEvent('DirectoryControl', 'Area', jQuery(this).text());
			});	
		}
		
		if (jQuery('div.c_directoryinterests').length) {
			jQuery('div.c_directoryinterests a').click(function() {
				pageTracker._trackEvent('DirectoryControl', 'Interest', jQuery(this).text());
			});	
		}
		
		jQuery('span.c_directory_tab').click(function() {
			pageTracker._trackEvent('DirectoryControl', 'Click', jQuery(this).children('span:last').attr('title'));
		});
		
		jQuery('div.c_directory_listings a').click(function() {
			pageTracker._trackEvent('DirectoryControl', 'Click', jQuery(this).attr('title'));
		});		
	}
});
