//JavaScript Document
var navi 			= navigator.appVersion;
var browserIE 		= false;
var browserIE6 		= false;
var browserIE8		= false;
var browserSAF 		= false;
var scrollSpeed 	= 50;
var scrollHeight	= 10;
var notification 	= '';

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

var width_Avail 	= screen.availWidth;
var heigth_Avail 	= screen.availHeight;
var innerWidth 		= 0;
var innerHeight 	= 0;
var middleX			= innerWidth / 2;
var middleY			= innerHeight / 2;

var shopping_hack 	= false;
var currentPage;

/*menu*/
var menuList;
var openProd 				= 0;
var openProdCounter			= 0;
var fx_ani_row				= new Array();
var fx_ani_listing_plus		= new Array();
var varY					= 145

var root_domain				= 'http://www.doopproducts.com/';


function pageInit(page, menu){
	currentPage	= page;
	openMenu	= menu;
		
	if(browserIE6==true){
		var notification		= 'You are currently using Internet Explorer 6.0. For optimal perfomance: upgrade to <a href="http://www.microsoft.com/windows/downloads/ie/getitnow.mspx" target="_blank">Internet Explorer 7.0</a> or try <a href="http://www.mozilla.com/en-US/firefox/" target="_blank">Mozilla Firefox</a>.';
		$('header_notification').innerHTML = notification;
		$('header_notification').setStyle('display','block');
	}
	
	projectList			= $$('.menu_row_cat');
	resizing();
	
	if($('add_product')){
		productInit();
	}
	setSorting();
	
	menulist			= $$('.menu_row_cat');
	menulist.each(function(element) {
		//var current = parseInt(element.getProperty('id').substring(9));
		
		element.addEvent('mouseenter', function(event){ 
			var current = parseInt(element.getProperty('id').substring(9));
			//activate(current);
		});
		element.addEvent('mouseleave', function(){
			var current = parseInt(element.getProperty('id').substring(9));
			//disable(current);
		});
		
   	});
	
	switch(page){
		case "home":
			active_current	= 1;
			if($('home_slide')){
				setSomeSWF(root_domain+'header_site.swf', 'ABOUT ELOISE', 745, 380, 'home_slide', '');
			}
		break;
		case "about":
			active_current	= 2;
		break;
		case "catalog":
			active_current	= 3;
			initDoopSpecs();
		break;
		case "shopping_cart":
			active_current	= 4;
			
			activateMarketing();
		break;
		case "login":
			active_current	= 5;
			//activate(5);
		break;
		case "register":
			active_current	= 6;
			//activate(6);
			setRegisterPage();
		break;
		case "account":
			active_current	= 6;
			//activate(7);
		break;
		default:
			if($('scroll-container')){
				updateScroll('container_page_scrollable', 'container_page');
			}
		break;
	}
	initCountries();
	initLanguages();
	
	var myElement 	= $(document.body);
	var allow_bg 	= true;
	var fx_body		= new Fx.Morph(myElement, {duration: 3500, transition: Fx.Transitions.Cubic.easeOut, onComplete:function(){
		allow_bg	= true;
	}});
	
	if($('slide_image')){
		setSlideBase();
	}
	
	myElement.addEvent('mousemove', function(){
		if(allow_bg){
			allow_bg	= false;
			fx_body.cancel();
			fx_body.start({'background-color':ColorWays[Math.floor(Math.random()*9)]});
		}
	});
	
}

function setRegisterPage(){
	$('country').addEvent('change', function(){
    	var country = parseInt($('country').value);
		
		//load corresponding states
		$('zoneSelecter').addClass('loading');
		$('zoneSelecter').innerHTML = '';
		$('zoneSelecter').load('flow_zoneSelecter.php?country='+country)
		
		if(country > 0){
			$('hairdressers').innerHTML = '';
			var url				= 'flow_hairdressersList.php?country='+country;
			var reqKappers	 	= new Request({url:url, method: 'get',
			onSuccess: function(responseText) {
				$('hairdressers').innerHTML = responseText;
			}});
			reqKappers.send();
		}
	});
	
	$('noDoopCode').addEvent('click', function(){
		if($('noDoopCode').checked){
			ChangeAnim('height', 'hairdressers', 105, 500, Fx.Transitions.Cubic.easeOut);
			$('doop_code').value 				= '';
			$('your_hairdressers').innerHTML 	= '';
			doopcodeCheck 						= false;
			ChangeAnim('height', 'your_hairdressers', 0, 400, Fx.Transitions.Cubic.easeOut);
		}else{
			$('doop_code').value 				= '';
			ChangeAnim('height', 'hairdressers', 0, 500, Fx.Transitions.Cubic.easeOut);
		}
	});	
	
	$('doop_code').value 				= '';
			
}

function updateScroll(target, scroll_in){
	var this_height 		= '';
	var container_height 	= '';
	
	if(browserIE){
		this_height 		= $(target).offsetHeight + 150;
		container_height 	= $(scroll_in).offsetHeight;
	}else{
		this_height 		= $(target).getHeight();
		container_height 	= $(scroll_in).getHeight();
	}
	
	if(container_height < this_height){
		activeScrollElement 	= $(scroll_in);
		activeScroll 			= new Fx.Scroll(activeScrollElement);
		scrollPosition			= 0;
		activeScrollHeight		= this_height - container_height;
		activeScroll.set(0, scrollPosition);
		
		$('scroll-container').setStyle('display','block');
		$('scroll-container').setStyle('opacity',1);
		
		mySlider = new Slider('scroll-container', 'scroller', {
			range: [0,800],
			wheel: false,
			steps: 100,
			snap: true,
			mode: 'vertical',
			onChange: function(pos){
				scrollPosition	= pos/700 * activeScrollHeight;
				activeScroll.set(0, scrollPosition);
			}
		});
	}else{
		scrollPosition		= 0;
		$('scroll-container').setStyle('opacity',0.1);
	}
}
var active_name_search					= false;
function checkSearchName(input){
	if(input.length > 2){
		if(!active_name_search){
			active_name_search				= true;
			mySpinner_search 				= new Spinner('items_suggest');
			mySpinner_search.show(true);
			loadNshow(root_domain + 'aShop/name_search.php?include_header=1&search='+input,'items_suggest', 'get', false);
		}
	}else{
		$('items_suggest').innerHTML					= '';	
	}
}

