// JavaScript Document

item_page_array 	= new Array('','SWFINLADEN','SWFINLADEN','SWFINLADEN','','','');
content_folder 		= new Array('','home','sunglasses','watches','dealers','contact','credits','media');
start_content 		= new Array('','flow_home.php','flow_glasses.php','flow_watches.php','flow_index.php','flow_contact.php','flow_credits.php','flow_media.php');

load_innercontent	= new Array('',0,0,0,0,0,0);
swfLoad				= new Array('',false,false,false,false,false,false,false);
class_array 		= new Array('','home','sunglasses','watches','dealers','contact','contact','media');
categories_array 	= new Array('',0,0,0,0,0,0);
pages_array 		= new Array('',7,'','','',8,'');
gallery_type		= new Array('',0,2,2,0,0,0);
//side positions
sidepositions_array = new Array(new Array(),new Array(),new Array(),new Array(),new Array());


//gallery V2
function setGalleryVars(){
	switch(active_current){
		case 2:
		active_category = 1;
		active_gallery 	= 0;
		break;
	}
}

function LoadPageAll(){
	//alert(innerHeight)
	if(innerHeight<600){
		$('bg2').setStyle('display', 'none');
		if(innerHeight<566){
			innerHeight = 566;
		}
	}
	
	$('main_container').setStyle('left' , 0);
	$('main_container').setStyle('top' , 0);
	
	$('main_container').setStyle('width' , innerWidth);
	$('main_container').setStyle('height' , innerHeight);
	
	$('bg1').setStyle('left', middleX - 55);
	$('bg2').setStyle('left', middleX - 211);
	$('bg2').setStyle('top', (innerHeight - 130 - 132)/2 - 211 + 130);
	
	$('site_menu').setStyle('left', middleX - 280);
	$('go_home').setStyle('left', innerWidth - 120);
	
	//small logo  + "header" 
	//131 + 132 
	//max! --> 600
	//height 600 - 263 = 337 --> 338
	//pos --> centered!
	$('flow_content').setStyle('width', innerWidth);
	$('inner_content_menu').setStyle('width', innerWidth);
	$('content').setStyle('top',(innerHeight - 130 - 132)/2 - 169 + 130);

	$('header').setStyle('width', innerWidth);
	
	$('footer').setStyle('top', innerHeight - 95);
	$('footer').setStyle('width', innerWidth);
	$('credits').setStyle('left', innerWidth - 110);
	
	
	
	menulist	= $$('.navigation_div');
	menulist.each(function(element) {
		var current = parseInt(element.getProperty('id').substring(4));
		fx_mouse_overs[current] = MorpheItems('menu'+current, 800, Fx.Transitions.Cubic.easeOut);
		
		element.addEvent('mouseenter', function(){ 
			var current = parseInt(element.getProperty('id').substring(4));
			if(active_current!=current){
				fx_mouse_overs[current].cancel();
				fx_mouse_overs[current].start({'color': '#bbbbbb', 'top': 5});
			}
		});
		element.addEvent('mouseleave', function(){
			var current = parseInt(element.getProperty('id').substring(4));
			if(active_current!=current){
				fx_mouse_overs[current].cancel();
				fx_mouse_overs[current].start({'color': '#a0a0a1', 'top': 10});
			}	
		});
		element.addEvent('click', function(){
			var current = parseInt(element.getProperty('id').substring(4));
			fx_mouse_overs[current].cancel();
			fx_mouse_overs[current].start({'color': '#ffffff', 'top': 15});
			processPreClick(current, '?include_header=1');
		});
   	});
	
	if(active_current!=0){
		//fx_mouse_overs[active_current].start({'top': 20});
	}
	
	fx_inner_content 	 		= MorpheItems('inner_content', 500, Fx.Transitions.Cubic.easeOut);
	fx_inner_content_menu 		= MorpheItems('inner_content_menu', 500, Fx.Transitions.Cubic.easeOut);
	
	//setSomeForm('newsletter');
	
	$('load_container').setStyle('display' , 'none');
	$('main_container').setStyle('opacity' , 0);
	$('main_container').setStyle('display' , 'block');
	$('main_container').setStyle('opacity' , '1');
	
		
	if(flash_can){
		//setSomeSWF('slideshow.swf', 'STUDIOSOO', '100%', '100%', 'inner_content', '');
	}else{
		//nonflash
		
	}
	
	
	if($('dealers_search_options')){
		active_current = 3;
			ChangeAnim('opacity', 'bg2', 1, 500, Fx.Transitions.Sine.easeOut);
			//activate dropdown!
			$('dealers_search_container').setStyle('left', (innerWidth - 390));
			
			
			var breedte_dealers	= Math.abs(innerWidth * 4/5);
			
			if(breedte_dealers < 900){
				breedte_dealers = 900
			}
			
			$('dealer_results').setStyle('width', breedte_dealers);
			$('dealer_results').setStyle('left', (innerWidth - breedte_dealers));
			
			loadDropDownActions('search_optionprovincie');
			loadDropDownActions('search_optionstad');
	}
}


