function init(){

	 
   	if($.browser.msie){
        $('a').focus(function(){
            this.blur();
        })
    }
   
    $(window).load(function(){
    	$('#searchDropDown')[0].blur();
    	if($.browser.msie){
        $('a').focus(function(){
            this.blur();
        })
        }
        resizeCheck();
    })

    if($.browser.msie && $.browser.version < 9){
        oldIE = true;
        //$('a').click(function(){
	 	//	this.blur();
		//})
    }else{
		oldIE = false;
        $('.layout752242815919b42e #header').delay(100).fadeTo(300,1);
        $('.fadein').delay(300).fadeTo(400,1,'easeInQuad');
    }
    $('#home-images').children('a').mouseenter(function(){
        $(this).append("<div class='overlay'></div>");
        $(this).children('.label').show();
    })
    $('#home-images').children('a').mouseleave(function(){
        $(this).children('.overlay').remove();
        $(this).children('.label').hide();
    })
    if($('.gm-slider').length > 0){
        $('.gm-slider').gmFade();
	
    }
    
    $(".VMlink").click(function() {
	$.fancybox({
		'padding'		: 0,
		'autoScale'		: false,
		'transitionIn'	: 'none',
		'transitionOut'	: 'none',
		'title'			: this.title,
		'width'			: 900,
		'height'		: 600,
		'href'			: this.href.replace(new RegExp("([0-9])","i"),'moogaloop.swf?clip_id=$1') + '&autoplay=1',
		'type'			: 'swf',
		'swf'			: {
		   	'wmode'		: 'transparent',
			'allowfullscreen'	: 'true'
		}
	});

return false;
});

$(window).resize(function(){
	resizeCheck();
});

resizeCheck();
    
}

function resizeCheck(){
	
	

	if(parseInt($(window).height()) > 628 && parseInt($('#container').height()) < 600){
		$('#table-container').css('overflow','hidden')
		$('#table-container').css('height',parseInt($(window).height())+'px');
		if(oldIE){
			//alert('test');
			if(($(window).height()-588)/2 > 30){
				$('#table-container').find('td:first').css('padding-top',($(window).height()-588)/2 + 'px');
			}else{
				$('#table-container').find('td:first').css('padding-top','30px');
			}
		}		
	}
	else{
		$('#table-container')[0].removeAttribute('style')	
	}
}

 function isInt(x) {
   var y=parseInt(x);
   if (isNaN(y)) return false;
   return x==y && x.toString()==y.toString();
 }


function viewPoloroids(self){
    $($('.gm-slider')[0]).fadeOut();
    $('#poloroids').fadeIn(function(){$(this).css('marginTop',0)});
    self.innerHTML = 'View Photos';
    
    self.setAttribute('onclick',"hidePoloroids(this)");
}

function hidePoloroids(self){
    $($('.gm-slider')[0]).css('marginBottom','-500px');
    $('#poloroids').fadeOut();
    $($('.gm-slider')[0]).fadeIn(function(){$('#poloroids').css('marginTop','-500px');$(this).css('marginBottom','0px')});
    
    self.innerHTML = 'View Poloroids';

    
    self.setAttribute('onclick',"viewPoloroids(this)");
}


	cancelNow = false;
function addToSelection(pageID,self){
	//alert('add');
    $.get(source+'actions/addToSelection.php?pageID='+pageID,function(data){
        $('#fd04f76cad5b5f5a').children('a')[0].innerHTML = 'my selection ('+data+')';
    });
    self.innerHTML = 'remove from my selection';
    self.setAttribute('onclick',"removeFromSelection('"+pageID+"',this)");
    
    if($.browser.msie){
    self.onclick = (function(pageID,self){
    	return function(){
    		if(!cancelNow){
    		removeFromSelection(pageID,self)
    		}
    		else{
    		cancelNow = false;
    		}
    	}
    
    })(pageID,self);
 	}
 	else{
	self.setAttribute('onclick',"removeFromSelection('"+pageID+"',this)");
 	}
    
     /*$(self).click(function(){
     	//alert('TEST');
     	removeFromSelection(pageID,self)
     })*/
    

}

function removeFromSelection(pageID,self){
	//alert('remove');
    $.get(source+'actions/removeFromSelection.php?pageID='+pageID,function(data){
        if(data == 0){
            $('#fd04f76cad5b5f5a').children('a')[0].innerHTML = 'my selection';
        }else{
            $('#fd04f76cad5b5f5a').children('a')[0].innerHTML = 'my selection ('+data+')';
        }
    });
    if($(self).parent().parent()[0].className == 'models'){
     $(self).parent().animate({width: '0',opacity:'0'},200);
     $(self).parent().next().animate({marginLeft:'0'},200);
    }
    
    else{
    self.innerHTML = 'add to my selection';
    
    if($.browser.msie){
    
	
    //if(cancelNowRemove){
    
    self.onclick = (function(pageID,self){
    
    	
    	return function(){
    	
    		//if(!cancelNowRemove){
    		addToSelection(pageID,self)
    		//}
    		//else{
    		//cancelNowRemove = false
    		//}
    	}
    
    })(pageID,self);
    
    }else{
    self.setAttribute('onclick',"addToSelection('"+pageID+"',this)")    
    }
	}
}

