/*! ADServe v1 <http://nvinteractive.co.nz>
	Copyright (c) NV Interactive
	
	References:
		jquery-1.2.6.js
		
	Release Notes:

		
*/

/* [ Ad declarations ] */
/* Only one replace will occur per page, order is important. */

var ads = new Array(

				
{
	id: "KFC1902-234x60",
	includeUrl: "summary.aspx",
	selectors: [ "#brandingidentifier[content='internationalhome'], #brandingidentifier[content='internationalaway']", "#matchType:contains('Twenty20')"],
	html: '<div class="summary-halfbanner adserve"><a href="http://www.kfc.co.nz/" target="_blank"><img src="http://www.blackcaps.co.nz/adserve/media/KFC1902-234x60.jpg" width="234" height="60" alt="KFC" /></a></div>',
	element: "#lastUpdatedBox",
	operation: "prepend"
}
,
{
	id: "KFC1902-468x60",
	includeUrl: "scorecard.aspx",
	selectors: [ "#brandingidentifier[content='internationalhome'], #brandingidentifier[content='internationalaway']", "#matchType:contains('Twenty20')"],
	html: '<div class="scorecard-banner adserve"><a href="http://www.kfc.co.nz/" target="_blank"><img src="http://www.blackcaps.co.nz/adserve/media/KFC1902-468x60.jpg" width="468" height="60" alt="KFC" /></a></div>',
	element: "#innings1_container",
	operation: "prepend"
}


)
	

adserve = function(){
	
	var init = function(){
		
		for(var i in ads){
			var ad = ads[i];
			
			var re_include = new RegExp(ad.includeUrl, "gim");
			var re_exclude = new RegExp(ad.excludeUrl, "gim");
			
			//Check - show the ad if the window.location matches the includeUrl regex and that the selectorExists jquery selector
			//returns at least one element.
			
			var selectorMatch = true;
			for(var s in ad.selectors)
				if( $(ad.selectors[s]).length == 0) selectorMatch = false;
				
			
			if( re_include.test(window.location) && selectorMatch){//Passes the window location tests
							
				if( !(ad.excludeUrl != undefined && re_exclude.test(window.location) ) ){//Passes the exclude test
					
					var $ad = $(ad.html);
					$(ad.element)[ad.operation]($ad);

					//Google analytics code					
					try {
						var trackingCodeView = "_adserve/view" + window.location.pathname + "/" + ad.id;
						pageTracker._trackPageview(trackingCodeView);
						
						var trackingCodeClick = "_adserve/click" + window.location.pathname + "/" + ad.id;
						$("a", $ad).click( function(){ pageTracker._trackPageview(trackingCodeClick) });
					}catch(err){}
					
				}
			}
		}
	
	}	
	
	return {
	/* Public API
	*/
	init: init
	}
		
}();

$( adserve.init );