﻿var Site=new Hash({
	init:function () {
		Site._initLightbox();
		Site._initDotNetValidatorFunctions();
		Site._initUrchin();
		Site._initCheckboxes();
		Site._initAnchors();

		//$$(".site-rss").addReplacingEvent("click",function (e) {
		//	window.location.href="Rss.ashx";
		//});

		//show "not supported" message for Safari 2
		if (Browser.Engine.webkit419){
			var lb=new SiteLightbox($("Safari2UsersLB")).show();
		}

	},
	_initUrchin:function () {
		//google search query tracker
		if (typeof(Ads)!="undefined") Ads.addEvent("onSearching",function (searchTerms,searchTags,topRated,editorsChoice) {
			var qs=new Hash();
			qs.q=searchTerms ? searchTerms.join(" ") : "";
			qs.tagIds=searchTags ? searchTags.join("-") : "";
			if (topRated) qs.topRated=1;
			if (editorsChoice) qs.editorsChoice=1;

			var query="/AdSearch?"+qs.toQueryString();
			Site.trackStats(query);
		});
		if (typeof(Ad)!="undefined") Ad.addEvent("onOpening",function (adId) {
			var query="/AdSmallPreview?adId="+adId;
			//console.log(query);
			Site.trackStats(query);
		});
		if (typeof(FullAd)!="undefined") FullAd.addEvent("onOpening",function (adId,name) {
			var query="/AdFullPreview?adId="+adId;
			Site.trackStats(query);
		});				
	},
	trackStats:function (url) {				
		pageTracker._trackPageview(url);
	},
	_initLightbox:function () {
		if (typeof(Lightbox)!="undefined") Lightbox.setOptions({
			backgroundColor:"#000000",
			opacity:0.4,
			containerClass:"lightbox",
			offsetTop:300
		});
	},
	_initDotNetValidatorFunctions:function () {
		if (typeof(ValidatorUpdateDisplay)=="function") eval(
			"window.ValidatorUpdateDisplay="+
			ValidatorUpdateDisplay.toString()
				.replace("ValidatorUpdateDisplay","")
				.replace(/inline/g,"block")
		);
		if (typeof(ValidationSummaryOnSubmit)=="function") eval(
			"window.ValidationSummaryOnSubmit="+
			ValidationSummaryOnSubmit.toString()
				.replace("ValidationSummaryOnSubmit","")
				.replace(/window.scrollTo\(0,0\);/,"")
		);
	},
	_initCheckboxes:function () {
		if (typeof(Lightbox)!="undefined") Lightbox.addEvent("onAfterShow",function () {
			new CheckBoxes($$("label>input[type=checkbox]").getParents("label"));
		});
	},

	_initAnchors:function () {
		new SmoothScroll({
			links:'.anchor',
			wheelStops:false
		},$(document.body));
	}
});


$DL(Site.init);