jQuery.validator.addMethod('phoneNL', function(phone_number, element) {
return this.optional(element) || phone_number.length > 9 &&
phone_number.match(/^(\(?(0|\+31)[1-9]{1}\d{1,4}?\)?\s?\d{3,4}\s?\d{3,4})$/);
}, 'Enter a valid phone number');

jQuery.validator.addMethod("dateNL", function(value, element) { 
		return this.optional(element) || /^\d\d?[\.\/-]\d\d?[\.\/-]\d\d\d\d$/.test(value);
	}, "Vul hier een geldige datum in. bv(24-09-1979)"
);
jQuery.validator.messages.required = '<img src="' + source + 'images/error.png" alt="Error..." />';
jQuery(function() {
	// show a simple loading indicator
	jQuery().ajaxStart(function() {
		$(".submit").html('<img src="' + source + 'images/form/loader.gif" alt="loading..." /> Uw formulier wordt verwerkt. Een ogenblik geduld...');
	}).ajaxStop(function() {
		//loader.hide();
	}).ajaxError(function(a, b, e) {
		throw e;
	});

	var v = jQuery("#form").validate({
		submitHandler: function(form) {
			jQuery(form).ajaxSubmit({
				target: "#form_container"
			});
		}
	});

	jQuery("#reset").click(function() {
		v.resetForm();
	});
});
$.extend($.validator.messages, {
	required: '<div class="error_image"><img src="' + source + 'images/error.png" alt="Error..." /></div>',
	maxlength: $.format("U kunt niet meer dan {0} karakters invoeren."),
	minlength: $.format("U dient minimaal {0} karakters in te voeren."),
	rangelength: $.format("U dient minimaal {0} en maximaal {1} karakters in te voeren."),
	email: "A valid e-mailaddress is required.",
	url: "Een geldig webadres is verplicht.",
	date: "Een geldige datum is verplicht.",
	number: "Een geldig getal is verplicht.",
	digits: "Gebruik alleen cijfers.",
	equalTo: "Herhaal de invoer nogmaals.",
	range: $.format("U dient een waarde tussen {0} en {1} in te voeren."),
	max: $.format("U dient een waarde kleiner dan of gelijk aan {0} in te voeren."),
	min: $.format("U dient een waarde groter dan of gelijk aan {0} in te voeren."),
	creditcard: "Een geldig creditcardnummer is verplicht."
});

// autoDropDown()
// gets a suggestion list trough ajax
// (c) leanopen.nl 2009


preventReload = false;

function autoDropDown(file,id,action,e){
	if(window.event){
	e = window.event;
	}
    dropdown = document.getElementById(id+'dropdown');
    field = document.getElementById(id);
    if(window.addEventListener){
    window.addEventListener('click',autoDropDownHide,false);
    }else{
    $('body').click(autoDropDownHide);
    }


    Qvalue = field.value;
    // xj_message(action);

    if(action == 'checkNeed'){
        if(Qvalue == ''){
            dropdown.style.display = 'none';
        }
    }else if(action == 'focus'&&dropdown.innerHTML){
        dropdown.style.display = 'block';
    }else if(e && e.keyCode == '40' && dropdown.innerHTML && action=='arrows'){
    	if(window.event){
    	event.returnValue = false;
    	}
    	else{
        e.preventDefault();
        }
        preventReload = true;
        rows = dropdown.childNodes;
        setDef = false;
        for (i=0;i<rows.length;i++)  {
            if(rows[i].className == 'selected' && rows[i+2] && !setDef){
                rows[i+1].className = 'selected';
                rows[i].className = 'normal'
                setDef = true;
            }else if(rows[i+1] && setDef){
                rows[i+1].className = 'normal'
            }
        }
    }else if(e && e.keyCode == '38' && dropdown.innerHTML && action=='arrows'){
        if(!window.event){
        e.preventDefault();
        }
        preventReload = true;
        rows = dropdown.childNodes;
        setDef = false;
        for (i=rows.length-1; i>=0; i--){
            if(rows[i].className == 'selected' && rows[i-1] && !setDef){
                rows[i-1].className = 'selected';
                rows[i].className = 'normal'
                setDef = true;
            }else if(rows[i-1] && setDef){
                rows[i-1].className = 'normal'
            }
        }
    }else if(action=='arrows' && e.keyCode == '13'){
        preventReload = true;
        rows = dropdown.childNodes;
        for (i=0;i<rows.length;i++){
            if(rows[i].className == 'selected'){
                link = rows[i].getAttribute('link');
                if(link){
                    window.location.href = link;
                }
            }
        }
        dropdown.style.display = 'none';
    }else if(action=='arrows' && e.keyCode != '38' && e.keyCode != '40'){
        preventReload = false;
    
    }else if(!preventReload&&action=='query'&& e.keyCode != '37' && e.keyCode != '39'&& e.keyCode != '91'&& e.keyCode != '18'&& e.keyCode != '17'&& e.keyCode != '93'&& e.keyCode != '16'&& e.keyCode != '20'){
        dropdown.style.width = parseInt(field.offsetWidth)-2+'px';
        dropdown.style.display = 'block';
        $.get(file+'?q='+Qvalue+'&ID='+id,function(data,status){
            $('#'+id+'dropdown').html(data);
            autoDropDown('',id,'checkNeed')
        });
    }

    

}

