/*
* use with jquery.js
* Analytics version : urchin.js
*/

$(document).ready(function(){
	var counter = new GoogleAnalyticsClickedImageCounter();
	counter.initialize();
});
function GoogleAnalyticsClickedImageCounter(){
	//If you want to add target banners, add that size to the following.
	var bannerSizes={
		header:{width:468,height:60},
		side:{width:150,height:50}
	};
	
	this.isTargetBanner = function(trgWidth,trgHeight){
		var sizes = bannerSizes;
		for(var i in sizes){
			var size=sizes[i];
			if(size.width==trgWidth&&size.height==trgHeight){
				return true;
			}
		}
		return false;
	}
	this.addGoogleAnalyticsEvent=function(addressStr,tag){
		$(tag).click(function(){
			urchinTracker(addressStr);
			//log(addressStr);
		});
	}
	this.getRecordAddress=function(imgTag){
		var src = $(imgTag).attr("src");
		var fileName=src.split(/[\\\/]/).pop();
		return fileName+location.pathname;
	}
	this.initialize=function(){
		var isBanner = this.isTargetBanner;
		var addEvent = this.addGoogleAnalyticsEvent;
		var getRecordAddress = this.getRecordAddress;
		$("a img").each(function(){
			var $img = $(this);
			if(isBanner($img.width(),$img.height())){
				var Atag = $img.parent()[0];
				var address = getRecordAddress(this);
				addEvent(address,Atag);
			};
		});
	}
}
function log(val){
	if(!v) v="no value";
	if(console.log) console.log(val);
}