//used to stop inliked errors reporting
function stopWindowErrors() {
	return true;
}

window.onerror = stopWindowErrors; 

function setTextVersion(url) {
	
	createCookie('textVersion', 'contrastText', 1);	

	window.location.reload();
};


function setGraphicVersion(url) {
	
	eraseCookie('textVersion');
	
	var hash = '';
	
	if (location.hash.length > 0) {
		
		hash = location.hash.replace('#txt', '');
		hash = hash.replace(',txt', '');
	}

	window.location.href = url + hash;	
};

function checkTextVersion(url) {
			
	if (location.hash.length > 0 && readCookie('textVersion') != 'contrastText') {
	    if (location.hash.indexOf('txt'))
			setTextVersion(url);
	}

	if (readCookie('textVersion') == 'contrastText') {
	
		var hash = '#txt';
		
		if (location.hash.length > 0) {
			
		    if (location.hash.indexOf('txt'))
		    	hash = location.hash;
		    	
		    else
		    	hash = location.hash + ',txt';
		}
		
		window.location.href = hash;
	}
}

function loadAddress(action) {

	var hash = '';

	if(location.hash.length > 0)
		hash = location.hash;

	window.location.href = action + hash;
};
				
function appendPlayer(parent, file, width, height, style) {

	$('.player_container').remove();
	
	$('#webCamListSection .close_link:visible').click();
	
	var player_html = '<div class="player_container" id="tmpPlayerId">';
	player_html 	+= '<div id="audio" style="display: block; float: left; clear: both; width:'+width+'px; height:'+height+'px;'+style+'" href="'+file+'"></div>';
	player_html		+= '<a href="javascript://" onclick="closePlayer(\'tmpPlayerId\')" class="close_link" title="close">&nbsp;</a>';
	player_html		+= '</div>';

	parent.append(player_html);
	parent.addClass('left');		

	//stopMusicBgr();

	// install flowplayer into container
	$f("audio", SiteUrl+"js/general/flowplayer/swf/flowplayer-3.2.7.swf", {

		// fullscreen button not needed here
		plugins: {
			controls: {
				fullscreen: false,
				height: height,
				autoHide: false
			}
		},
		
		clip: {
			autoPlay: true,

			// optional: when playback starts close the first audio playback
			onBeforeBegin: function() {
				//$f("player").close();				
			},
		
			onBegin: function() {
				setTimeout('stopMusicBgr()', 1000);
			}
		}				
	});
}

function closePlayer(id) {		
	$('#'+id).remove();
	startMusicBgr();
}

function setPlayer() {

	if ($('#audioGlobalContainer').hasClass('play')) {
		$f("audio_global").pause();
		$('#audioGlobalContainer').removeClass('play').addClass('pause');
		createCookie('audioPlay', 'pause', 1);
	}

	else {
		$f("audio_global").play();
		$('#audioGlobalContainer').removeClass('pause').addClass('play');
		createCookie('audioPlay', 'play', 1);
	}
}

function openBrochure() {

	$('.player_container').remove();
	
	$('#webCamListSection .close_link:visible').click();	
	
	// stop player

	if ($('#audioGlobalContainer').hasClass('play')) {		
		setTimeout('stopMusicPlayer()', 1000);		
		createCookie('audioPlay', 'pause', 1);
	}	
}

function stopMusicPlayer() {	
	$(document).ready(function(){
		$f("audio_global").pause();
		$('#audioGlobalContainer').removeClass('play').addClass('pause');
	});
}

function stopMusicBgr() {
	$(document).ready(function(){
		$f("audio_global").pause();
	});
}

function startMusicBgr() {
	if (readCookie('audioPlay') != 'pause')
		$f("audio_global").play();
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
