window.onload = function() {
    setMainImageSize();
}

window.onresize = function() {
    setMainImageSize();
}

var type = "";
if (navigator.userAgent.indexOf("Opera")!=-1 && document.getElementById) type="OP";
if (document.all) type="IE";
if (document.layers) type="NN";
if (!document.all && document.getElementById) type="MO";

function setMainImageSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
		 myWidth = window.innerWidth;
		 myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
	}
	
	
	var new_image_height = (myHeight-70-50-10);
	var new_image_width = new_image_height * (1280/720);
	
	var target_image_width = (myWidth-50-50-20-16);
	
	if(new_image_width > target_image_width) {
		new_image_width = target_image_width;
		new_image_height = new_image_width * (720/1280);
	}

	var videoplayer = document.getElementById('videoplayer');
	videoplayer.style.height = new_image_height + "px";
	videoplayer.style.width = new_image_width + "px";
	
	var main = document.getElementById('main');
	main.style.height = new_image_height + "px";
	main.style.width = new_image_width + "px";
	
	// move text around
	
	var video_meta = document.getElementById('video_meta');
	video_meta.style.width = new_image_width + "px";
	
	var branding_content = document.getElementById('branding_content');
	branding_content.style.width = (new_image_width + 20) + "px";
	
	var main_content = document.getElementById('main_content');
	main_content.style.width = (new_image_width + 20) + "px";
}

function toggleMore() {
	var container = document.getElementById('container');
	var morelink = document.getElementById('morelink');
	
	if(container.style.marginTop != '-440px') {
		container.style.marginTop = '-440px';
		morelink.innerHTML = 'less';
		
	} else {
		container.style.marginTop = '0px';
		morelink.innerHTML = 'more';
	}
}

function fieldFocus(element, text)
{
	if(text == element.value) {
		element.value = "";
	}
}
function fieldBlur(element, text)
{
	if("" == element.value) {
		element.value = text;
	}
}

function muteTracker(obj) {
	alert('the new mute state is: '+obj.state);
}

function timeTracker(obj) {
	//alert('the new TIME state is: '+obj.position);
	var time = obj.position;

	var trackname = document.getElementById('trackname');
	
	if(time < 278) {
		// track 1
		trackname.innerHTML = "Real Live Flesh";
		//alert(obj.position);
	} else if(time < 631) {
		// track 2
		trackname.innerHTML = "Little Tiger";
	} else if(time < 979) {
		// track 3
		trackname.innerHTML = "Powa";
	} else if(time < 1317) {
		// track 4
		trackname.innerHTML = "Hatari";
	} else {
		trackname.innerHTML = "Jumping Jack";
	}
	
};

var player = null; 
function playerReady(thePlayer) {
	player = window.document[thePlayer.id];
	player.addModelListener("TIME","timeTracker");
}

function trackselectchanged(selectobject) {
    
    track = selectobject.options[selectobject.selectedIndex].value;
    
    if(track == 1) {
    	player.sendEvent("SEEK", 15);
    } else if(track == 2) {
    	player.sendEvent("SEEK", 278);
    } else if(track == 3) {
    	player.sendEvent("SEEK", 631);
    } else if(track == 4) {
    	player.sendEvent("SEEK", 979);
    } else if(track == 5) {
    	player.sendEvent("SEEK", 1317);
    }
    
}