function CollectionPage(page){
	
	var TipRemove = $$('.tip');
	TipRemove.each(function(element) {
		element.destroy();
	});
	collection_pos			= 1;
	loadNshow(content_folder[active_current]+'/'+start_content[active_current]+'?include_header=1&page='+page, 'inner_content_menu', 'get', false);					
}


var active_collection 		= 0;
var mouse_set_to_navigate	= false;
var collection_pos			= 1;

function processAfterClick(target){
	switch(active_current){
		case 1:
			ChangeAnim('opacity', 'bg2', 1, 500, Fx.Transitions.Sine.easeOut);
		break;
		case 5:
			ChangeAnim('opacity', 'bg2', 1, 500, Fx.Transitions.Sine.easeOut);
		break;
		case 2:
		case 3:
			active_collection 				= 0;
			var collection_divs				= $$('.collection_divs');
			var fx_mouse_overs_collection	= new Array;
			
			ChangeAnim('opacity', 'bg2', 0, 500, Fx.Transitions.Sine.easeOut);
	
			$('label_scrollable_content').setStyle('left', middleX - 399);
			$('page_navigation').setStyle('left', middleX - 260);
			
			
			$('page_navigation_prev_20').setStyle('left', middleX - 290);
			$('page_navigation_nxt_20').setStyle('left', middleX + 260);
			
			if(!browserIE){
				var TipsInBasket = new Tips($$('.the_nav'),{ fixed: false, showDelay: 0, hideDelay: 0, offsets: {'x': 15, 'y': -15} });
			}		
			collection_divs.each(function(element) {
				var current = parseInt(element.getProperty('id').substring(11));
				fx_mouse_overs_collection[current] = MorpheItems('collection_'+current, 800, Fx.Transitions.Cubic.easeOut);
				
				element.setStyle('opacity',0.2);
				$('page_nav_'+current).setStyle('opacity',0.4);
				
				element.addEvent('click', function(){
					var current = parseInt(element.getProperty('id').substring(11));
					if(current!=active_collection){
						if(current != collection_pos){
							var to_move = current - collection_pos;
							moveBar(to_move);
							/*if(to_move > 0){
								ChangeAnim('left', 'label_scrollable_content', middleX - 399 - (current * 266), 500, Fx.Transitions.Sine.easeOut);
							}else{
								ChangeAnim('left', 'label_scrollable_content', middleX - 399 - ((current - 1) * 266), 500, Fx.Transitions.Sine.easeOut);
							}*/
						}
					}
					//openBigImage();
				});
			});
			
			$('collection_1').setStyle('opacity', 1);
			$('collection_2').setStyle('opacity', 0.6);
			$('page_nav_1').setStyle('opacity', 1);
			$('page_nav_2').setStyle('opacity', 0.6);
			$('page_nav_1').setStyle('font-size', 13);
			$('page_nav_2').setStyle('font-size', 11);
			
			$('scroll_right').setStyle('left', (innerWidth - 71));
			
			
			
			var myElement 	= $('scroll_right');
			myElement.addEvent('mouseenter', function(event){
				
				mouse_set_to_navigate 	= true	
				setNextCollection();
				
				mouse_set_to_navigate 	= false;
				direction_scroll		= 1;
				
				interval_scroll 		= processNavigation.periodical(800)
			});
			
			myElement.addEvent('mouseleave', function(event){
				$clear(interval_scroll);
				direction_scroll		= 0;
				mouse_set_to_navigate = false	
			});
			
			var myElement 	= $('scroll_left');
			myElement.addEvent('mouseenter', function(event){
				
				mouse_set_to_navigate 	= true	
				setPrevCollection();
				
				mouse_set_to_navigate 	= false;
				direction_scroll		= -1;
				
				interval_scroll			= processNavigation.periodical(800)
			});
			
			myElement.addEvent('mouseleave', function(event){
				$clear(interval_scroll);
				direction_scroll		= 0;
				mouse_set_to_navigate = false	
			});
		break;
		case 4:
			
			ChangeAnim('opacity', 'bg2', 1, 500, Fx.Transitions.Sine.easeOut);
			//activate dropdown!
			$('dealers_search_container').setStyle('left', (innerWidth - 390));
			
			
			var breedte_dealers	= Math.abs(innerWidth * 4/5);
			
			if(breedte_dealers < 900){
				breedte_dealers = 900
			}
			
			$('dealer_results').setStyle('width', breedte_dealers);
			$('dealer_results').setStyle('left', (innerWidth - breedte_dealers));
			
			loadDropDownActions('search_optionprovincie');
			loadDropDownActions('search_optionstad');
			
		break;
		case 7:
		
			var breedte_dealers	= Math.abs(innerWidth * 4/5);
			$('dealer_div_content').setStyle('width', breedte_dealers);	
		break;
	}
	
	$(target).addEvent('domready', function() {
		fx_inner_content_menu.cancel();
		fx_inner_content_menu.start({'opacity': 1});
	});	
}


