/**
 * This function will set the new skin when it is selected by the user.
 * @param	Integer		$id		The id of the skin.
 * 
 * @return	Void
 */
function setSkin($id)
{
	if ($id != 0) {
		var $element = document.getElementById('websiteSkin');
		$element.style.background = 'url(\'http://provincie.fm/Images/Skins/'+$id+'.png\')';
		createCookie('playerSkin', $id, 365);
	}
}

/**
 * This function will start the animation of the speakers.
 * 
 * @return	Void
 */
function startSpeakers(){
	$('#speakerAnimation').fadeOut(200, function(){
		setTimeout(function(){
			$('#speakerAnimation').fadeIn(200, startSpeakers)
		},300);
	});
}

/**
 * This function retrieves the correct player through an AJAX request.
 * @param	Integer		$playerId		The id of the player.
 */
function getPlayer($playerId)
{
	$('#stationPlayer').html('');
	$.post("/getPlayer.php", { playerId: $playerId, text: false }, function(data){
		$('#stationPlayer').html(data);
	});
	$('#speakerAnimation').css("display", "block");
	$('#visualization').css("display", "block");
}

function getStations($province, $updateUrl)
{
	$.ajaxSetup({
		cache: false
	});
	$.getJSON("/getStations.php", {province: $province, text: false}, 
	function(data)
	{
		for ($i = 1; $i < 19; $i++)
		{
			$station = document.getElementById('station' + $i);
			if ($station != "undefined" && $station != null) {
				if (data[$i] != "undefined" && data[$i] != null) {
					$station.innerHTML = data[$i];
				} else {
					$station.innerHTML = '<div style="height:68px;width:68px"></div>';
				}
			} else {
				break;
			}
		}
		
		$("#stationsLeft img, #stationsRight img, #stationsLeft a, #stationsRight a").tooltip({
			track: true,
			delay: 0,
			fade: 0,
			showURL: false,
			showBody: "", 
			extraClass: "tooltipSkins"
		});
		
		var pageTracker = _gat._getTracker("UA-398344-10");
		
		pageTracker._trackPageview("/"+$province);
	});
}

/**
 * This function will create the media player which will play a jingle.
 * @param	Integer		$id		The id of the jingle to play.
 */
function playJingle($id)
{
	var $jingles = [];
	$jingles[1]	 = '1.wav';
	$jingles[2]	 = '2.wav';
	$jingles[3]	 = '3.wav';
	$jingles[4]	 = '4.wav';
	$jingles[5]	 = '5.mp3';
	$jingles[6]	 = '6.wav';
	$jingles[7]	 = '7.wav';
	$jingles[8]	 = '8.wav';
	$jingles[9]	 = '9.wav';
	for ($i in $jingles)
	{
		if ($id == $i)
		{
			var $url = 'http://www.provincie.fm/Sound/Samples/'+$jingles[$i];
			var $html = '';
			
			$html += '	<object id="" width="0" height="0" classid="CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112" type="application/x-oleobject">';
			$html += '		<param name="url" value="'+$url+'" />';
			$html += '		<param name="autoStart" value="true" />';
			$html += '		<param name="showControls" value="true" />';
			$html += '		<param name="ShowStatusBar" value="true" />';
			$html += '		<param name="uiMode" value="none" />';
                        $html += '		<param name="volume" value="100" />';
			$html += '		<embed type="application/x-mplayer2" pluginspage="http://www.microsof.com/Windows/MediaPlayer/" src="'+$url+'" width="270" height="65" autostart="1" showcontrols="1" showstatusbar="1" volume="100" />';
			$html += '</object>';
			
			$('#jingleMediaPlayer').html($html);
		}
	}
}

function getInfo($info, $form)
{
    $.post("/getInfo.php", { info: $info, form: $form}, function(data){
	$('#infoPopupContent').html(data);
        $('#infoPopup').css('display', 'block');
    });
}

function sendEmail()
{   $info           = 'contactSubmit';
    $name           = $('#name').val();
    $emailAddress   = $('#emailAddress').val();
    $subject        = $('#subject').val();
    $message        = $('#message').val();
    $.post("/getInfo.php", { info: $info, name: $name, emailAddress: $emailAddress, subject: $subject, message: $message}, function(data){
	$('#infoPopupContent').html(data);
        $('#infoPopup').css('display', 'block');
    });

}

function closePopup()
{
    $('#infoPopup').css('display', 'none');
}


	/* Cookie Handling Scripts */


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);
}
