window.dhtmlHistory.create({
    toJSON: function(o) {
            return JSON.stringify(o);
    }
    , fromJSON: function(s) {
            return JSON.parse(s);
    }
});

var yourListener = function(hash, historyData) {
	
	if (typeof hash == "undefined" || !hash) {
		return false;
	}
	
	jQuery(".newigation a").closest(".buttonLink").removeClass("selectedButtonLink");
	jQuery(".newigation a[href='#"+hash+"']").closest(".buttonLink").addClass("selectedButtonLink");
	
	
	jQuery(".page").hide();
	jQuery(".page[page='"+hash+"']").show();
	
	
	_gaq.push(['_trackPageview', hash]);
	
	setTimeout(function() {
		document.title = "Cup Manager - " + jQuery(".newigation a[href='#"+hash+"']").text();
	}, 50);
}



jQuery(function() {
	jQuery(".newigation a").click(function() {
		var page = jQuery(this).attr("href").substring(1);
		//document.title = "Cup Manager - " + jQuery(this).text();
		dhtmlHistory.add(page);
		yourListener(page);
		return false;
	});
	
	dhtmlHistory.addListener(yourListener);
	dhtmlHistory.initialize();
	
	if (window.location.hash.length > 1)
	{
		var hash = window.location.hash.substring(1);
		jQuery(".newigation a[href='#"+hash+"']").click();
	} else {
		jQuery(".newigation a:first").click();
	}
	
});


jQuery(function() {
	var relCounter = 1;
	jQuery(".featurePreview").each(function() {
		jQuery(this).find("a>img").parent().attr("rel", "rel_"+(relCounter++)).colorbox({loop:false});
	});
	
	jQuery(".goButton").colorbox({iframe:true, innerWidth:525, innerHeight:260});
	
	jQuery(".featurePreview a").click(function() {
		var title = jQuery(this).attr("title");
		_gaq.push(['_trackEvent', 'Image', 'Click', title]);
	});
	
	jQuery(".buttonLink").hover(function() {
		jQuery(this).addClass("hoverButtonLink");
	}, function() {
		jQuery(this).removeClass("hoverButtonLink");
	});
	
});