function processAfterClickDropdown(childof, tempval){
	switch(childof){
		case 'provincie':
			//laad steden
			$('stad_container').setStyle('opacity', 0);
			loadNshow(content_folder[active_current]+'/flow_steden.php?include_header=1&provincie='+tempval, 'stad_container', 'get', false);
			//loadNshow(content_folder[active_current]+'/flow_dealers.php?include_header=1&provincie='+tempval, 'dealer_results', 'get', false);
			//laad result van provincie...
		break;
		case 'stad':
			//laad result van stad...
			//alert(content_folder[active_current]+'/flow_dealers.php?include_header=1&stad='+tempval);
			active_option	= 0;
			loadNshow(content_folder[active_current]+'/flow_dealers.php?include_header=1&stad='+tempval, 'dealer_results', 'get', false);
		break;
	}
}


function openCredits(){
	processPreClick(6, '?include_header=1')
}

function processPreClick(current, query){
	if(current!=active_current && allow_click == true){
		allow_click = false;
		
		if(active_current!=0 && active_current!=6){
			fx_mouse_overs[active_current].cancel();
			fx_mouse_overs[active_current].start({'top': 10, 'color': '#a0a0a1'});
		}
		processClick(current, query);
		active_current	= current;
		allow_click 	= true;
	}else{
		//alert(allow_click + ' - ' + active_current);	
	}
}

function resizing(){
	//$('main_container').setStyle('opacity' , 0);
	if(!browserSAF){
		innerWidth 	= parseInt((document.documentElement.clientWidth * 1));
		innerHeight	= parseInt((document.documentElement.clientHeight * 1));
	}else{
		innerWidth 	= parseInt((document.documentElement.clientWidth * 1));
		innerHeight	= parseInt((document.documentElement.clientHeight * 1));
	}
	middleX				= innerWidth / 2;
	middleY				= innerHeight / 2;
	
	ChangeAnim('width', 'main_container', innerWidth, 400, Fx.Transitions.Sine.easeOut);
	ChangeAnim('height', 'main_container', innerHeight, 400, Fx.Transitions.Sine.easeOut);
	
	ChangeAnim('left', 'bg1', middleX - 55, 400, Fx.Transitions.Sine.easeOut);
	ChangeAnim('left', 'bg2', middleX - 211, 400, Fx.Transitions.Sine.easeOut);
	ChangeAnim('top', 'bg2', (innerHeight - 130 - 132)/2 - 211 + 130, 400, Fx.Transitions.Sine.easeOut);
	
	ChangeAnim('left', 'site_menu', middleX - 280, 400, Fx.Transitions.Sine.easeOut);
	
	ChangeAnim('width', 'flow_content', innerWidth, 400, Fx.Transitions.Sine.easeOut);
	ChangeAnim('width', 'inner_content_menu', innerWidth, 400, Fx.Transitions.Sine.easeOut);
	ChangeAnim('top', 'content', (innerHeight - 130 - 132)/2 - 169 + 130, 400, Fx.Transitions.Sine.easeOut);
	
	ChangeAnim('top', 'footer', innerHeight - 95, 400, Fx.Transitions.Sine.easeOut);
	ChangeAnim('width', 'footer', innerWidth, 400, Fx.Transitions.Sine.easeOut);
	ChangeAnim('width', 'header', innerWidth, 400, Fx.Transitions.Sine.easeOut);
	
	ChangeAnim('left', 'go_home', innerWidth - 120, 400, Fx.Transitions.Sine.easeOut);
	
	
	
}


var direction_scroll	= 0;
var interval_scroll	= 0;

var processNavigation = function(){ 
	if(direction_scroll > 0){
		if(mouse_set_to_navigate == false && collection_pos < $('aantal_thumbs').value ){
			mouse_set_to_navigate = true	
			setNextCollection.delay(0);
		}
	}else if(direction_scroll < 0){
		if(mouse_set_to_navigate == false && collection_pos > 1 ){
			mouse_set_to_navigate = true	
			setPrevCollection.delay(0);
		}
	}else{
		mouse_set_to_navigate = false
	}
}

var setNextCollection 	= function (){
	if(mouse_set_to_navigate==true){
		mouse_set_to_navigate	= false;
		moveBar(1);
	}
}

