/*
	Carat Tracking Library for www.gleeson-homes.co.uk
	v2.0 2011-09-19
	(c) Carat (Leeds) 2011
*/

function mv_CreateIFrame(strURL) {
	var e = document.getElementById("mv_TargetDiv");
	if (!e) return "";
	var newIFrame=document.createElement('iframe');
	newIFrame.src=strURL;
	newIFrame.width="1";
	newIFrame.frameBorder="0";
	newIFrame.allowTransparency=true;
	newIFrame.height="1";
	e.appendChild(newIFrame);	
}

function mv_Track() {
	var a = Math.random() * 10000000000000 + "";
	var strHREF = window.location.href;
	var strPath = window.location.pathname;
	var strPage = encodeURIComponent(window.location.host + strPath);
	var strArr = strPath.split("/");
	var strProt = "http:";
	if (window.location.protocol == "https:") {
		strProt = "https:";
	}
	
	/* Generic Unique */
	mv_CreateIFrame(strProt + "//fls.doubleclick.net/activityi;src=2796491;type=count491;cat=01_ge309;u1=" + strPage + ";ord=1;num=" + a + "?");

	/* Contact Us */
	if (strHREF.indexOf('thank-you') > 0) {
		var pageName = "contact-us";		
		if(strArr.length - 1 >= 2) {pageName = strArr[2];}
		mv_CreateIFrame(strProt + "//fls.doubleclick.net/activityi;src=2796491;type=count491;cat=02_co244;u1=" + pageName + ";ord=" + a + "?");
	}
	
	/* Developments */
	var isChar = isNaN(strArr[3]);	
	if ((strArr[1] == 'developments') && (isChar == false)) {
		var pageName = strArr[2];
		mv_CreateIFrame(strProt + "//fls.doubleclick.net/activityi;src=2796491;type=count491;cat=03_de806;u1=" + pageName + ";ord=" + a + "?");	
	}
	
	/* Book Viewing Click Event */
	$("a[href*='/viewingsdirect.co.uk/'], a[href*='.viewingsdirect.co.uk/']").click(function(){carat_track_view_booking(strArr[2], strProt, a)});	
}

function carat_track_view_booking(p,s,a) {
	mv_CreateIFrame(s + "//fls.doubleclick.net/activityi;src=2796491;type=count491;cat=04_bo484;u1=" + p + ";ord=" + a + "?");		
}


mv_Track();
