var $j = jQuery.noConflict();

$j(document).ready(function() {
	SWFAddress.addEventListener(SWFAddressEvent.CHANGE, onAddressChange);
	SWFAddress.addEventListener(SWFAddressEvent.INIT, onAddressInit);
});

function onAddressChange(event) {
	if (self.document.location.hash.substring(1).toString() == event.path.toString()) {
		document.location.href = event.path.toString();
	}
}

function onAddressInit(event) {
	if (event.path.toString() != "/") {
		document.location.href = event.path.toString();
	}
}

function updateNavigationBar(lang,controller,action) {
	window.scrollTo(0,0);
	$j.get("/"+lang+"/navigation", { first: controller, second: action }, function(data) {
		$j('#navigation').html(data);
		setMediaPlayerContent(controller, action);
	});
}

function updateNavigationBarFromFlash(lang,controller,action) {
	$j.get("/"+lang+"/navigation", { first: controller, second: action }, function(data) {
		$j('#navigation').html(data);
	});
}

function setMediaPlayerContent(controller,action,id) {
	document.getElementById('sounddevelopment').setContent(controller, action, id);
}

function updateNavigationStatic(lang,controller,action,id,mod) {
	$j.get("/"+lang+"/navigation/static", { first: controller, second: action, third: id, fourth: mod }, function(data) {
		$j('#html_static').html(data);
	});
}

function stopMediaPlayer() {
	document.getElementById('sounddevelopment').pauseMediaPlayer();
}

function loadPinwall() {
	// mediaPlayerOver();
	$j('#html_static').hide();
	$j('#html_content').hide();
	document.getElementById('sounddevelopment').loadPinwall();
}

function closePinwall() {
	$j('#html_static').show();
	$j('#html_content').show();
	mediaPlayerOver();
}

function setContentFromFlash(lang,controller,action,id) {
	switch(controller) {
		
		case "projects":
		$j.get("/"+lang+"/projects/project/"+id+".js", function(data) {
			$j('#content').html(data);
			updateNavigationBarFromFlash(lang,'projects','overview');
			updateNavigationStatic(lang,'projects','overview','','');
		});
		break;
		
		case "about":
		$j.get("/"+lang+"/"+controller+"/"+action+".js", function(data) {
			$j('#content').html(data);
			updateNavigationBarFromFlash(lang,controller,action);
			updateNavigationStatic(lang,controller,action,'','');
		});
		break;
		
		case "static":
		$j.get("/"+lang+"/"+controller+"/"+action+".js", function(data) {
			$j('#content').html(data);
			updateNavigationBarFromFlash(lang,controller,action);
			updateNavigationStatic(lang,controller,action,'','');
		});
		break;
	}
}

function mediaPlayerOver () {
	$j('#html_static').css('opacity', '0');
	$j('#html_content').css('opacity', '0');
}

function mediaPlayerOut () {
	$j('#html_static').css('opacity', '1');
	$j('#html_content').css('opacity', '1');
}

function outLinks() {
	var yourURL = location.hostname; 
	var outLink; 
	if (document.getElementsByTagName('a')) { 
		for (var i = 0; (outLink = document.getElementsByTagName('a')[i]); i++) {
			if (outLink.href.indexOf(yourURL) == -1) { 
				outLink.setAttribute('target', '_blank'); 
			} 
		}
	}
}