function initNameSearch(input){
	if(input == 'search'){
		$('zoek_woord').value					= '';
		$('items_suggest').innerHTML			= '';
	}
}

var has_scroll  = false;
function resizing(){
	//$('main_container').setStyle('opacity' , 0);
	if(!browserSAF){
		if(browserIE && browserIE8 == false){
			innerWidth 	= parseInt((document.documentElement.clientWidth * 1));
		}else{
			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));
	}
	
	if(innerHeight < 850){
		innerHeight = 850;
		if(!browserIE && has_scroll == false){
			//alert(has_scroll)
			if(!browserSAF){
				innerWidth 	= parseInt((document.documentElement.clientWidth * 1) - 17);
			}else{
				innerWidth 	= parseInt((document.documentElement.clientWidth * 1) - 16);
			}
		}
		has_scroll 	= true;
	}else{
		has_scroll 	= false;
	}
	
	
	if(innerWidth<1000){
		innerWidth = 1000;
	}
	middleX				= innerWidth / 2;
	middleY				= innerHeight / 2;
	
	if($('slides_container')){
	$('slides_container').setStyle('width' , innerWidth);
	$('slides_container').setStyle('height' , innerHeight);
	proportions_site 		= innerHeight/innerWidth;
	resizeBG();
	}
	/*
	varY = middleY - 300;
		if(varY < 145){
			varY = 145
		}
	
	$('div_container').setStyles({'width': innerWidth, 'height': innerHeight, 'left': 0});
	else if(currentPage == 'catalogus' || openMenu > 0){
		$('header').setStyles({'width': innerWidth, 'height': varY});
		$('div_menu').setStyles({'width': 350, 'top': varY});
		$('div_content_shop').setStyles({'width': innerWidth - 100, 'left': 100, 'top': middleY - 140, 'height': 280});
		$('div_menu_container').setStyles({'left': -150});
	}
	
	$('footer').setStyle('top' , (innerHeight - 20));
	$('footer').setStyle('width' , (innerWidth));
	if($('div_content_3')){
		$('div_content_3').setStyle('left' , (innerWidth - 190) , 'top' , (varY - 40));
	}

	$('div_content_item_background').setStyles({'width': innerWidth, 'height': innerHeight, 'opacity':0.7});
	$('div_content_item_container').setStyles({'left': middleX - 400, 'top': middleY - 280});
	
	if(currentPage == 'catalogus'){
		if(openMenu!=0){
			AJAXopen	= false;
			setMenu(openMenu);
			initListing();
		}
	}
	*/
	
	
	if(innerWidth > 1100){
		//$('side_label').setStyle('display','block');		
	}
	
	$('div_container').setStyle('display','block');
	
}


var proportions_site;


var mySpinner;
var navigating				= false;
var projectList;
var openMenu 				= 0;
var openCat					= 0;
var AJAXopen				= true;
var fx_ani_row				= new Array();
var fx_ani_listing_plus		= new Array();
var fx_menu_container;
var fx_label_scrollable_content;
var fx_content_shop;

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 );
	}
}

var active_collection 			= 0;
var collection_pos				= 0;
var fx_mouse_overs_collection 	= new Array();
var fx_collection_infos 		= new Array();
var product_ids;

function loadNshow(url, target, method){
	var req = new Request({url: url,
	    method: method,
	   	onSuccess: function(responseText) {
			var output 			= req.response.text
			afterLoadProcess(target, output)
		},
		onFailure: function() {
			$(target).set('innerHTML', 'The request failed.');
		}
	});
	req.send();
}


var addedMessage	= false;
function afterLoadProcess(target, output){
	switch(target){
		case 'items_suggest':
			$(target).innerHTML 	= output;
			$(target).addEvent('domready', function() {
				active_name_search	= false;
				mySpinner_search.toggle(target);
				mySpinner_search.destroy()
				$(target).setStyles({'opacity': 1});
			});
		break;
		case 'div_content_shop':
			$('div_content_shop').setStyle('opacity',0);
			$('div_content_shop').innerHTML = output;
	
			initListing();
			
		break;
		case 'div_content_item_container':
			
			$(target).setStyle('opacity',0);
			$(target).innerHTML = output;
			$(target).setStyle('opacity',1);
			
			productInit();
															
		break;
		case 'div_content_3_container':
			$(target).setStyle('opacity',0);
			$(target).innerHTML = output;
			$(target).setStyle('opacity',1);
			
			closeAddMessage();
			
			var myDiv = new Element('div');
			myDiv.setProperty('id','itemAdded');
			myDiv.setProperty('class','itemAdded');
			myDiv.setStyle('opacity',0.8);
			
			if(mouseX){
				myDiv.setStyles({'left':(mouseX - 1) * 250 + 30, 'top':250 + (mouseY - 1) * 250 + 30});
				myDiv.inject($('div_container'));
			}else{
				myDiv.setStyles({'left':655, 'top':375});
				myDiv.inject($('div_container'));
			}
			
			var target_detail			= 'itemAdded';
			var product_url 			= root_domain+'aShop/product_added.php';
			loadNshow(product_url,target_detail,'get');
			addedMessage				= true;

		break;
		case 'itemAdded':
			allow_click			= true
			allowAdding			= true;
			$(target).innerHTML 		= output;		
		break;
		case 'marketing_container':
			$(target).innerHTML 		= output;	
			allow_click			= true
			allowAdding			= true;
			activateMarketing();		
		break;
	}	
}

