// JavaScript Document
var width_Avail 		= screen.availWidth;
var heigth_Avail 		= screen.availHeight;
window.moveTo(0,0);
window.resizeTo(width_Avail,heigth_Avail);

var navi 		= navigator.appVersion;
var browserIE 	= false;
var browserIE6 	= false;
var browserSAF 	= false;

if(navi.indexOf("MSIE")>-1){
	browserIE = true;
	var navAr = navi.split(";");
	browserIE6 = (parseFloat(navAr[1].split(" ")[2])<=6.0?true:false);
} else if(navi.indexOf("Safari")>-1){
	browserSAF = true;
}


function preloadImages(){
	image_url[0] 				= "gfx/btns/"+language+"/enr.png";
	image_url_active[0] 		= "gfx/btns/"+language+"/enrA.png";
	preload_image_object[0] 	= new Image();
	preload_image_object[0].src = image_url_active[0];
}


function activate(menu_id){
	document.getElementById("btn_"+menu_id).src = preload_image_object[menu_id].src;
}
function disable(menu_id){
	document.getElementById("btn_"+menu_id).src = image_url[menu_id];
}

var current_page		= 0;
var current_sub_page	= 0;
var language			= 0;
var containerwidth		= 1005;
var containerheight		= 700;

var container_top		= 0;
var container_left		= 0;
	
function setInterface(){
	
	
if(!browserSAF){
	var besch_1 	= parseInt((document.documentElement.clientWidth * 1) - 17);
	var besch_2	= parseInt((document.documentElement.clientHeight * 1));
}else{
	var besch_1 	= parseInt((document.documentElement.clientWidth * 1)- 16);
	var besch_2	= parseInt((document.documentElement.clientHeight * 1));
}

  	hoogte  	= containerheight;
	breedte  	= containerwidth;	
	
	pos_x = parseInt((besch_1 - breedte) / 2);
	pos_y = parseInt((besch_2 - hoogte) / 2);
	if(pos_y < 0){
		//pos_y = 0
	}
	container_top 	= 200;
	container_left 	= 142 + pos_x;
	
	$('div_container').setStyle('opacity', 0);
	$('div_container_bg').setStyle('opacity', 0);
	$('div_container_bg1').setStyle('opacity', 0);
	$('div_container_bg2').setStyle('opacity', 0);
	$('div_container_bg3').setStyle('opacity', 0);
	$('div_container_bg4').setStyle('opacity', 0);
	$('div_container_bg5').setStyle('opacity', 0);

//1000
//700
	document.getElementById("div_container_credits").style.left 		= pos_x + 770 +'px';
	document.getElementById("div_container_credits").style.top 			= '650px';
	
	document.getElementById("div_container_bg1").style.left 	= (pos_x) + 232 + 'px';
	document.getElementById("div_container_bg2").style.left 	= (pos_x) + 'px';
	document.getElementById("div_container_bg3").style.left 	= (pos_x) + 700 + 'px';
	document.getElementById("div_container_bg4").style.left 	= (pos_x) + 581+ 'px';
	document.getElementById("div_container_bg5").style.left 	= (pos_x) + 'px';
	document.getElementById("div_container_bg").style.left 		= pos_x + 'px';
	document.getElementById("div_container_bg").style.top 		= '0px';
	document.getElementById("div_container_bg5").style.top 		= '304px';
	document.getElementById("div_container_bg1").style.top 		= 409+'px';
	document.getElementById("div_container_bg2").style.top 		= '0px';
	document.getElementById("div_container_bg3").style.top 		= '298px';
	document.getElementById("div_container_bg4").style.top 		= '0px';
	document.getElementById("div_container_bg").style.display 	= 'block';
	document.getElementById("div_container_bg1").style.display 	= 'block';
	document.getElementById("div_container_bg2").style.display 	= 'block';
	document.getElementById("div_container_bg3").style.display 	= 'block';
	document.getElementById("div_container_bg4").style.display 	= 'block';
	document.getElementById("div_container_bg5").style.display 	= 'block';
	document.getElementById("div_container").style.left 		= container_left + 'px';
	document.getElementById("div_container").style.top 			= container_top + 'px';
	loadContainer();
	
	
	
}

