/*
 * Gunn JavaScript
 */


	  	function publishStream() {
			FB.ui({
					method: 'feed',
					name: 'Gunn',
					link: 'http://gunn-site.com',
					picture: 'http://gunn-site.com/images/cover.jpg',
				//	caption: 'Download our new EP for free!',
					description: 'Download den nye EP med Gunn gratis på www.gunn-site.com'
				},
			function(response) {
				if (response && response.post_id) {
					loadDownloadInIFrame(); // Start Download
				} else {
					alert('Post on facebook to start the download'); // Meddelelsen vises hvis brugeren ikke laver et post
				}
			});
		}

		function loadDownloadInIFrame() {
				iframe = document.getElementById('i');
				iframe.src = 'http://gunn-site.com/ep_download/download.php';
		}





	function muteOrUnmute() {
	var video = document.getElementById('video');
	var audio = document.getElementById('audio');
			video.muted = !video.muted;
			audio.muted = !audio.muted;
			if(video.muted) {
				document.getElementById('muteText').innerHTML ='<b>SOUND: OFF</b>';
				video.muteState = 1;
			} else {
				document.getElementById('muteText').innerHTML ='<b>SOUND: ON</b>';
				video.muteState = 0;
			}
	}






function doResize() {
	
	var deviceAgent = navigator.userAgent.toLowerCase();
	var agentIDiPhone = deviceAgent.match(/(iphone|ipod)/);
	var agentIDiPad = deviceAgent.match(/(ipad)/);
	
	if (agentIDiPad) {

//		$('#video_background_div').css('width', '100%');
//		$('#video_background_div').css('height', '635px');
		
//		$('#video').css('width', '1024px');
		$('#video').css('height', '618px'); // SAFE: 675 px + no top margin
		
		document.getElementById('video_background_div').style.marginTop = "22px";
	
	} else if (agentIDiPhone) {
		// iPhone specific resize here !!
		
	} else {
	
		var video_ratio = (1280/720);
            var x = 0;
            if (self.innerHeight) {
                      x = self.innerWidth;
            } else if (document.documentElement && document.documentElement.clientHeight) {
                      x = document.documentElement.clientWidth;
            } else if (document.body) {
                      x = document.body.clientWidth;
            }
			var y = 0;
			if (self.innerHeight) {
                      y = self.innerHeight; }
			else if (document.documentElement && document.documentElement.clientHeight) {
                      y = document.documentElement.clientHeight;
			} else if (document.body) {
                      y = document.body.clientHeight;
			}
			// den y-værdi, der ud fra vinduets x-værdi ville give videoen sin rette ratio
			var fs_y = x / video_ratio;

		if (document.getElementById('audio').active == 1) {
			document.getElementById('video_background_div').style.marginTop = "0px";
		} else if (fs_y < y && x > 1100) {
			var margin = parseInt((y-fs_y)/2);
			margin += "px";
			document.getElementById('video_background_div').style.marginTop = margin;
		} else if (fs_y < y && x <= 1100) {
			var margin = parseInt((y-619)/2);
			margin += "px";
			document.getElementById('video_background_div').style.marginTop = margin;
/*			$('#downloadBackground').css('right', '');
			$('#downloadText').css('right', '');
			$('#downloadBackground').css('left', '658px');
			$('#downloadText').css('left', '658px');
*/
		} else {
			document.getElementById('video_background_div').style.marginTop = "0px";
		}

		if (x <= 900) {
			$('#download_like_wrapper').css('right', '');
			$('#download_like_wrapper').css('left', (parseInt(900 - 437 - 20)) + 'px');
			$('#playlist_wrapper').css('right', '');
			$('#playlist_wrapper').css('left', (parseInt(900 - 220 - 20)) + 'px');

		} else {
			$('#download_like_wrapper').css('left', '');
			$('#download_like_wrapper').css('right', '20px');
			$('#playlist_wrapper').css('left', '');
			$('#playlist_wrapper').css('right', '20px');

		}
	}
}

	function loadVideo1() {
		var video = document.getElementById('video');
		var isMuted = 0;
		if (video.muteState == null) {
				video.muteState = 0;
		}
		isMuted = video.muteState;
		
		if (video.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"') == "probably"){
			video.src="video/gunn.mp4";
        	video.load();
        	video.play();
		} else if (video.canPlayType('video/ogg; codecs="theora, vorbis"') == "probably") {
			video.src="video/gunn.ogv";
        	video.load();
        	video.play();
		} else {
			alert('mp4 and ogg not supported'); // burde aldrig blive vist med browser-sniffing-code i start()
		}
		video.addEventListener('ended',loadVideo1,false);
	}


	


	function loadAudio1() {
		var audio = document.getElementById('audio');
		var video = document.getElementById('video');
		var isMuted = 0;
		if (video.muteState == null) {
				video.muteState = 0;
		}
		isMuted = video.muteState;		
		if (!!audio.canPlayType && audio.canPlayType('audio/mpeg;').replace(/no/, '')) {
			audio.src="audio/highway_chills.mp3";
        	audio.load();
       		audio.play();
			document.getElementById('audio1title').innerHTML = '<strike>HIGHWAY CHILLS</strike>';
			document.getElementById('audio2title').innerHTML = 'MASTODON';
			document.getElementById('audio3title').innerHTML = 'WESTCOAST';
			document.getElementById('audio4title').innerHTML = 'FRAME IT';
			document.getElementById('audio5title').innerHTML = "WAIT (till' I wake up)";
			if (isMuted == '1') {
				muteOrUnmute();
				muteOrUnmute();
			}
			audio.addEventListener('ended',loadAudio2,false);
			return;
		} else { //if (audio.canPlayType('audio/ogg; codecs="vorbis"') == "probably") {
			audio.src="audio/highway_chills.ogg";
        	audio.load();
       		audio.play();
			document.getElementById('audio1title').innerHTML = '<strike>HIGHWAY CHILLS</strike>';
			document.getElementById('audio2title').innerHTML = 'MASTODON';
			document.getElementById('audio3title').innerHTML = 'WESTCOAST';
			document.getElementById('audio4title').innerHTML = 'FRAME IT';
			document.getElementById('audio5title').innerHTML = "WAIT (till' I wake up)";
			if (isMuted == '1') {
				muteOrUnmute();
				muteOrUnmute();
			}
			audio.addEventListener('ended',loadAudio2,false);
			return;
		} 
	}
	
	function loadAudio2() {
		var audio = document.getElementById('audio');
		var video = document.getElementById('video');
		var isMuted = 0;
		if (video.muteState == null) {
				video.muteState = 0;
		}
		isMuted = video.muteState;	
		if (!!audio.canPlayType && audio.canPlayType('audio/mpeg;').replace(/no/, '')) {
			audio.src="audio/mastodon.mp3";
        	audio.load();
       		audio.play();
			document.getElementById('audio1title').innerHTML = 'HIGHWAY CHILLS';
			document.getElementById('audio2title').innerHTML = '<strike>MASTODON</strike>';
			document.getElementById('audio3title').innerHTML = 'WESTCOAST';
			document.getElementById('audio4title').innerHTML = 'FRAME IT';
			document.getElementById('audio5title').innerHTML = "WAIT (till' I wake up)";
			if (isMuted == '1') {
				muteOrUnmute();
				muteOrUnmute();
			}
			audio.addEventListener('ended',loadAudio3,false);
			return;
		} else { //if (audio.canPlayType('audio/ogg; codecs="vorbis"') == "probably") {
			audio.src="audio/mastodon.ogg";
        	audio.load();
       		audio.play();
			document.getElementById('audio1title').innerHTML = 'HIGHWAY CHILLS';
			document.getElementById('audio2title').innerHTML = '<strike>MASTODON</strike>';
			document.getElementById('audio3title').innerHTML = 'WESTCOAST';
			document.getElementById('audio4title').innerHTML = 'FRAME IT';
			document.getElementById('audio5title').innerHTML = "WAIT (till' I wake up)";
			if (isMuted == '1') {
				muteOrUnmute();
				muteOrUnmute();
			}
			audio.addEventListener('ended',loadAudio3,false);
			return;
		}
	}
	
	function loadAudio3() {
		var audio = document.getElementById('audio');
		var video = document.getElementById('video');
		var isMuted = 0;
		if (video.muteState == null) {
				video.muteState = 0;
		}
		isMuted = video.muteState;	
		if (!!audio.canPlayType && audio.canPlayType('audio/mpeg;').replace(/no/, '')) {
			audio.src="audio/westcoast.mp3";
        	audio.load();
       		audio.play();
			document.getElementById('audio1title').innerHTML = 'HIGHWAY CHILLS';
			document.getElementById('audio2title').innerHTML = 'MASTODON';
			document.getElementById('audio3title').innerHTML = '<strike>WESTCOAST</strike>';
			document.getElementById('audio4title').innerHTML = 'FRAME IT';
			document.getElementById('audio5title').innerHTML = "WAIT (till' I wake up)";
			if (isMuted == '1') {
				muteOrUnmute();
				muteOrUnmute();
			}
			audio.addEventListener('ended',loadAudio4,false);
			return;
		} else { //if (audio.canPlayType('audio/ogg; codecs="vorbis"') == "probably") {
			audio.src="audio/westcoast.ogg";
        	audio.load();
       		audio.play();
			document.getElementById('audio1title').innerHTML = 'HIGHWAY CHILLS';
			document.getElementById('audio2title').innerHTML = 'MASTODON';
			document.getElementById('audio3title').innerHTML = '<strike>WESTCOAST</strike>';
			document.getElementById('audio4title').innerHTML = 'FRAME IT';
			document.getElementById('audio5title').innerHTML = "WAIT (till' I wake up)";
			if (isMuted == '1') {
				muteOrUnmute();
				muteOrUnmute();
			}
			audio.addEventListener('ended',loadAudio4,false);
			return;
		}
	}


	function loadAudio4() {
		var audio = document.getElementById('audio');
		var video = document.getElementById('video');
		var isMuted = 0;
		if (video.muteState == null) {
				video.muteState = 0;
		}
		isMuted = video.muteState;	
		if (!!audio.canPlayType && audio.canPlayType('audio/mpeg;').replace(/no/, '')) {
			audio.src="audio/frame_it.mp3";
        	audio.load();
       		audio.play();
			document.getElementById('audio1title').innerHTML = 'HIGHWAY CHILLS';
			document.getElementById('audio2title').innerHTML = 'MASTODON';
			document.getElementById('audio3title').innerHTML = 'WESTCOAST';
			document.getElementById('audio4title').innerHTML = '<strike>FRAME IT</strike>';
			document.getElementById('audio5title').innerHTML = "WAIT (till' I wake up)";
			if (isMuted == '1') {
				muteOrUnmute();
				muteOrUnmute();
			}
			audio.addEventListener('ended',loadAudio5,false);
			return;
		} else { //if (audio.canPlayType('audio/ogg; codecs="vorbis"') == "probably") {
			audio.src="audio/frame_it.ogg";
        	audio.load();
       		audio.play();
			document.getElementById('audio1title').innerHTML = 'HIGHWAY CHILLS';
			document.getElementById('audio2title').innerHTML = 'MASTODON';
			document.getElementById('audio3title').innerHTML = 'WESTCOAST';
			document.getElementById('audio4title').innerHTML = '<strike>FRAME IT</strike>';
			document.getElementById('audio5title').innerHTML = "WAIT (till' I wake up)";
			if (isMuted == '1') {
				muteOrUnmute();
				muteOrUnmute();
			}
			audio.addEventListener('ended',loadAudio5,false);
			return;
		}
	}
	
	function loadAudio5() {
		var audio = document.getElementById('audio');
		var video = document.getElementById('video');
		var isMuted = 0;
		if (video.muteState == null) {
				video.muteState = 0;
		}
		isMuted = video.muteState;	
		if (!!audio.canPlayType && audio.canPlayType('audio/mpeg;').replace(/no/, '')) {
			audio.src="audio/wait.mp3";
        	audio.load();
       		audio.play();
			document.getElementById('audio1title').innerHTML = 'HIGHWAY CHILLS';
			document.getElementById('audio2title').innerHTML = 'MASTODON';
			document.getElementById('audio3title').innerHTML = 'WESTCOAST';
			document.getElementById('audio4title').innerHTML = 'FRAME IT';
			document.getElementById('audio5title').innerHTML = "<strike>WAIT (till' I wake up)</strike>";
			if (isMuted == '1') {
				muteOrUnmute();
				muteOrUnmute();
			}
			audio.addEventListener('ended',loadAudio1,false);
			return;
		} else { //if (audio.canPlayType('audio/ogg; codecs="vorbis"') == "probably") {
			audio.src="audio/wait.ogg";
        	audio.load();
       		audio.play();
			document.getElementById('audio1title').innerHTML = 'HIGHWAY CHILLS';
			document.getElementById('audio2title').innerHTML = 'MASTODON';
			document.getElementById('audio3title').innerHTML = 'WESTCOAST';
			document.getElementById('audio4title').innerHTML = 'FRAME IT';
			document.getElementById('audio5title').innerHTML = "<strike>WAIT (till' I wake up)</strike>";
			if (isMuted == '1') {
				muteOrUnmute();
				muteOrUnmute();
			}
			audio.addEventListener('ended',loadAudio1,false);
			return;
		}
	}