var active_option 	= '';
var measureX		= 0;
var measureY		= 255;
var relativeX		= 0;
var bigWidth		= 765;
var bigHeight		= 675;
var smallWidth		= 254;
var smallHeight		= 225;
var relativeX		= 0;
var fxImageBig;	
var allowAdding 	= true;
var optionslist;

function productInit(){
	active_option = '';
	
	var valueTarget = '';
	optionslist 	= $$('.product_option');
	optionslist.each(function(element) {
	 	element.addEvent('click', function(){
			if(element.getProperty('name')!=active_option){;
				
				if(active_option!=''){
					var valueTarget = $('product_option_values'+active_option);
					ChangeAnim('height', valueTarget, 0, 500, Fx.Transitions.Cubic.easeOut)
				}
				
				active_option 	= element.getProperty('name');
				var nr 			= element.getProperty('name');
				var nr_ofValues	= document.getElementById('option_value_counter'+nr).value;
				valueTarget 	= $('product_option_values'+nr);
				var toMove		= nr_ofValues * 21;
				if(toMove>200){
					toMove = 200;
				}
				ChangeAnim('height', valueTarget, toMove, 500, Fx.Transitions.Cubic.easeOut)
			}
		});
		
	});
	
	
	var optionsValuelist = $$('.product_option_value');
	optionsValuelist.each(function(element) {
	 
		var fxvalues = new Fx.Morph(element, {duration:200, wait:false});
		element.addEvent('mouseenter', function(){
			if(element.getProperty('class')=='product_option_value'){									
			fxvalues.start({
				'background-color': '#f1c594'
			});
			}
		});
	 
		element.addEvent('mouseleave', function(){
			if(element.getProperty('class')=='product_option_value'){									
			fxvalues.start({
				'background-color': '#ffffff'
			});
			}
		});
		
		element.addEvent('click', function(){
			var childof = parseInt(element.getProperty('childof'));
			var disablelist = $$('#product_option_values'+childof+' .product_option_value');
			disablelist.each(function(element) {
				element.setStyle('background-color', '#ffffff');
				element.removeClass('selected');
			});
			element.addClass('selected');
			fxvalues.start({
				'background-color': '#cfcfcf'
			});
			
		});
		
	});
	
	
		
	$('buy_now').addEvent('click', function(e) {
		var size_selected		= true;
		optionslist 	= $$('.product_option');
		optionslist.each(function(element) {
	 		var check_option = element.getProperty('name');
			if($('id['+check_option+']')){
				if($('id['+check_option+']').value == 0){
					size_selected	= false;
				}
			}
	 	});


		if(size_selected){
			if(allowAdding==true){
				$('select_option_alert').setStyle('display','none');	
				new Event(e).stop();
				allowAdding				= false;
				var target_form 		= 'add_product';
				var target_loading 		= 'div_content_3_container';
				var target_output 		= 'div_content_3_container';
				
				$(target_form).set('send', {
					method: 'post',
					data: $(target_form),                                      
					onSuccess: function(responseText, responseXML) {
						//alert(responseText);
						loadNshow('aShop/shopping_cart_stripped.php','div_content_3_container','get');
					}
				});
				$(target_form).send($(target_form).action); 
			}
		}else{
			$('select_option_alert').setStyle('display','block');				
		}
	});
		
	$('wish_now').addEvent('click', function(e) {
		var size_selected		= true;
		
		
		optionslist.each(function(element) {
	 		var check_option = element.getProperty('name');
			if($('id['+check_option+']')){
				if($('id['+check_option+']').value == 0){
					size_selected	= false;
				}
			}
	 	});


		if(size_selected){
			if(allowAdding==true){
				$('select_option_alert').setStyle('display','none');	
				new Event(e).stop();
				allowAdding				= false;
				var target_form 		= 'add_product';
				var target_loading 		= 'wish_now';
				var target_output 		= 'wish_now';
				
				$(target_form).set('send', {
					url: root_domain + 'aShop/wishlist_add.php',
					method: 'post',
					data: $(target_form),                                      
					onSuccess: function(responseText, responseXML) {
						$(target_output).innerHTML = responseText;
						allow_click			= true
						allowAdding			= true;
					}
				});
				$(target_form).send(); 
			}
		}else{
			$('select_option_alert').setStyle('display','block');				
		}
	});
	
	allow_click			= true
}

function closeAddMessage(){
	if($('itemAdded')){
		$('itemAdded').destroy();
		addedMessage = false;
	}	
}

function submitForm(target){
	$(target).submit();
}