var colors = Array('#ffffff','#2c6fae','#6f845d','#be8e30','#cb64af','#c1214b');

function loadContainer(){
	document.getElementById("div_container").style.display 	= 'block';
	var fx_mouseover = MorpheItems($('menu_anim'), 100, Fx.Transitions.Cubic.easeOut);
	
	var fx_mouse_overs = new Array;
	
	var fx1 = new Fx.Tween($('div_container'), {duration:500, onComplete: function(){ 
			$('div_container_bg').fade(1);
			
			setImages(); 
		
			swf_loaded[0] = true;
			$('div_container_bg1').fade(0.8);
			
			var teller 		= 0
			var menulist 	= $$('#menu_container .navigation_btn');
			menulist.each(function(element) {
			 	
				fx_mouse_overs[teller] = MorpheItems(element, 500, Fx.Transitions.Cubic.easeOut);
				
				teller++;
				
				ChangeAnim('top',$('menu'+teller), 0, teller*400, Fx.Transitions.Back.easeOut);
				
				
				element.addEvent('mouseenter', function(){
					
					var current = parseInt(element.getProperty('name'));
					fx_mouse_overs[current-1].cancel();
					fx_mouse_overs[current-1].start({'background-color': colors[current]})
					
					//fx_mouseover.set({'left': ((parseInt(element.getProperty('name')) - 1) * 77)+(parseInt(element.getProperty('name'))*5), 'background-color': colors[parseInt(element.getProperty('name'))]});
					$('menu_anim').fade(1);
					$('menu_link' + parseInt(element.getProperty('name'))).addClass('active');
					
			
				});
			 
				element.addEvent('mouseleave', function(){
					var current = parseInt(element.getProperty('name'));
					fx_mouse_overs[current-1].cancel();
					fx_mouse_overs[current-1].start({'background-color': '#000000' })
					$('menu_link' + parseInt(element.getProperty('name'))).removeClass('active');
					$('menu_anim').fade('hide');
				});
			 
			});
			
			
			var menulist 	= $$('.sub_navigation_btn');
			menulist.each(function(element) {
				element.addEvent('mouseenter', function(){														
					element.setStyle('border-color',colors[parseInt(element.getProperty('name'))]);											
				});
			 
				element.addEvent('mouseleave', function(){												
					element.setStyle('border-color','#333333');	
				});
			 
			});
			
			diableStandardFields(1);
			
			$('menu_container').addEvent('mouseleave', function(){
				fx_mouseover.set({'left': 400, 'background-color': '#000000'});//ChangeAnim('background-color',element, '#222222', 800, Fx.Transitions.Back.easeOut);
			});
		} 
	});
	
	fx1.options.transition = Fx.Transitions.linear;
	fx1.start('opacity', 1);

	
	setSomeForm('form_contact','contact_form');
	
}

var currentPage = 10;
var allow 		= true;
function setPage(id){	
	if(currentPage!=id && allow == true){
		allow = false;
		var newSlide = id;
		ChangeAlphaAnimGallery(loadedImages[slide], 1, 0, 500, newSlide);
	}
}


function diableStandardFields(show){
	for(i=1;i<6;i++){
		if(show!=i){
			$('div_content_'+i).setStyle('display','none');
			$('div_content_'+i).fade('hide');
		}else{
			$('div_content_'+i).setStyle('display','block');
			$('div_content_'+i).fade(1);
		}
		if($('sub_menu_container_'+i)){
			$('sub_menu_container_'+i).fade(0);
		}
	}
}

var swf_loaded = new Array(false,false,false,false,false);

function loadDate(slide){
	currentPage  = slide;
	switch(currentPage){
		case 0:
			allow = true;
			diableStandardFields(1);
			if(!swf_loaded[0]){
				swf_loaded[0] = true;
				$('div_container_bg1').fade(0.8);
			}
		break;
		case 1:
			allow = true;
			diableStandardFields(2);
			if(!swf_loaded[1]){
				swf_loaded[1] = true;
				$('div_container_bg2').fade(0.8);
			}
		break;
		case 2:
			diableStandardFields(0);
			if($('sub_menu_container_3')){
				$('sub_menu_container_3').fade('hide');
				$('sub_menu_container_3').setStyle('display', 'block');
				$('sub_menu_container_3').fade(1);
			}
			allow = true;
			
			if(!swf_loaded[2]){
				swf_loaded[2] = true;
				$('div_container_bg3').fade(0.7);
			}
		break;
		case 3:
			allow = true;
			diableStandardFields(4);
			
			if(!swf_loaded[3]){
				swf_loaded[3] = true;
				$('div_container_bg4').fade(0.9);
			}

				
			changeMovie('deadline_2010.swf','deadline_2010');
		break;
		case 4:
			allow = true;
			diableStandardFields(5);
			if(!swf_loaded[4]){
				swf_loaded[4] = true;
				$('div_container_bg5').fade(0.8);
			}
		break;
	}		
}