function autoDropDownHide(e){
    if(e.target.parentNode.className != 'autodropdown' && e.target.className != 'autodropdownfield'){
        allDivs = document.getElementsByTagName('div');
        for (i=0;i<allDivs.length;i++)    {
            if(allDivs[i].className == 'autodropdown'){
                allDivs[i].style.display = 'none';
            }
        }
    }
}

function fillEmailMessage(){
    SelUid = giveUnusedID();
    var msg = "Dear Name Recipient,\n\nI would like to propose the following model selection I made at deboekers.nl, please click this link:\n\n"+source+"view-selection.html?selectionID="+SelUid+"\n\nRegards,\n\nYour Name";
    $('#db-popup').find('textarea').val(msg);
    
    window.yourName = $('#yourName')[0].value;
    $('#yourName').blur(function(){
        $('#db-popup').find('textarea')[0].value =  $('#db-popup').find('textarea')[0].value.replace(window.yourName,this.value); 
        window.yourName = this.value;
    })
    
    window.recpName = $('#recpName')[0].value;
    $('#recpName').blur(function(){
        $('#db-popup').find('textarea')[0].value =  $('#db-popup').find('textarea')[0].value.replace(window.recpName,this.value); 
        window.recpName = this.value;
    })
    
    $('#sendSel').find('input').focus(function(){
        $(this).removeClass('error');
    })
    
    $('#sendSel').submit(function(e){
        error = false;
        $('#sendSel').find('input').each(function(){
                if(this.value == 'Your Name' || this.value == 'Your Email' || this.value == 'Name Recipient' || this.value == 'Email Recipient' || this.value == ''){
                $(this).addClass('error');
                error = true;
            }
        })
        
        e.preventDefault();
        if(!error){
        $.get(source+'actions/sendSelection.php?id='+SelUid+'&'+$(this).serialize(),function(){
        closePopup();
        
        rollIntopbar('#000050',3,"Your selection has been sent");            
        
        });
        }
    })    
}

function fillRequestMessage(){
    SelUid = giveUnusedID();
    var msg = "Dear Boekers,\n\nI would like to request the following model selection I made at deboekers.nl:\n\n"+source+"view-selection.html?selectionID="+SelUid+"\n\nRegards,\n\nYour Name";
    $('#db-popup').find('textarea').val(msg);
    
    window.yourName = $('#yourName')[0].value;
    $('#yourName').blur(function(){
        $('#db-popup').find('textarea')[0].value =  $('#db-popup').find('textarea')[0].value.replace(window.yourName,this.value); 
        window.yourName = this.value;
    })
    
    window.recpName = $('#recpName')[0].value;
    $('#recpName').blur(function(){
        $('#db-popup').find('textarea')[0].value =  $('#db-popup').find('textarea')[0].value.replace(window.recpName,this.value); 
        window.recpName = this.value;
    })
    
    $('#sendSel').find('input').focus(function(){
        $(this).removeClass('error');
    })
    
    $('#sendSel').submit(function(e){
        error = false;
        $('#sendSel').find('input').each(function(){
                if(this.value == 'Your Name' || this.value == 'Your Email' || this.value == ''){
                $(this).addClass('error');
                error = true;
            }
        })

		if( isValidEmailAddress( $('#senderEmail').val() ) == false ) {
			$('#senderEmail').addClass('error');
			error = true;
		}
        
        e.preventDefault();
        if(!error){
        $.get(source+'actions/sendSelection.php?id='+SelUid+'&'+$(this).serialize(),function(){
        closePopup();
        
        rollIntopbar('#000050',3,"Your selection has been sent");            
        
        });
        }
    })    
}