function setSorting(){
	var valueTarget = '';
	optionslist 	= $$('.sorting_option');
	optionslist.each(function(element) {
	 	element.addEvent('click', function(){
			if(element.getProperty('name')!=active_option){;
				
				if(active_option!=''){
					var valueTarget = $('sorting_option_values'+active_option);
					ChangeAnim('height', valueTarget, 0, 500, Fx.Transitions.Cubic.easeOut)
				}
				
				active_option 	= element.getProperty('name');
				var nr 			= element.getProperty('name');
				var nr_ofValues	= document.getElementById('option_value_counter'+nr).value;
				valueTarget 	= $('sorting_option_values'+nr);
				var toMove		= nr_ofValues * 21;
				if(toMove>200){
					toMove = 200;
				}
				ChangeAnim('height', valueTarget, toMove, 500, Fx.Transitions.Cubic.easeOut)
			}
		});
		
	});
	
	
	var optionsValuelist = $$('.sorting_option_value');
	optionsValuelist.each(function(element) {
	 	//element.setStyle('opacity' , 0.9);
			
		var fxvalues = new Fx.Morph(element, {duration:200, wait:false});
		element.addEvent('mouseenter', function(){
			if(element.getProperty('class')=='sorting_option_value'){									
			fxvalues.start({
				'background-color': '#cfcfcf'
			});
			}
		});
	 
		element.addEvent('mouseleave', function(){
			if(element.getProperty('class')=='sorting_option_value'){									
			fxvalues.start({
				'background-color': '#ffffff'
			});
			}
		});
		
		element.addEvent('click', function(){
			var childof = parseInt(element.getProperty('childof'));
			var disablelist = $$('#sorting_option_values'+childof+' .sorting_option_value');
			disablelist.each(function(element) {
				element.setStyle('background-color', '#ffffff');
				element.removeClass('selected');
			});
			//element.addClass('selected');
			var valueTarget = $('sorting_option_values'+active_option);
			ChangeAnim('height', valueTarget, 0, 500, Fx.Transitions.Cubic.easeOut)
			active_option = '';
		
		});
		
	});
}

function SetOptionValue(option_id,values_id){
	
	if(active_option!=''){
		$('product_option_'+option_id).innerHTML 	= $('product_option_value_'+values_id).innerHTML;
		var valueTarget = $('product_option_values'+active_option);
		ChangeAnim('height', valueTarget, 0, 500, Fx.Transitions.Cubic.easeOut)
		active_option = '';
	}
	document.getElementById('id['+option_id+']').value = values_id;		
}

function openLink(str_link){
	window.location	= str_link;	
}

//scrolling etc -- OK!
var myScrollEffect;
var listScrollPosition		= new Array();
listScrollPosition['most_popular_scollable']		= 0;
listScrollPosition['latest_group_1_scollable']		= 0;
listScrollPosition['latest_group_2_scollable']		= 0;

var oldListScrollPosition 	= new Array();
oldListScrollPosition['most_popular_scollable']		= 0;
oldListScrollPosition['latest_group_1_scollable']	= 0;
oldListScrollPosition['latest_group_2_scollable']	= 0;
var inList					= 12
var currScrollTarget		= '';
function scrollLeft(target){
	oldListScrollPosition[target]	= listScrollPosition[target];
	listScrollPosition[target]-=(4*166);
	doScroll(target);
}

function scrollRight(target){
	oldListScrollPosition[target]	= listScrollPosition[target];
	listScrollPosition[target]+=(4*166);
	doScroll(target);
}

function doScroll(target){
	
	if(myScrollEffect){
		myScrollEffect.cancel();
	}
	if(listScrollPosition[target]<0){
		listScrollPosition[target] = 0;
	}
	if(listScrollPosition[target] > ((1992 - 4 * 166))){
		listScrollPosition[target] = (1992 - 4 * 166);
	}
	myScrollEffect = MorpheItems(target, 800, Fx.Transitions.Cubic.easeOut);
	myScrollEffect.start({'left': -listScrollPosition[target]});
	
}

function resetScroll(target){
	oldListScrollPosition 	= 0;
	listScrollPosition 		= 0;
	
	myScrollEffect = new Fx.Scroll(target, {
		offset: {
			'x': listScrollPosition,
			'y': 0
		}
	}).toTop();
}

function openWindow(url, name){
	var winRef = window.open(url, name, 'left=20,top=20,width=680,height=600,scrollbars=1,toolbar=0,resizable=0');
}
function confirmAll(){
	if($('agree').checked){
		$('agree_notice').setStyle('display','none');
		document.checkout_confirmation.submit();
	}else{
		$('agree_notice').setStyle('display','block');
	}
}

var preload_image_object 	= new Array();
var image_url 				= new Array();
var image_url_active 		= new Array();
var active_current			= 0;



/*doop specs*/

var fx_shine		= new Array;
var fx_hold			= new Array;
var fx_shine_txt	= new Array;
var fx_hold_txt		= new Array;
var fx_img_list		= new Array;
var fx_info_list	= new Array;
var fx_buy			= new Array;
var mouseY,mouseX;