/*
function supports_h264_baseline_video() {
  if (!supports_video()) { return false; }
  var v = document.createElement("video");
  return v.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"');
}

function supports_ogg_theora_video() {
  if (!supports_video()) { return false; }
  var v = document.createElement("video");
  return v.canPlayType('video/ogg; codecs="theora, vorbis"');
}

function supports_webm_video() {
  if (!supports_video()) { return false; }
  var v = document.createElement("video");
  return v.canPlayType('video/webm; codecs="vp8, vorbis"');
}
*/

	function goFullscreen() {
		document.getElementById('fullscreen').innerHTML = '<b>> return <</b>';
		$("#controls2").fadeTo(2000, 0.5); //fadeOut i stedet ?

		$("#controls").fadeOut(2000);
		$("#cover").fadeOut(2000);
		$("#bandname_div").fadeOut(2000);
		$("#downloadText").fadeOut(2000);
		$("#like").fadeOut(2000);
		$("#links_div").fadeOut(2000);
		$("#downloadBackground").fadeOut(2000);
	}

	function leaveFullscreen() {
		document.getElementById('fullscreen').innerHTML = '<b>FULLSCREEN</b>';
		$("#controls2").fadeTo(2000, 1);

		$("#controls").fadeTo(2000, 1);
		$("#cover").fadeTo(2000, 1);
		$("#bandname_div").fadeTo(2000, 1);
		$("#downloadText").fadeTo(2000, 1);
		$("#like").fadeTo(2000, 1);
		$("#links_div").fadeTo(2000, 1);
		$("#downloadBackground").fadeTo(2000, 1);
	}



	function start() {
/*	
		document.getElementById('loadVideo1Marker').innerHTML ='->';
		document.getElementById('video').addEventListener('ended',loadVideo2,false);
*/
		// flyt evt op som første step i start() ??

		if($.browser.msie) {
			$("#downloadText").css('font-size', '19px');
			if($.browser.version=="6.0") {
//				alert("Im the annoying IE6");
				location.href="old_ie.html";
			}
		}


		if (!(!!document.createElement('video').canPlayType)) {
			$("#playlistDiv").fadeOut(3000, function() {
				document.getElementById('mainText').innerHTML ='To enjoy all functionality on this website, use a HTML5-compatible browser such as <a href="http://mozilla.com/firefox"><u>Mozilla Firefox</u></a>, <a href="http://www.google.com/chrome"><u>Google Chrome</u></a> or <a href="http://windows.microsoft.com/ie"><u>Internet Explorer 9</u></a>';
			})
		} else {
			loadVideo1();
			loadAudio1();
		}

		var deviceAgent = navigator.userAgent.toLowerCase();
		var agentIDiPhone = deviceAgent.match(/(iphone|ipod)/); // deviceAgent.match(/(iphone|ipod|ipad)/);
		var agentIDiPad = deviceAgent.match(/(ipad)/);
		// iPad, iPod eller iPad
		if (agentIDiPhone) {
			$("#video_background_div").fadeOut(2000);
		} else if (agentIDiPad) {

		}
	}