var setPrevCollection = function (){
	if(mouse_set_to_navigate==true){
		mouse_set_to_navigate	= false;
		moveBar(-1);
	}
}

function collectionGoTo(goto){
	//alert(goto);
	//alert(collection_pos);
	var direction = goto - collection_pos;
	if(gallery_open){
		if(direction > 0 || direction < 0 ){
			openBigImage(currentFolder,imageURLS[currentImageIndex + (direction - 1)],currentImageIndex + direction, imageTTLS[currentImageIndex + (direction - 1)], '');		
		}
	}
	moveBar(direction);
	
	
}

function moveBar(direction){
	
	if(direction>1 || direction <-1){
		//grotere sprongen...dus de oude ook deactiveren!
		if($('collection_'+(collection_pos-1))){
			ChangeAnim('opacity', 'collection_'+(collection_pos-1), 0.2, 200, Fx.Transitions.Sine.easeOut);
			$('page_nav_'+(collection_pos-1)).setStyle('opacity', 0.4);
			$('page_nav_'+(collection_pos-1)).setStyle('font-size', 10);
			$('page_nav_'+(collection_pos-1)).setStyle('font-weight', 'normal');
		}
		
		if($('collection_'+collection_pos)){
			ChangeAnim('opacity', 'collection_'+collection_pos, 0.2, 200, Fx.Transitions.Sine.easeOut);
			$('page_nav_'+collection_pos).setStyle('opacity', 0.4);
			$('page_nav_'+collection_pos).setStyle('font-size', 10);
			$('page_nav_'+collection_pos).setStyle('font-weight', 'normal');
		}
		if($('collection_'+(collection_pos+1))){
			ChangeAnim('opacity', 'collection_'+(collection_pos+1), 0.2, 200, Fx.Transitions.Sine.easeOut);
			$('page_nav_'+(collection_pos+1)).setStyle('opacity', 0.4);
			$('page_nav_'+(collection_pos+1)).setStyle('font-size', 10);
			$('page_nav_'+(collection_pos+1)).setStyle('font-weight', 'normal');
		}
	}
	
	if(direction >= 1){
	ChangeAnim('left', 'label_scrollable_content', middleX - 399 - ((collection_pos + direction - 1) * 266), 500, Fx.Transitions.Sine.easeOut);
	}else{
	ChangeAnim('left', 'label_scrollable_content', middleX - 399 - ((collection_pos + direction - 1) * 266), 500, Fx.Transitions.Sine.easeOut);
	}

	collection_pos = collection_pos + direction;
	
	if($('collection_'+(collection_pos-2))){
		ChangeAnim('opacity', 'collection_'+(collection_pos-2), 0.2, 500, Fx.Transitions.Sine.easeOut);
		$('page_nav_'+(collection_pos-2)).setStyle('opacity', 0.4);
		$('page_nav_'+(collection_pos-2)).setStyle('font-size', 10);
		$('page_nav_'+(collection_pos-2)).setStyle('font-weight', 'normal');
	}
	if($('collection_'+(collection_pos-1))){
		ChangeAnim('opacity', 'collection_'+(collection_pos-1), 0.6, 500, Fx.Transitions.Sine.easeOut);
		$('page_nav_'+(collection_pos-1)).setStyle('opacity', 0.6);
		$('page_nav_'+(collection_pos-1)).setStyle('font-size', 11);
		$('page_nav_'+(collection_pos-1)).setStyle('font-weight', 'normal');
	}
	
	if($('collection_'+collection_pos)){
		ChangeAnim('opacity', 'collection_'+collection_pos, 1, 500, Fx.Transitions.Sine.easeOut);
		$('page_nav_'+collection_pos).setStyle('opacity', 1);
		$('page_nav_'+collection_pos).setStyle('font-size', 13);
		$('page_nav_'+collection_pos).setStyle('font-weight', 'bold');
	}
	if($('collection_'+(collection_pos+1))){
		ChangeAnim('opacity', 'collection_'+(collection_pos+1), 0.6, 500, Fx.Transitions.Sine.easeOut);
		$('page_nav_'+(collection_pos+1)).setStyle('opacity', 0.6);
		$('page_nav_'+(collection_pos+1)).setStyle('font-size', 11);
		$('page_nav_'+(collection_pos+1)).setStyle('font-weight', 'normal');
	}
	if($('collection_'+(collection_pos+2))){
		ChangeAnim('opacity', 'collection_'+(collection_pos+2), 0.2, 500, Fx.Transitions.Sine.easeOut);
		$('page_nav_'+(collection_pos+2)).setStyle('opacity', 0.4);
		$('page_nav_'+(collection_pos+2)).setStyle('font-size', 10);
		$('page_nav_'+(collection_pos+2)).setStyle('font-weight', 'normal');
	}
}


