function positionAll(){
	var viewport	= getViewport();
	var docWidth 	= viewport[0];
	var docHeight 	= viewport[1];
	
    var windowWidth = viewport[0];
    var windowHeight = viewport[1];
    
    // set visual width 
    var visualMinWidth = 300;
    var visualMaxWidth = 650;
    var visualWidth	   = windowWidth - 760;
    if(visualWidth < visualMinWidth){
    	visualWidth = visualMinWidth; 
    }
    if(visualWidth > visualMaxWidth){
    	visualWidth = visualMaxWidth; 
    }
    $('#logo').width(visualWidth);
    $('#mainMenu').width(visualWidth);
    $('#innerMainWrapper').css('margin-left', visualWidth + 'px');
    
    // set menu position
    var menuPos = 220;
    if(windowHeight < ((menuPos*2) + $('#mainMenu .wrapper ul').height())){
        menuPos = Math.round((windowHeight - $('#mainMenu .wrapper').height()) / 2);
    }

    if(menuPos <88){
        menuPos = 88;
    }
    $('#mainMenu .wrapper').css('top', menuPos + 'px' );
    
    $('#innerMainWrapper').height('auto');
    if($('#innerMainWrapper').height() < (docHeight - 155)){
    	$('#innerMainWrapper').height(docHeight - 155);
    }
    
    
}



function formValidate(formData, jqForm, options){
    var send = false;
    var hasName     = false;
    var hasContact  = false;

    for (var i=0; i < formData.length; i++) {
        if(formData[i].name == 'name' && formData[i].value != ''){
            hasName = true;
        }
        if(formData[i].name == 'email' && formData[i].value != ''){
            hasContact = true;
        }
        if(formData[i].name == 'phone' && formData[i].value != ''){
            hasContact = true;
        }
    }
    if(hasName == true && hasContact == true){
        send = true;
    }

    if(send == false){
        alert('U moet ten minste uw naam en uw emailadres of telefoonnummer opgeven.');
    }

    return send;
}

function formResponse(responseText, statusText, xhr, $form){
    $('div#form0holder').html('<div class="response">Het formulier is verstuurd. We zullen u spoedig een reactie geven.</div>');
}

var curvis 		= -1;
var visuals 	= new Array();
var animvis		= false;
var vistime		= null;
var curcolor	= null;

function setVisuals(){
	var slashed,filename,visual;
	var images = $('#mainMenu div.visuals img');
	$.each(images, function(index, value) {
		slashed 	= $(value).attr('src').split('/');
		filename 	= slashed[slashed.length-1].substring(0, slashed[slashed.length-1].lastIndexOf('.')).split('_');
		//0=name,1=color,2=logo,3=align
		visual = [{}];
		visual.name = filename[0];
		visual.color = filename[1];
		visual.logo = filename[2];
		visual.align = filename[3];
		visuals.push(visual);
		if(visual.align == 'right'){
			$(value).css('left', 'auto');
			$(value).css('right', '0px');
		}
		else{
			$(value).css('left', '0px');
			$(value).css('right', 'auto');
		}
		
        // prepare element
        $(value).css('z-index', index);
        $(value).attr('id', 'vis'+index);
        
    });
	
	
	
	if(images.length > 1 && $('body.diensten').length == 0){
		animvis = true;
	}
	
	if(images.length > 0){
		if($('body.diensten').length == 1){
			selectaccordionitem();
		}
		else{
			showVisual();
		}
		
	}
	
	
}

function showVisual(id, speed){
	var alpha, rgba, rgbb, bgcolor, oldvis;
	if(speed == undefined){
		speed = 2000;
	}
	if(id == undefined){
		id = curvis + 1;
		if(id == visuals.length){
			id = 0;
		}
	}
	if(id != curvis){
		if(vistime != null && animvis == true){
			clearTimeout(vistime);
		}
		if(curvis != -1){
            swapDepth($('#vis' + id), $('#vis' + curvis));
        }
		if(visuals[id].logo == 'color'){
			if($('#logo .color').css('display') == 'none'){
				//swapDepth($('#logo .color'), $('#logo .white'));
				$('#logo .color').fadeIn(speed/4);
				$('#logo .white').fadeOut(speed/4);
			}
		}
		else{
			if($('#logo .white').css('display') == 'none'){
				swapDepth($('#logo .white'), $('#logo .color'));
				$('#logo .white').fadeIn(speed/4);
				$('#logo .color').fadeOut(speed/4);
			}
		}
		
		if(visuals[id].color == 'none'){
			if(curcolor == null){
				curcolor = hexToRGB('102f63');
			}
			alpha = 0;
			bgcolor = hexToRGB('102f63');
		}
		else{
			curcolor = hexToRGB(visuals[id].color);
			bgcolor = curcolor
			alpha = 1;
		}
		rgba = 'rgb('+curcolor.r+','+curcolor.g+','+curcolor.b+')';
		rgbb = 'rgb('+bgcolor.r+','+bgcolor.g+','+bgcolor.b+', 1)';
		
		//alert(curcolor.hex);
		$('#logo .background').animate({
		    backgroundColor : rgba,
		    opacity: alpha
		}, 1000);
		
		$('#mainMenu').animate({
		    backgroundColor : rgbb
		}, 1000);
		
		oldvis = curvis;
		curvis = id;
		
		
		$('#vis' + id).fadeIn(speed, function(){
			if(oldvis != -1){
				$('#vis' + oldvis).hide();
			}
			if(animvis == true){
				vistime = setTimeout('showVisual()', speed*2);
			}
            
        });
	}
}

function swapDepth(el1, el2){
    var z1 = el1.css('z-index');
    var z2 = el2.css('z-index');
    if(z1 < z2){
        el1.css('z-index', z2);
        el2.css('z-index', z1);
    }
}

function hexToRGB(val){
	var rgb = [{}];
	rgb.r = parseInt(val.substring(0,2), 16);
	rgb.g = parseInt(val.substring(2,4), 16);
	rgb.b = parseInt(val.substring(4,6), 16);
	rgb.hex = val;
	return rgb;
}


function getViewport(){
	 var viewportwidth;
	 var viewportheight;
	 
	 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	 
	 if (typeof window.innerWidth != 'undefined')
	 {
	      viewportwidth = window.innerWidth,
	      viewportheight = window.innerHeight
	 }
	 
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

	 else if (typeof document.documentElement != 'undefined'
	     && typeof document.documentElement.clientWidth !=
	     'undefined' && document.documentElement.clientWidth != 0)
	 {
	       viewportwidth = document.documentElement.clientWidth,
	       viewportheight = document.documentElement.clientHeight
	 }
	 
	 // older versions of IE
	 
	 else
	 {
	       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
	       viewportheight = document.getElementsByTagName('body')[0].clientHeight
	 }
	
	 
	 return new Array(viewportwidth, viewportheight);
}

function tweenColor(el, color){
	$(el).css('background','#'+color);
}