var active_movie = 'movie';
function changeMovie(movie,target_link){
	
	$(active_movie).removeClass('active')
	$(target_link).addClass('active')
	active_movie = target_link;
	
	var sovideo = new SWFObject(movie, "Vivienne van den Assem", "352", "240", "9", "86A098");
	sovideo.addParam("wmode", "transparent"); 
	sovideo.addParam("quality", "high"); 
	sovideo.useExpressInstall('expressinstall.swf');
	sovideo.write("video_1");
}

var album = 0;
function setPageGallery(this_album){
	album 	= this_album;
	loadNshow('gallery.php?album='+album, 'div_content_3', 'get')
}

function loadNshow(url, target, method){
	var preloader = $(target).empty().addClass('loading');
 	var loadOne = new Request({url:url, 
		method: method,
		onComplete: function() {
			allow = true;
			var output 	= loadOne.response.text
			$(target).innerHTML = output;
			
			switch(currentPage){
				case 2:
					$('div_imageBG').setStyle('opacity', 0.5);
					setBigImage('images/gallery'+album+'/',1);
					ChangeAnim('alpha',$('div_content_3'), 1, 500);
					$('div_content_3').setStyle('display','block');
					$('div_content_3').fade(1);
					ChangeAnim('opacity', loadedImages[slide], 0.3, 1000);
				break;
			}
		}
	});
	loadOne.send();
}

function MorpheItems(target, speed, trans){
	if(target){
		return new Fx.Morph(target, {duration: speed, transition: trans});
	}
}

function ChangeAnim(prop, target, to, speed, trans){
	if(target){
		var myFx = new Fx.Tween(target,{duration:speed, transition: trans});
		myFx.start(prop, to );
	}
}

