$(function(){
	
	var urlSite = "http://" + top.location.host.toString(),
			hash 		= window.location.hash,
			$internalLinks = $('a[href^='+urlSite+']'),
			$layer = $('#layer'),
			$title = $('#title h1');

	if(hash){
		hash = hash.substr(1);
		loadContent(urlSite + hash, $layer, $title );
	}
	
	$internalLinks.each(function(){
		$(this).attr('href', "#" + this.pathname);	
	}).click(function(e){
		var $this = $(this),
				href = $this.attr('href').substr(1);
		loadContent(href, $layer, $title);
	});
	
	
	function loadContent(href, the_layer, the_title){
		the_layer.stop(true,true).animate({ opacity: "0.1"});
		$.get(href,{}, function(html){
			var title = $(html).find('#title h1').html();
			var content = $(html).find('#layer');
			
			the_layer.html(content);
			the_title.html(title);
			the_layer.stop(true,true).animate({ opacity: "1"});
		});
	}
	
	var flashvars = {
	  mp3: rootUrl+"/sound/bo2.mp3",
		autoreplay: true,
		autoplay:true
	};
	var params = {
	  wmode: "transparent"
	};
	var attributes = {
	  id: "dewplayer"
	};
	swfobject.embedSWF(rootUrl + "/swf/dewplayer.swf", "playerholder", "160", "20", "9.0.0", false, flashvars, params, attributes);
});