function initDoopSpecs(){
	var optionsValuelist = $$('.collection_divs_home');
	optionsValuelist.each(function(element) {
	 	if(element.getProperty('id')){
			var current = parseInt(element.getProperty('id').substring(10));
			fx_shine[current]		= MorpheItems('graph_shine_'+current, 500, Fx.Transitions.Cubic.easeOut);
			fx_hold[current]		= MorpheItems('graph_hold_'+current, 500, Fx.Transitions.Cubic.easeOut);
			fx_shine_txt[current]	= MorpheItems('txt_shine_'+current, 500, Fx.Transitions.Cubic.easeOut);
			fx_hold_txt[current]	= MorpheItems('txt_hold_'+current, 500, Fx.Transitions.Cubic.easeOut);
			fx_img_list[current]	= MorpheItems('img_'+current, 500, Fx.Transitions.Cubic.easeOut);
			fx_info_list[current]	= MorpheItems('info_'+current, 0, Fx.Transitions.Cubic.easeOut);
			fx_buy[current]			= MorpheItems('buy_'+current, 0, Fx.Transitions.Cubic.easeOut);
		}
		
		var fxvalues = new Fx.Morph(element, {duration:200, wait:false});
		element.addEvent('mouseenter', function(){
			if(element.getProperty('id')){
				var current = parseInt(element.getProperty('id').substring(10));
				mouseOverInfo(current);
			}
		});
	 
		element.addEvent('mouseleave', function(){
			if(element.getProperty('id')){
				var current = parseInt(element.getProperty('id').substring(10));
				mouseOutInfo(current);
			}
		});
		
	});
	
	var submitListAdd = $$('.collection_buy');
	submitListAdd.each(function(element) {
		element.addEvent('click', function(e){
			if(allowAdding==true){
				if(addedMessage){
					closeAddMessage();
				}
				mouseY 			= e.page.y;											  
				mouseX 			= e.page.x;											  
				mouseY			= (Math.ceil((mouseY-250)/250));
				mouseX			= (Math.ceil((mouseX - (middleX - 500))/250));
				new Event(e).stop();
				
				var id 			= parseInt(element.getProperty('id').substring(4));								
				
				var size_selected		= true;
				/*optionslist 	= $$('.product_option');
				optionslist.each(function(element) {
					var check_option = element.getProperty('name');
					if($('id['+check_option+']')){
						if($('id['+check_option+']').value == 0){
							size_selected	= false;
						}
					}
				});
				*/
		
		
				
				if(size_selected){
					if(allowAdding==true){
						//$('select_option_alert').setStyle('display','none');	
						new Event(e).stop();
						
						allowAdding				= false;
						var target_form 		= 'add_product_'+id;
						var target_loading 		= 'div_content_3_container';
						var target_output 		= 'div_content_3_container';
						
						var qty 				= parseInt($('quantity_'+id).getProperty('value'));
						qty						+= 1;
						$('quantity_'+id).setProperty('value',qty);
						
						$(target_form).set('send', {
							method: 'post',
							data: $(target_form),                                      
							onSuccess: function(responseText, responseXML) {
								//alert(responseText);
								loadNshow(root_domain + 'aShop/shopping_cart_stripped.php','div_content_3_container','get');
							}
						});
						$(target_form).send($(target_form).action); 
					}
				}else{
					$('select_option_alert').setStyle('display','block');				
				}
			}
			
		});
	});
}
var ColorWays 			= new Array('#8b8b84','#6E2A8D','#00B5CC','#FFD200','#273691','#EF3E42','#888927','#DB0962','#005DAA','#F78F1E','#8CC63F');
var ColorPick			= 0

function mouseOverInfo(tiptextValue){
	
	
	//product
	var hold  			= $('hold_'+tiptextValue).getProperty('value');
	var shine  			= $('shine_'+tiptextValue).getProperty('value');
	
	//$('info_lefter_'+tiptextValue).fade('hide');
	//$('info_lefter_'+tiptextValue).setStyle('left', 600 + 'px');
	
	//$('txt_hold_'+tiptextValue).setStyle('color',ColorWays[hold]);
	//$('txt_shine_'+tiptextValue).setStyle('color',ColorWays[shine]);
	
	fx_shine[tiptextValue].cancel();
	fx_shine[tiptextValue].start({'height':shine*15, 'top':(250 - shine*15), 'background-color':ColorWays[shine]});
	fx_hold[tiptextValue].cancel();
	fx_hold[tiptextValue].start({'height':hold*15, 'top':(250 - hold*15), 'background-color':ColorWays[hold]});
	
	fx_shine_txt[tiptextValue].cancel();
	fx_shine_txt[tiptextValue].set({'color':ColorWays[0]});
	fx_hold_txt[tiptextValue].cancel();
	fx_hold_txt[tiptextValue].set({'color':ColorWays[0]});
	
	fx_img_list[tiptextValue].cancel();
	fx_img_list[tiptextValue].start({'opacity':0.5, 'width':150, 'margin-left':48});
	fx_info_list[tiptextValue].cancel();
	fx_info_list[tiptextValue].start({'color':'#ffffff'});
	
	fx_buy[tiptextValue].set({'display':'block'});
	
}
function mouseOutInfo(tiptextValue){
	
	//product
	//$('info_lefter_'+tiptextValue).fade('hide');
	//$('info_lefter_'+tiptextValue).setStyle('left', 600 + 'px');
	
	//$('txt_hold_'+tiptextValue).setStyle('color',ColorWays[hold]);
	//$('txt_shine_'+tiptextValue).setStyle('color',ColorWays[shine]);
	
	fx_shine[tiptextValue].cancel();
	fx_shine[tiptextValue].start({'height':0, 'top':250, 'background-color':'#000000'});
	fx_hold[tiptextValue].cancel();
	fx_hold[tiptextValue].start({'height':0, 'top':250, 'background-color':'#000000'});
	
	fx_shine_txt[tiptextValue].cancel();
	fx_shine_txt[tiptextValue].start({'color':'#ffffff'});
	fx_hold_txt[tiptextValue].cancel();
	fx_hold_txt[tiptextValue].start({'color':'#ffffff'});
	
	fx_img_list[tiptextValue].cancel();
	fx_img_list[tiptextValue].start({'opacity':1, 'width':240, 'margin-left':0});
	fx_info_list[tiptextValue].cancel();
	fx_info_list[tiptextValue].start({'color':'#8b8b84'});
	
	fx_buy[tiptextValue].set({'display':'none'});
	
}




