// JavaScript Document
function LoadPageAll(){
	firstResize();
	window.onresize = function goResize(){resizing();}
	initVideoWerkwijze();
}

function initVideoWerkwijze(){
	if(browserIE && browserIE9 == false){
	//if(!browserIE){
		var obj = new Swiff('http://www.luckydubz.com/video-promo/video.swf', {
			id: 'video_container_movie',
			container: $('video_container_IE'),
			width: '100%',
			height: '100%',
			params: {
				wmode: 'window',
				bgcolor: '#000000'
			},
			vars: {
				direct_ttl: 'Lucky Dubz',
				direct_url: 'http://www.luckydubz.com/video-promo/luckydubz.mp4',
				v_width: innerWidth,
				v_height: innerHeight
			}
		})
	}else{
		playtoggle		= $('playtoggle');
		processed		= $('processed');
		guttertrack		= $('guttertrack');
		gutter			= $('gutter');
		handle			= $('handle');
		time			= $('time');
		video			= $('video_container');
		loadingvideo	= $('loadingvideo');
		controls		= $('controls');
		controls_bg		= $('controls_bg');
	
		
		processed_volume		= $('processed_volume');
		guttertrack_volume		= $('guttertrack_volume');
		gutter_volume			= $('gutter_volume');
		handle_volume			= $('handle_volume');
		
		//controls_bg.setStyle('opacity',0.6);
		//controls.setStyle('display','block');
		
		/*video.addEventListener("loadstart", function() { alert(1); }, true);
		video.addEventListener("empty", function() { alert(2); }, true);
		video.addEventListener("canplay", function() { alert(3); }, true);*/
		
		video_refresher	= videoStatus.periodical(100);
	}
}


var minWidth		= 900; //buffert of 20! basic width = 916 rounded gives 920 + 20
var minHeight		= 600; //buffert of 20! basic width = 916 rounded gives 920 + 20
function firstResize(){
	
	//if(q_str_page!='blog'){
		if(document.documentElement.clientWidth){
		
			innerWidth 	= getDocWidth();
			innerHeight	= getDocHeight();
			
			if(innerWidth<minWidth){
				innerWidth 	= minWidth;
			}
			if(innerHeight < minHeight){
				if(!browserIE){
					innerWidth 	= parseInt(innerWidth - 17);
				}
				innerHeight = minHeight;
				has_scroll	= true;
			}
		}else{
			innerWidth 	= minWidth;
			innerHeight = minHeight;
		}
	//}else{
	//	innerWidth 	= parseInt((document.documentElement.clientWidth * 1)) - 17;
	//	innerHeight = 0;
	//}
	positionAfterResize();
	
}
var browserIE
function resizing(){
	if(document.documentElement.clientWidth){
			innerWidth 	= parseInt((document.documentElement.clientWidth * 1));
			innerHeight	= parseInt((document.documentElement.clientHeight * 1));
		if(innerWidth<minWidth){
			innerWidth 	= minWidth;
		}
		if(innerHeight < minHeight){
			if(innerHeight > minHeight){ 
				if(!browserIE){
						innerWidth 	= parseInt((document.documentElement.clientWidth * 1) - 17);
					
				}
			}
			innerHeight = minHeight;
			has_scroll	= true;
		}
	}else{
		innerWidth 	= minWidth;
		innerHeight = minHeight;
	}
	positionAfterResize();
					
}

function positionAfterResize(){
	middleX				= innerWidth / 2;
	middleY				= innerHeight / 2;
	
	var verhouding_video	= 1280 / 720;
	var verhouding_page		= innerWidth / innerHeight;
	var this_hoogte;
	var this_breedte;
	var this_left 	= 0;
	var this_top	= 0;
		
	if(verhouding_video > verhouding_page){
		var temp_hoogte_image 	= innerHeight;
		this_breedte			= parseInt(temp_hoogte_image * verhouding_video)
		this_hoogte				= temp_hoogte_image;
		this_left				= ((innerWidth - this_breedte)/2)
	}else{
		var temp_breedte_image 	= innerWidth;
		this_hoogte				= parseInt(temp_breedte_image / verhouding_video)
		this_breedte			= temp_breedte_image;
		this_top				= ((innerHeight - this_hoogte)/2)
	}
	//console.log(innerWidth);
	//console.log(this_breedte);
	
	$('loadingvideo').setStyles({'width' : innerWidth, 'display':'block'});
	$('video_player').setStyles({'width' : innerWidth, 'height' : innerHeight});
	$('video_container').setStyles({'width' : this_breedte, 'height' : this_hoogte, 'top' : this_top, 'left' : this_left});
	$('video_container_IE').setStyles({'width' : this_breedte, 'height' : this_hoogte, 'top' : this_top, 'left' : this_left});
}

function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

function getDocWidth() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollWidth, D.documentElement.scrollWidth),
        Math.max(D.body.offsetWidth, D.documentElement.offsetWidth),
        Math.max(D.body.clientWidth, D.documentElement.clientWidth)
    );
}
