/*
	name			: ClassBehaviours, the javascript framework based on class-name parsing
	update			: 9.11.9
	author			: Maurice van Creij
	dependencies	: jquery.classbehaviours.js
	info			: http://www.classbehaviours.com/

    This file is part of jQuery.classBehaviours.

    ClassBehaviours is a javascript framework based on class-name parsing.
    Copyright (C) 2008  Maurice van Creij

    ClassBehaviours is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    ClassBehaviours is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with ClassBehaviours. If not, see http://www.gnu.org/licenses/gpl.html.
*/

	// create the jQuery object if it doesn't already exist
	if(typeof(jQuery)=='undefined') jQuery = function(){};

	// create the root classbehaviours object if it doesn't already exist
	if(typeof(jQuery.classBehaviours)=='undefined') jQuery.classBehaviours = function(){};

	// create the handlers child object if it doesn't already exist
	if(typeof(jQuery.classBehaviours.handlers)=='undefined') jQuery.classBehaviours.handlers = function(){}
	// implements the functionality to this classname
	jQuery.classBehaviours.handlers.googleEventTracker = {
		// properties
		name: 'googleEventTracker',
		domains: new Array('www.nederlandenergie.nl', 'www.nlenergie'),
		binaries: new Array('.pdf', 'doc.ashx'),
		// methods
		start: function(node){		   
			// set event handlers of all links
			allLinks = node.getElementsByTagName('A');
			
			for(var a=0; a<allLinks.length; a++){
				if (allLinks[a].onclick == null)
					allLinks[a].onclick = this.clicked;
			}
		},
		// events
		clicked: function(that){
			var node = (typeof(this.nodeName)=='undefined') ? that : this ;
			var got = jQuery.classBehaviours.handlers.googleEventTracker;
			// check the link for known domains
			localDomain = false;
			a = 0;
			while(!localDomain && a<got.domains.length){
				localDomain = (node.getAttribute('href').indexOf('http://')<0 || node.href.toLowerCase().indexOf(got.domains[a])>-1) ? true : localDomain ;
				a++;
			}
			// check if the link is a binary download
			binaryDownload = false;
			a = 0;
			while(!binaryDownload && a<got.binaries.length){			
				binaryDownload = (node.href.toLowerCase().indexOf(got.binaries[a])>-1) ? true : binaryDownload ;
				a++;
			}
			
			// if this link is a foreign domain
			if(!localDomain){
			   // node.innerHTML = "<b>"+node.innerHTML+"</b>";
				if(pageTracker!=null) pageTracker._trackEvent('outbound', 'link', node.href);
			}
			// else if this link is a binary download
			else if(binaryDownload){
			   // node.innerHTML = "<b>"+node.innerHTML+"</b>";
				if(pageTracker!=null) pageTracker._trackEvent('downloads', 'pdf', node.innerHTML);
			}
		}
	}

	// add this addon to the jQuery object
	if(typeof(jQuery.fn)!='undefined'){
		// extend jQuery with this method
		jQuery.fn.googleEventTracker = function(){
			return this.each(
				function(){
					jQuery.classBehaviours.handlers.googleEventTracker.start(this);
				}
			);
		};
		// set the event handler for this jQuery method
		$(document).ready(
			function(){
				$(".googleEventTracker").googleEventTracker();
			}
		);
	}