var active_slide			= 0;
var count_slides			= 0;
var slide_urls				= new Array();
var slide_ttls				= new Array();
var fx_slide_info;
var proportions_original	= 0;
var allow_refresh			= true;
var allow_auto_refresh		= true;
var refresher;

function setSlideBase(){
	active_slide		= -1;
	if($('valuesURL_x')){
		if($('valuesURL_x').value != ''){
			var url_slides		= $('valuesURL_x').value;
			slide_urls			= url_slides.split('#');
			var title_slides	= $('valuesTitles_x').value;
			slide_ttls			= title_slides.split('#');
			count_slides		= $('aantal_thumbs_x').value;
			setSlideAuto();
		}
	}
}
function setSlideManual(){
	$clear(refresher)
	var nr 			= active_slide
	if(nr < (count_slides-1)){
		nr++
	}else{
		nr			= 0;
	}
	setSlide(nr);
}
function setSlideAuto(){
	if(allow_auto_refresh){
		var nr 			= active_slide
		if(nr < (count_slides-1)){
			nr++
		}else{
			nr			= 0;
		}
		setSlide(nr);
	}else{
		$clear(refresher)
	}
}

function setSlide(nr){
	if(nr!=active_slide && allow_refresh == true){
		active_slide	= nr;
		allow_refresh	= false;
		loadNewSlide(slide_urls[nr]);
	}
}

var current_img_fx_out;
var current_img_fx_in;
var this_breedte_image;
var this_hoogte_image;
var proportions_site;
				
function loadNewSlide(new_url){
	new Asset.images(new_url, {
		onProgress: function(i) {
			this_breedte_image 	= this.width;
			this_hoogte_image 	= this.height;
			this.setStyles({
				'opacity': 0
			});
		},
		onComplete: function() {
			
			proportions_original 	= this_hoogte_image/this_breedte_image;
			
			current_img_fx_out = new Fx.Morph($('slide_image'), {duration: 200, transition: Fx.Transitions.Cubic.easeOut,onComplete: function() {
				
				current_img_fx_in = new Fx.Morph($('slide_image'), {duration: 200, transition: Fx.Transitions.Cubic.easeOut,onComplete: function() {
					allow_refresh	= true;
					$clear(refresher);
					refresher		= setSlideAuto.periodical(5000);
				}});
				
				current_img_fx_in.set({'opacity': 0});
				$('slide_image').src = new_url;
				$('slide_image').setStyles({'display' : 'block'});
				var new_width;
				var new_height;
				
				if(proportions_original >= proportions_site){
					new_height		= innerWidth * proportions_original
					if(new_height < innerHeight){
						new_height 		=  innerHeight;
						new_width 		=  new_height * proportions_original;
					}
					$('slide_image').setStyles({'width' : new_width, 'height' : new_height});
					$('slides_container').setStyles({'top' : 0, 'left' : 0});
					//$('slide_image').setStyle('width' ,innerWidth);
				}else{
					var new_width		= innerHeight / proportions_original
					if(new_width < innerWidth){
						new_width 		=  innerWidth;
						new_height 		=  innerWidth / proportions_original;
					}
					$('slide_image').setStyles({'width' : new_width, 'height' : innerHeight});
					$('slides_container').setStyles({'left' : 0 , 'top' : 0});
				}
				
				
				current_img_fx_in.cancel();
				current_img_fx_in.start({'opacity': 1});
				
				
			}});
				
			current_img_fx_out.cancel();
			current_img_fx_out.start({'opacity': 0});
			
		}
	});
		
}

function resizeBG(){
	if(proportions_original >= proportions_site){
		new_height		= innerWidth * proportions_original
		if(new_height < innerHeight){
			new_height 		=  innerHeight;
			new_width 		=  new_height * proportions_original;
		}
		$('slide_image').setStyles({'width' : new_width, 'height' : new_height});
		$('slides_container').setStyles({'top' : 0, 'left' : 0});
		//$('slide_image').setStyle('width' ,innerWidth);
	}else{
		var new_width		= innerHeight / proportions_original
		if(new_width < innerWidth){
			new_width 		=  innerWidth;
			new_height 		=  innerWidth / proportions_original;
		}
		$('slide_image').setStyles({'width' : new_width, 'height' : innerHeight});
		$('slides_container').setStyles({'left' : 0 , 'top' : 0});
	}
}

//adviser
function changeSizeTo(a, b, target, speed){
	var myResizer = new Fx.Morph(target, {duration: speed * 500, transition: Fx.Transitions.Sine.easeOut});
	myResizer.start({
		'width': a,
		'height': b
	});
}
function changePosTo(a, b, target, speed){
	var myResizer = new Fx.Morph(target, {duration: speed * 500, transition: Fx.Transitions.Sine.easeOut});
	myResizer.start({
		'left': a
	});
}
function changeTopTo(a, b, target, speed){
	var myResizer = new Fx.Morph(target, {duration: speed * 500, transition: Fx.Transitions.Sine.easeOut});
	myResizer.start({
		'top': b
	});
}