function sendSubscription(){
    SelUid = giveUnusedID();

    $('#sendSub').find('input').focus(function(){
        $(this).removeClass('error');
    })
    
    $('#sendSub').submit(function(e){
        error = false;
        $('#sendSub').find('input').each(function(){
             if(this.value == 'Your Firstname' || this.value == 'Your Surname' || this.value == 'Your E-mailaddress' || this.value == ''){
                $(this).addClass('error');
                error = true;
            }
        })

		if( isValidEmailAddress( $('#yourEmailaddress').val() ) == false ) {
			$('#yourEmailaddress').addClass('error');
			error = true;
		}
		if( $('#checkWomen').attr('checked') == false && $('#checkMen').attr('checked') == false ) {
			$('#checkWomen').parent().addClass('errorText');
			$('#checkMen').parent().addClass('errorText');
			error = true;
		}
        
        e.preventDefault();
        if(!error){
        $.get(source+'actions/sendSubsription.php?idMen='+giveUnusedID()+'&idWomen='+giveUnusedID()+'&'+$(this).serialize(),function(){
        closePopup();
        
        rollIntopbar('#000050',3,"Your subscription has been sent");            
        
        });
        }

    })    
	
}

function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}

function popup(title,content,width,height){
    $('body').append("<div id='db-overlay'></div>");
    $('body').append("<div id='db-popup'><h2>"+title+"<a class='close' onclick='closePopup()' href='javascript:void(0)'>X</a></h2><div class='inner'>"+content+"</div></div>");

    doValTag();    
    
    
    $('#db-popup').css('width',width+'px');
    $('#db-popup').css('height',height+'px');
    
    
    $('#db-popup').css('marginLeft:',-1*width/2+'px');
    $('#db-popup').css('marginTop',-1*height/2+'px');
}

function closePopup(){
    $('#db-overlay').fadeOut(100,function(){$(this).remove()}); 
    $('#db-popup').fadeOut(100,function(){$(this).remove()}); 
}

function giveUnusedID(){

   var chars = '0123456789abcdef'.split('');

   var uuid = [], rnd = Math.random, r;
   uuid[8] = uuid[13] = uuid[18] = uuid[23] = '';
   uuid[14] = '4'; 

   for (var i = 0; i < 30; i++)
   {
      if (!uuid[i])
      {
         r = 0 | rnd()*16;

         uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r & 0xf];
      }
   }

   return uuid.join('');
}


function rollIntopbar(color,rollouttime,value){
if(!document.getElementById('error')){
errordiv = document.createElement('div');
errordiv.id = 'error';
errordiv.style.position = 'fixed';
errordiv.style.top = '-34px';
errordiv.style.left = '0px';
errordiv.style.width = '100%';
errordiv.style.height = '24px';
errordiv.style.paddingTop = '10px';
errordiv.style.color = '#FFF';
errordiv.style.textAlign = 'center';
errordiv.style.fontFamily = 'Georgia';
errordiv.style.fontSize = '15px';
errordiv.style.fontWeight = 'normal';
errordiv.style.zIndex = '100';
document.body.insertBefore(errordiv,document.body.childNodes[0]);
}
if(!document.getElementById('shadow')){
shadowdiv = document.createElement('shadow');
shadowdiv.id = 'shadow';
shadowdiv.style.backgroundImage = "url('http://commons.leanopen.nl/img/topbar_shadow.png')";
shadowdiv.style.width = '100%';
shadowdiv.style.height = '10px';
shadowdiv.style.position = 'fixed';
shadowdiv.style.left = '0px';
shadowdiv.style.top = '-10px';
shadowdiv.style.zIndex = '100';
document.body.insertBefore(shadowdiv,document.body.childNodes[1]);
}

document.getElementById('error').innerHTML = value;
if(!color){
color = '#FF0000';
}
document.getElementById('error').style.backgroundColor = color;
if(rollouttime){
hoesnel3 = 10 //in milliseconden
div3 = document.getElementById('shadow');
div4 = document.getElementById('error');
timer3 = rollouttime*1000;
i5 = 0;
for (i4=34;i4>=-10;i4--) 
{
setTimeout("div4.style.top = '"+i5+"px'",timer3);
setTimeout("div3.style.top = '"+i4+"px'",timer3);
timer3 = timer3+hoesnel3;
i5--;
}	
}
hoesnel2 = 10 //in milliseconden
div3 = document.getElementById('shadow');
div4 = document.getElementById('error');
timer2 = 0;
i3 = -34;
for (i2=0;i2<=34;i2++) 
{
setTimeout("div4.style.top = '"+i3+"px'",timer2);
setTimeout("div3.style.top = '"+i2+"px'",timer2);
timer2 = timer2+hoesnel2;
i3++;
}
} 