function ChangeAlphaAnimGallery(target, from, to, speed, newSlide){
	var ChangeSize = new Fx.Tween(target, {duration:speed, 
	onComplete: function(){
		//target.remove();
		if((slide==2 || slide == 1 || slide == 4 || slide == 3) && (newSlide!=2 && newSlide != 1 && newSlide != 4 && newSlide != 3)){
			var myMorpher_div_container = MorpheItems($('div_container'), 1000, Fx.Transitions.Cubic.easeOut);
			myMorpher_div_container.start({'top': container_top, 'height': 230});
			var myMorpher_gallery = MorpheItems($('gallery'), 1000, Fx.Transitions.Cubic.easeOut);
			myMorpher_gallery.start({'opacity': 1, 'height': 230, 'width': 230, 'left': 0});
		}
		
		if(slide == 3){
			$('video_1').innerHTML = '';
		}
		
		slide = newSlide;
		//alert(slide);
		if(slide>=loadedImages.length){
			slide 		= 0;
		}
		
		loadDate(slide);
		
		if(slide==1){
			var myMorpher_div_container = MorpheItems($('div_container'), 1000, Fx.Transitions.Cubic.easeOut);
			myMorpher_div_container.start({'top': container_top - 40, 'height': 310});
			var myMorpher_gallery = MorpheItems($('gallery'), 1000, Fx.Transitions.Cubic.easeOut);
			myMorpher_gallery.start({'opacity': 1, 'height': 310, 'width': 310, 'left': 0});
			var myMorpher_image = MorpheItems(loadedImages[slide], 1000, Fx.Transitions.Cubic.easeOut);
			myMorpher_image.start({'height': 310, 'width': 310, 'opacity': 1});
		}else if(slide==2){
			var myMorpher_div_container = MorpheItems($('div_container'), 1000, Fx.Transitions.Cubic.easeOut);
			myMorpher_div_container.start({'top': (container_top - 140), 'height': 520});
			var myMorpher_gallery = MorpheItems($('gallery'), 1000, Fx.Transitions.Cubic.easeOut);
			myMorpher_gallery.start({'opacity': 1, 'height': 520, 'width': 520, 'left': -280});
			var myMorpher_image = MorpheItems(loadedImages[slide], 1000, Fx.Transitions.Cubic.easeOut);
			myMorpher_image.start({'height': 520, 'width': 520, 'opacity': 0.8});
		}else if(slide==4){
			var myMorpher_div_container = MorpheItems($('div_container'), 1000, Fx.Transitions.Cubic.easeOut);
			myMorpher_div_container.start({'top': container_top - 40, 'height': 310});
			var myMorpher_gallery = MorpheItems($('gallery'), 1000, Fx.Transitions.Cubic.easeOut);
			myMorpher_gallery.start({'opacity': 1, 'height': 310, 'width': 310, 'left': 0});
			var myMorpher_image = MorpheItems(loadedImages[slide], 1000, Fx.Transitions.Cubic.easeOut);
			myMorpher_image.start({'height': 310, 'width': 310, 'opacity': 1});
		}else if(slide ==3){
			var myMorpher_div_container = MorpheItems($('div_container'), 1000, Fx.Transitions.Cubic.easeOut);
			myMorpher_div_container.start({'top': container_top - 20, 'height': 325});
			var myMorpher_gallery = MorpheItems($('gallery'), 1000, Fx.Transitions.Cubic.easeOut);
			myMorpher_gallery.start({'opacity': 1, 'height': 325, 'width': 275, 'left': 0});
			var myMorpher_image = MorpheItems(loadedImages[slide], 1000, Fx.Transitions.Cubic.easeOut);
			myMorpher_image.start({'height': 275, 'width': 275, 'opacity': 1, 'top':50});
		}else{
			ChangeAnim('opacity', loadedImages[slide], 1, 500);
		}
		
	},
	transition: Fx.Transitions.linear});
	ChangeSize.start('opacity', to);
}

var busy = false, timer, loadedImages = [], gallery , progress , bar ; 
var path = 'http://www.viviennevandenassem.nl/images/links/';
var images = [
	path + '1.jpg',
	path + '2.jpg', 
	path + '3.jpg', 
	path + '4.jpg', 
	path + '5.jpg'
];

var periodical, dummy; 
var timer = 15; 

function setImages(){
	busy 			= false
	loadedImages 	= []
	gallery 		= $('gallery')
	progress 		= $('progress')
	bar 			= $$('#progress .bar');
	
	progress.setStyle('display', 'block');
	progress.setStyle('visibility', 'hidden');
	 
	if (!busy) {
		var galleryImgs = $$('#gallery img');
		//if (galleryImgs.length > 0) galleryImgs.each(function(image) {	//image.remove();	});
		busy = true;
		progress.setStyle('visibility', 'visible');
		gallery.setStyle('display', 'block');
		new Asset.images(images, {
			onProgress: function(j,i) {
				this.setStyles({
					'position': 'absolute',
					'opacity': 0,
					'left': 0,
					'top': 0
				});
				loadedImages[i] = this;
				var percent = ((i + 1) * progress.getStyle('width').toInt()) / images.length;
				bar.setStyle('width', percent);
				bar.innerHTML = (i + 1 + ' / ' + images.length);
			},
			onComplete: function() {
				progress.setStyle('visibility', 'hidden');
				$('gallery').fade(1);
				loadedImages[0].inject(gallery);
				loadedImages[1].inject(gallery);
				loadedImages[2].inject(gallery);
				loadedImages[3].inject(gallery);
				loadedImages[4].inject(gallery);
				loadedImages[0].fade(1);
				slide = 0;
			}
		});
	}
}


var slide = 0;//tracks which slide is showing
var refreshGallery = (function() {
	ChangeAlphaAnimGallery(loadedImages[slide], 1, 0, 500)				
});

function setSomeForm(target_form,target_name){
	$(target_form).addEvent('submit', function(e){
		new Event(e).stop();
		this.set('send', {
			method: 'post',
			data: $(target_form),                                      
			onSuccess: function(responseText, responseXML) {
				var result = responseText;
				$(target_name).set('html', result);
			}
		});
		this.send(this.action); 
	});		
}