var stepSpinner;
function loadNshowAdvise(url, advisor_stage, method){
//	var preloader = $(target).empty().addClass('loading');
	
	var target; 
	switch(advisor_stage){
		case 0:
			target = 'div_content_2'+advisor_addon;
		break;
		case 1:
			target = 'div_content_3'+advisor_addon;
		break;
		case 2:
			target = 'div_content_4'+advisor_addon;
		break;
		case 3:
			target = 'div_content_5'+advisor_addon;
		break;
		case 4:
			target = 'div_content_6'+advisor_addon;
		break;
	}
	//stepSpinner = new Spinner(target);
	//stepSpinner.show(true);
	
	
	var req = new Request({url: url,
	    method: method,
	   	onSuccess: function(responseText) {
			document.getElementById(target).innerHTML = responseText;
			//stepSpinner.destroy()
			if(advisor_stage == 1){
				if($('innercontent_dealer_scrollable')){
					updateScroll('innercontent_dealer_scrollable', 'innercontent_dealer');
				}
			}
		},
		onFailure: function() {
			document.getElementById(target).innerHTML = 'The request failed';
		}
	});
	req.send();
}

function openDealer(parent,stap){
	advisor_addon = '_dealer';	
	switch(stap){
		case -1:
			advisor_stage = 0;
			poststr	= '?category='+parent+'&stage=0';
			loadNshowAdvise('flow_advisor.php' + poststr, stap ,'get');	
			//changeSizeTo(178, 180, 'div_content_1', 1);	
			changeSizeTo(0, 249, 'div_content_2', 1);	
			//changePosTo(250, 0, 'div_content_2', 1);
			//resetVlakkenDealer(2);
		break;
		case 0:
			advisor_stage = stap;
			poststr	= '?category='+parent+'&stage='+stap;
			loadNshowAdvise('flow_dealer_regions.php' + poststr, stap ,'get');		
			//changeSizeTo(150, 65, 'div_content_1_dealer', 1);	
			$('div_content_2_dealer').setStyles({'display' : 'block'});
			changeSizeTo(500, 249, 'div_content_2_dealer', 1);	
			//changePosTo(0, 0, 'div_content_2', 1);
			resetVlakkenAdviser(3);
		break;
		case 1:
			advisor_stage = stap;
			//changeSizeTo(150, 0, 'div_content_1_dealer', 1);	
			//changeSizeTo(150, 25, 'div_content_2_dealer', 1);
			$('div_content_3_dealer').setStyles({'display' : 'block'});
			changeSizeTo(249, 1000, 'div_content_3_dealer', 1);
			//changeTopTo(0, 30, 'div_content_3_dealer', 1);
			//changeTopTo(0, 0, 'div_content_2_dealer', 1);	
			
			poststr	= '?category='+parent+'&stage='+stap;
			loadNshowAdvise('flow_dealers_list.php' + poststr, stap ,'get');	
			resetVlakkenAdviser(4);	
		break;
		case 2:
			advisor_stage = stap;
			changeSizeTo(120, 180, 'div_content_3', 1);
			changeSizeTo(230, 180, 'div_content_4', 1);
			changePosTo(400, 0, 'div_content_4', 1);
			poststr	= '?category='+parent+'&stage='+stap;
			loadNshowAdvise('flow_advisor.php' + poststr, stap ,'get');	
			resetVlakkenDealer(4);
		break;
		case 3:
			advisor_stage = stap;
			changeSizeTo(120, 180, 'div_content_4', 1);
			changeSizeTo(120, 180, 'div_content_5', 1);
			changePosTo(525, 204, 'div_content_5', 1);
			poststr	= '?category='+parent+'&stage='+stap;
			loadNshowAdvise('flow_advisor.php' + poststr, stap ,'get');	
			resetVlakkenAdviser(5);
			//myAnim.animate();
		break;
		case 4:
			advisor_stage = stap;
			changeSizeTo(634, 180, 'div_content_5', 1);
			changePosTo(273, 318, 'div_content_5', 1);
			poststr	= '?category='+parent+'&stage='+stap;
			loadNshowAdvise('flow_advisor.php' + poststr, stap ,'get');	
			resetVlakkenAdviser(6);
			//myAnim.animate();
		break;
	}
}

function openAdviser(parent,stap){
	advisor_addon = '_adviser';	
	switch(stap){
		case 0:
			advisor_stage = stap;
			poststr	= '?category='+parent+'&stage='+stap;
			loadNshowAdvise('flow_advisor.php' + poststr, stap ,'get');		
			$('div_content_2_adviser').setStyles({'display' : 'block'});
			changeSizeTo(250, 249, 'div_content_2_adviser', 1);	
			resetVlakkenAdviser(3);
		break;
		case 1:
			advisor_stage = stap;
			$('div_content_3_adviser').setStyles({'display' : 'block'});
			changeSizeTo(250, 249, 'div_content_3_adviser', 1);
			poststr	= '?category='+parent+'&stage='+stap;
			loadNshowAdvise('flow_advisor.php' + poststr, stap ,'get');	
			resetVlakkenAdviser(4);
		break;
		case 2:
			advisor_stage = stap;
			poststr	= '?category='+parent+'&stage='+stap;
			$('div_content_4_adviser').setStyles({'display' : 'block'});
			changeSizeTo(248, 249, 'div_content_4_adviser', 1);
			loadNshowAdvise('flow_advisor.php' + poststr, stap ,'get');
			resetVlakkenAdviser(5);
		break;
		case 3:
			advisor_stage = stap;
			poststr	= '?category='+parent+'&stage='+stap;
			$('div_content_5_adviser').setStyles({'display' : 'block'});
			changeSizeTo(250, 249, 'div_content_5_adviser', 1);
			loadNshowAdvise('flow_advisor.php' + poststr, stap ,'get');	
		break;
		case 4:
			advisor_stage = stap;
			changeSizeTo(634, 180, 'div_content_5', 1);
			changePosTo(273, 318, 'div_content_5', 1);
			poststr	= '?category='+parent+'&stage='+stap;
			loadNshowAdvise('flow_advisor.php' + poststr, stap ,'get');	
			resetVlakkenAdviser(5);
			//myAnim.animate();
		break;
	}
}

