var Main = function($){
	var config = {
	
	}
	
	var priv = {
		stripDomain : function(url){
			try {
				return url.substr(url.indexOf("/", 7) + 1);
			}
			catch(exp) {
				return url;
			}
		},
		
		tracking : function(url){
			Log.Info("Tracking : " + url);
			try {//google analytics tracking
				pageTracker._trackPageview(url);
			}
			catch(exp){Log.Debug("google tracking failed, " + exp.toString())};
		}
	}
	
	return {
		Ready : function(){
			$.browser.msie6 = ($.browser.msie && typeof(XMLHttpRequest) == "undefined" && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent) && !/MSIE 8\.0/i.test(window.navigator.userAgent)); 
			
			//preload offstate for demo hover
			var dummyImg = document.createElement("IMG");
			dummyImg.src = "images/demo-balloon-on.gif";
			
			//initiate the podcast carousel
			//define the start index
			var startIndex = 0;
			if(document.location.hash){
				var hash = priv.stripDomain(document.location.hash.substr(1));
				Log.Debug("Hash : " + hash);
				var $item = $("#podcasts ul li div.interaction a.play[href=" + hash + "]");
				
				startIndex = $("#podcasts ul li").index($item.parents("li:eq(0)"));
				Log.Debug("selected index : " + startIndex);
				priv.tracking("/podcast-entered-on/" + priv.stripDomain($item.attr("href")));				
			}
			
			var carousel = new Carousel({"container" : $("#podcasts div.podcasts-container").get(0), "startIndex" : Math.max(0, startIndex)});
			//for IE6 disable the anchor, it messes up the images (wants to load the page)
			if($.browser.msie6){
				//$("#podcasts a.next, #podcasts a.prev").attr("href", "javascript:void(0);");
			}
			$("#podcasts a.next").not(".inactive").bind("click",
				function(){
					priv.tracking("/podcast-navigate-to/" + priv.stripDomain($(this).attr("href")));
					carousel.Next();
				}
			);
			$("#podcasts a.prev").not(".inactive").bind("click",
				function(){
					priv.tracking("/podcast-navigate-to/" + priv.stripDomain($(this).attr("href")));
					carousel.Prev();
				}
			);
			
			//play in smaller window
			$("a[rel='play']").attr("target", "playerWindow").bind("click", 
				function(){
					priv.tracking("/listening-to/" + $(this).attr("href"));
					var openwin = window.open("", "playerWindow", "width=200, height=100");
				}
			);
			
			//stats for downloads
			$("a[rel='download']").bind("click", 
				function(){
					priv.tracking("/downloading/" + $(this).attr("href"));
				}
			);
			
			//stats for email
			$("#text-content p.contact a").bind("click", 
				function(){
					priv.tracking("/email-to/sanne");
				}
			);
			
			//init the players
			//Player.Ready();			
		}
	}
}(jQuery);

$(document).ready(
	function(){
		Main.Ready();
	}
);