function getContact(){
	$('form_contact').set('send', {
		method: 'post',
		data: $('form_contact'),                                      
		onSuccess: function(responseText, responseXML) {
				var result = responseText;
			$('contact_form').set('html', result);
		}
	});
	$('form_contact').send(this.action); 
}

function checkEmail( field ) {
	veld = field.value;
	//kijk naar formaat: name@site.nl
	var objRegExp  = /^([a-zA-Z0-9_\-])([a-zA-Z0-9_\-\.]*)@(\[((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}|((([a-zA-Z0-9\-]+)\.)+))([a-zA-Z]{2,}|(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\])$/;
	if( veld==null || veld=='')
		$('myspan_contact').innerHTML = 'onjuist emailadres ingevoerd';
	else if( objRegExp.test(veld)==false){
		$('myspan_contact').innerHTML = 'onjuist emailadres ingevoerd';
	}else
		$('myspan_contact').innerHTML = '';
}

function ie6PNGFix(){
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	
	if ((version >= 5.5) && (document.body.filters) && (version <= 6.0)) 
	{
	   for(var i=0; i<document.images.length; i++)
	   {
		  var img = document.images[i]
		  var imgName = img.src.toUpperCase()
		  //alert(imgName);
		  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		  {
			 var imgID = (img.id) ? "id='" + img.id + "' " : ""
			 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			 var imgStyle = "display:inline-block;" + img.style.cssText 
			 if (img.align == "left") imgStyle = "float:left;" + imgStyle
			 if (img.align == "right") imgStyle = "float:right;" + imgStyle
			 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
			 var strNewHTML = "<span " + imgID + imgClass + imgTitle
			 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
			 img.outerHTML = strNewHTML
			 i = i-1
		  }
	   }
	}	
}

//gallery

var newX        = 0;
var newY		= 0; 
var oldX 		= 500
var oldY 		= 500;
var imageB 		= new Array();
var loadedBig 	= new Array();
var busyBig		= false;
var galleryBig;
function setBigImage(folder, nr){
	imageB = [
		folder + nr + '.jpg'
	];
	
	galleryBig 		= $('div_image')
	 
	if (!busyBig) {
		var galleryBigImgs = $$('#div_image img');
		if (galleryBigImgs.length > 0){
			galleryBigImgs.each(function(image) {
				var RemoveImage = new Fx.Tween($('div_image'), {duration:500, 
					onComplete: function(){
					image.destroy();	
					loadNewImage();
				},
				transition: Fx.Transitions.linear});
				RemoveImage.start('opacity', 0);															
			});
			busyBig = true;
		}else{
			galleryBig.setStyle('display', 'block');
			loadNewImage();	
		}
	}
}

function loadNewImage(){
	new Asset.images(imageB, {
		onProgress: function(i) {
			this.setStyles({
				'position': 'absolute',
				'opacity': 0
			});
			loadedBig[i] = this;
			newX = this.width;
			newY = this.height;
		},
		onComplete: function() {
			$('div_image').fade(1);
			$('div_image').setStyle('left', 7 + (450-newX));
			//$('div_image').setStyle('top', 7);
			loadedBig[0].inject(galleryBig);
			var fxBG = new Fx.Morph($('div_imageBG'), {duration: 1000, transition: Fx.Transitions.Cubic.easeOut,onComplete: function() {
					ChangeAnim('opacity', loadedBig[0], 1, 500);
				}});
			fxBG.start({
				'width': newX + 9,
				'height': newY + 9,
				'left': 1+ (459-(newX+9))
			});
			busyBig  = false			
		}
	});
}

var scrollSpeed = 50;
var scrollHeight= 10;

function scrollStart(direction, divID, elementID){
	ourInterval = setInterval("move"+direction+"('"+divID+"')", scrollSpeed);
}

function scrollEnd(which){
	//document.getElementById(which).style.backgroundColor = origColor;
	clearInterval(ourInterval);
}
function moveUp(which){
	document.getElementById(which).scrollTop = document.getElementById(which).scrollTop - scrollHeight;	
}
function moveDown(which){
	//alert(which);
	document.getElementById(which).scrollTop+=scrollHeight;	
}
