var intTotalEventHeight = 0;
var intBoxTopMargin = 0;
var intDoTheThing = 1;
var intImageheight = 83;
var intImageMargin = 10;
var intVisibleImages = 3;
var strTempText = "";
$(document).ready(function(){
	$(".imgscrollup").click(function(){
		if (intBoxTopMargin < 0 ) {
			scrolly("up",(intImageheight+intImageMargin));
		}
	});
	$(".imgscrolldown").click(function(){
		if (intBoxTopMargin > -intTotalEventHeight + (intVisibleImages*(intImageheight+intImageMargin))) {
			scrolly("down",(intImageheight+intImageMargin));
		}
	});
	$(".propertyscrollimg").each(function(){
		intTotalEventHeight = intTotalEventHeight + intImageheight + intImageMargin;
	});
	
	$(".enquirylink").click(function(){
		var intThisId = $(this).attr("href").split("=");
		pageTracker._trackPageview("/enquiry.php?ID="+intThisId[1]);
	});
	
	$("#enquiryform").validate({
		errorClass: "enqerrorlabel",
		submitHandler: function(form) {
			$("#enquiryform").ajaxSubmit({
				target: ".enquirycontainer",
				success: enqSuccess
			});
			return false;
		}
	});
	
	function enqSuccess() {
		$(".enquirycontainer").html("<div class=\"enqsuccess\"><p class=\"enqsuccesstext\">Thank you for your enquiry. A member of our team will contact you shortly.</p></div>");
		trackConversion(1070404926, "en_gb", 2, "ffffff", "QR7QCIL8pQEQvqq0_gM", 0);
		trackConversionMSN(51212, 5050, "dedup=1");
		var arrQueryString = $(".meaninglesslinkclass", top.document).attr("href").split("?");
		if (arrQueryString[1] != undefined) {
			strQueryString = arrQueryString[1];
			arrQueryObjects = strQueryString.split("&");
			
			var objQueryObject = new Object();
	
			for(x in arrQueryObjects) {
				arrQueryObject = arrQueryObjects[x].split("=");
				objQueryObject[arrQueryObject[0]] = arrQueryObject[1];
			}
		}
		if(objQueryObject != undefined) {
			if (objQueryObject["type"] != undefined && objQueryObject["intID"] != undefined) {
				pageTrackerURL = "/enquiryconfirmation.php?type="+objQueryObject["type"]+"&ID="+objQueryObject["intID"];
			} else {
				pageTrackerURL = "/enquiryconfirmation.php?type=ERROR&ID=ERROR";
			}
		} else {
				pageTrackerURL = "/enquiryconfirmation.php?type=generic";
		}
		pageTracker._trackPageview(pageTrackerURL);
	}
	
	$("#newslettersignup").validate({
		submitHandler: function(form) {
			$("#newslettersignup").ajaxSubmit({
				//target: ".newsletterajaxcont",
				success: newsSignupSuccess
			});
			return false;
		}
	});
	
	function newsSignupSuccess() {
		$(".newsletterajaxcont").html("<p class=\"signupsuccesstext\">Thank you for signing up to the Golf Options Newsletter. Your subscription has been successful.</p>");
		//trackConversion(1070404926, "en_gb", 2, "ffffff", "QR7QCIL8pQEQvqq0_gM", 0);
		trackConversionMSN(51212, 5050, "dedup=1");
	}
	
	$("#brochurerequestform").validate({
		submitHandler: function(form) {
			$("#brochurerequestform").ajaxSubmit({
				target: ".brochurerequestform",
				success: brochureSuccess
			});
			return false;
		},
		rules: {
			brochurerequest_email: "required",
			brochurerequest_emailconf: {
				equalTo: "#brochurerequest_email"
			}
		}
	});
	
	function brochureSuccess() {
		//trackConversion(1070404926, "en_gb", 2, "ffffff", "QR7QCIL8pQEQvqq0_gM", 0);
		trackConversionMSN(51212, 5050, "dedup=1");
	}
	
	strTempText = "Enter your email address"
	$("#newsletter_email").focus(function(){if($(this).val()==strTempText){$(this).val("");};}).blur(function(){$(this).val(($(this).val() == "" ? strTempText : $(this).val()));});
	
	$(".parentlist").hover(function(){
		$(this).children("ul").addClass("subnavactive");
	},function(){
		$(this).children("ul").removeClass("subnavactive");
	});
});	

scrolly = function(direction,directionval) {
	if (intDoTheThing == 1) {
		intDoTheThing = 0;
		strDirection = direction;
		intScroll = parseInt(directionval);
		if (direction == "up") {
			intScroll = intScroll;
		} else {
			intScroll = -intScroll;
		}
		var topmargin = $(".propertyimagescrollcontainer ").css("top");
		topmargin = topmargin.substr(0,topmargin.length - 2)
		topmargin = parseInt(topmargin);
		topmargin = topmargin + intScroll;
		intBoxTopMargin = topmargin;
		$(".propertyimagescrollcontainer ").animate({"top":topmargin+"px"}, 350, "swing", function(){intDoTheThing = 1;});
		if (direction == "up") {
			intScroll = intScroll;
		} else {
			intScroll = -1 * intScroll;
		}
		if (intBoxTopMargin != 0 ) {
			$(".imgscrollup").addClass("imgscrollup-change");
		} else if (intBoxTopMargin == 0 ) {
			$(".imgscrollup").removeClass("imgscrollup-change");
		}
		if (intBoxTopMargin == -intTotalEventHeight + 279 ) {
			$(".imgscrolldown").addClass("imgscrolldown-change");
		} else if (intBoxTopMargin != -intTotalEventHeight + 279) {
			$(".imgscrolldown").removeClass("imgscrolldown-change");
		}
	}
}
var google_conversion_id = "";
var google_conversion_language = "";
var google_conversion_format = "";
var google_conversion_color = "";
var google_conversion_label = "";
var google_conversion_value = "";

var microsoft_adcenterconversion_domainid = 0;
var microsoft_adcenterconversion_cp = 0;
var microsoft_adcenterconversionparams = new Array();

trackConversion = function(googleID, googleLang, googleFormat, googleColour, googleLabel, googleVal) {
	google_conversion_id = googleID;
	google_conversion_language = googleLang;
	google_conversion_format = googleFormat;
	google_conversion_color = googleColour;
	google_conversion_label = googleLabel;
	google_conversion_value = googleVal;
	$("body").append("<img height=\"1\" width=\"1\" style=\"border-style:none;\" alt=\"\" title=\"\" src=\"http://www.googleadservices.com/pagead/conversion/"+google_conversion_id+"/?label="+google_conversion_label+"&amp;guid=ON&amp;script=0\"/>");
}

trackConversionMSN = function(intDomainID, intCP, arrConvParams) {	
	$("body").append("<img height=\"1\" width=\"1\" style=\"border-style:none;\" alt=\"\" title=\"\" src=\"http://"+intDomainID+".r.msn.com/?type=1&cp="+intCP+"&"+arrConvParams+"\"/>");
};