function resetVlakkenAdviser(from){
	var i	= from;
	for(i=from;i<6;i++){
		if($('div_content_'+i+'_adviser')){
		changeSizeTo(0, 0, 'div_content_'+i+'_adviser', 1);
		}else if($('div_content_'+i+'_dealer')){
		changeSizeTo(0, 0, 'div_content_'+i+'_dealer', 1);
		}
	}
}

var activeDealer = 0;
function openDealerInfo(dealer){
	//move index
	if(activeDealer!=0){
		if($('dealerName_'+activeDealer)){
		$('dealerName_'+activeDealer).removeClass('active');
		}
	}
	

	$('dealerDetailInfo').innerHTML = '<br><img src="/aShop/img/assets/spinner.gif" alt="loading" />';
	
	var url			= 'flow_dealer_info.php?dealer_id='+dealer;
	var reqDealer 	= new Request({url:url, method: 'get',
	onSuccess: function(responseText) {
		//if(responseText!=shopping_cartVersion){
			$('dealerDetailInfo').innerHTML = responseText;
			var DesignerList = $$('#designersThumbContainer .designerThumb');
			DesignerList.each(function(element) {
				/*element.addEvent('mouseenter', function(){
					ChangeAnim('top', element, 10, 500, Fx.Transitions.Cubic.easeOut);
				});
			 
				element.addEvent('mouseleave', function(e){
					ChangeAnim('top', element, 80, 500, Fx.Transitions.Cubic.easeOut);
				});
				*/
				element.addEvent('click', function(e){
					//alert('click');
					$('BI').src = root_domain + "images/dealers/designers/" + parseInt(element.getProperty('id')) + ".jpg"
				});
				
			});
		//}
	}});
	reqDealer.send();
	
	
	activeDealer = dealer;
	$('dealerName_'+activeDealer).addClass('active');
}
var productRows = 0;
var activemarketing = 1000

function activateMarketing(){
	var accordion = new Accordion('div.atStart', 'div.atOpened', {
		show : 10000,
		opacity: true,
		onActive: function(toggler, element){
			activemarketing = parseInt(element.getProperty("name")) - 1;
			toggler.setStyle('color', '#00b5cf');
		},
	 
		onBackground: function(toggler, element){
			toggler.setStyle('color', '#000000');
			toggler.setStyle('cursor', 'pointer');
		}
		
	}, $('marketing_container_content'));
	
	
	
	var ListRemoveMark = $$('.deleteProd_marketing');
	ListRemoveMark.each(function(element) {
		element.addEvent('click', function(e){
			if(allowAdding==true){
				new Event(e).stop();
				allowAdding	= false
				var prod 	= element.getProperty('id').substring(7);								
				deleteMarketingFromBasket(prod);
			}
		});
	});	
	
	if($('add_product_marketing')){
		$('add_product_marketing').set('send', {
			method: 'post', 
			data: $('add_product_marketing'),                                     
			onSuccess: function(responseText, responseXML) {
				$('marketing_container').innerHTML = responseText;
				allowAdding		= true
				 //loadNshow('flow_shopping_cart.php','cart_container','get');				
				//if(qty==1){
					//$('submitRem_'+id).setStyle('display', 'block');
				//}
				var preloader2 	= $('marketing_container').empty().addClass('loading');
				loadNshow('flow_marketing.php?include=1','marketing_container','get');
			}
		});
	
		var count = 0;
		var submitListAdd = $$('.add_to_basket_marketing');
		submitListAdd.each(function(element) {
			element.addEvent('click', function(e){
				if(allowAdding==true){
					new Event(e).stop();
					allowAdding		= false
					var id 			= element.getProperty('id').substring(10);								
					var prod 		= 0;								
					var attr		= '';								
					
					if(id.indexOf('_') > 0){
						//attributes!
						var arr		= id.split('_');
						prod		= arr[0];
						attr		= prod + '-' + arr[1] + '-' + arr[2];
					}else{2
						//single product
						prod		= id;
						attr		= id;
					}
					
					var qty 		= parseInt($('quantity_'+id).getProperty('value'));
					
					
					$('products_id').value 		= prod;
					$('products_attr').value 	= attr;
					
					
					qty+=1
					$('quantity').value 		= qty;
					$('quantity_'+id).value 	= qty;
					
					
					
					$('add_product_marketing').send($('add_product_marketing').action); 
		
				}
				
			});
		});
		
		var submitListRemove = $$('.remove_from_basket_marketing');
		submitListRemove.each(function(element) {
			element.addEvent('click', function(e){
				if(allowAdding==true){
					new Event(e).stop();
					allowAdding		= false
					var id 			= element.getProperty('id').substring(10);								
					var prod 		= 0;								
					var attr		= '';								
					
					if(id.indexOf('_') > 0){
						//attributes!
						var arr		= id.split('_');
						prod		= arr[0];
						attr		= prod + '-' + arr[1] + '-' + arr[2];
					}else{2
						//single product
						prod		= id;
						attr		= id;
					}
					
					var qty 		= parseInt($('quantity_'+id).getProperty('value'));
					
					
					$('products_id').value 		= prod;
					$('products_attr').value 	= attr;
					
					
					qty-=1
					$('quantity').value 		= qty;
					$('quantity_'+id).value 	= qty;
					
					
					
					$('add_product_marketing').send($('add_product_marketing').action); 
				}
			});
		});
	}
}
