
	
// Main Page SlideShow ----------------------------------------------------------------------------------------
var flashvars = {};
flashvars.slideTime = 6;
flashvars.transitionTime = 3;
flashvars.xmlUrl = '/content/flash/slideshow.xml';

var flashvarsLogos = {};
flashvarsLogos.speed = 1;
flashvarsLogos.maxSpeed = 35;
flashvarsLogos.xmlUrl = '/content/flash/logos.xml';

var params = {};
params.menu = 'false';
params.wmode = 'transparent';

var attributes = {};
attributes.id = 'myDynamicContent';
attributes.name = 'myDynamicContent';

var attributesLogo = {};
attributes.id = 'myLogos';
attributes.name = 'myLogos';

swfobject.embedSWF('/content/flash/slideshow.swf', 'FlashContainer', '375', '451', '9.0.0','/content/flash/expressInstall.swf', flashvars, params, attributes);
swfobject.embedSWF('/content/flash/logos.swf', 'FlashLogos', '638', '55', '9.0.0','/content/flash/expressInstall.swf', flashvarsLogos, params, attributesLogo);

// jQuery ----------------------------------------------------------------------------------------
var hoverDelay = 1000; //De tijd dat dropout menu actief blijft als eruit wordt gegaan met de muis
var activeHover; //Indien gevuld dan is een scroll menu hover actief
var activeMenu;
var dropOuts;
var dropOutsNumber = 0; //Als dropOutsNumber > 4, sta dan dropOut niet toe
var enableHover; //Sta dropOut hover toe zodra timeout is afgelopen

var heightUL; //De hoogte van een alle links totaal
var scrollWindow; //De hoogte van de opgevraagde scroll window
var menuOpen = false; //Geeft aan of het hoofdmenu momenteel open is
var keyDown = '';
var filtering;
var filter;
var listItems = 0;
var listString;
var listText;
var scrollTop;
var scrollPane;
var scrollPaneTop;

function resetScroll()
{
	scrolling = false;
}
function hoverOut()
{
	$(activeMenu).find('div.dropOut').slideUp(500);
	menuOpen = false;
}

$(document).ready(function() {


    // Gallery ----------------------------------------------------------------------------------------
	/*
	$.Lightbox.construct({
		"show_linkback": false,
		"download_link": false,
		"show_extended_info": true
	});

	$('div.infoBox img').each(function(index)
	{
		var imageName = $(this).parents('div.infoBox').find('div.infoTitle').text();
		var imageSrc = $(this).attr('src');
		
		imageSrc = imageSrc.replace('medium', 'large');
		
		$(this).wrap('<a title="' + imageName + '" href="' + imageSrc + '" />');
		//$(this).parent('a').lightbox();
	});

	$('table.selectType img').each(function(index)
	{
		var imageName = $(this).parents('li').find('div.selectInfo').text();
		var imageSrc = $(this).attr('src');
		
		imageSrc = imageSrc.replace('small', 'large');
		
		$(this).wrap('<a title="' + imageName + '" href="' + imageSrc + '" />');
		//$(this).parent('a').lightbox();
	});
	*/
	
	var isOverview = false;
	if ($('div#infoContainer > div.infoBox').length > 0)
	{
		isOverview = true;
	}
	
	$('div#infoContainer > div.productInfo > div.type ul.selectType li, div#infoContainer > div.infoBox').each(function(index)
	{
		var id = 'Product' + (index + 1);

		var lightboxContent = $(this).find('div.lbContent');
		
		if (lightboxContent.length == 0)
		{
			$(this).append('<div class="lbContent" id="' + id + '" />');
			
			lightboxContent = $(this).find('div.lbContent');
			
			if (isOverview == true)
			{
				var text = $(this).find('div.infoTitle div.product').clone().appendTo(lightboxContent);
				text.html($.trim(text.text()));
				
				var image = $(this).find('table img').clone().appendTo(lightboxContent);
				image.attr('src', image.attr('src').replace('small', 'large'));
				image.wrap('<div class="image" />');
				
				$(this).find('div.information p').clone().appendTo(lightboxContent).wrap('<div class="content" />');
			}
			else
			{
				var text = $(this).find('div.selectInfo p span').eq(0).clone().appendTo(lightboxContent).wrap('<div class="product" />');
				//var text = $('div.productInfo div.infoTitle div.product').clone().appendTo(lightboxContent);
				text.html($.trim(text.text()));
				
				var image = $(this).find('table img').clone().appendTo(lightboxContent);
				image.attr('src', image.attr('src').replace('small', 'large'));
				image.wrap('<div class="image" />');
				
				$(this).find('div.selectInfo p span').eq(1).clone().appendTo(lightboxContent).wrap('<div class="content" />').css('display','block');
			}
			
			lightboxContent.append('<div class="clear">&nbsp;</div>');
			
		}

		//$(this).find('> div.selectInfo div.bestelAantal div.bestelForm, > div.information div.buttons').append('<a class="iLink thickbox" href="#TB_inline?inlineId=' + id + '">i</a>');
		//$(this).find('> div.selectInfo div.bestelAantal div.bestelForm, > div.information div.buttons').append('<a class="iLink " href="#' + id + '">i</a>');
		
		$(this).find('> div.selectInfo, > div.information div.buttons').append('<a class="iLink " href="#' + id + '">i</a>');
		
		$(this).find('table img').click(function()
		{
			if ($(this).parents('div.productInfo').hasClass('opened')) return false;
			
			$(this).parents('table').parent().find('a.iLink').click();
			return false;
		});
		
	});
	
	$('a.iLink').colorbox({ inline: true, innerWidth: '900px' });
	
	// Main menu ----------------------------------------------------------------------------------------
    $('div#mainMenu ul li').not('div#mainMenu ul li ul li').mouseenter(function() {
																				
		listItems = $(this).find('ul li').length;

        if (activeHover) {
            if (activeMenu.html() == $(this).html()) {
                clearTimeout(activeHover);
            }
            else {
                hoverOut();
                clearTimeout(activeHover);
            }
        }

        dropOuts = $(this).find('div.dropOut');

        if ($(dropOuts).attr('class') != 'dropOut heightSet') //Set dropOut active en non active om de hoogtes te bepalen
        {
            $(dropOuts).addClass('active');

            heightUL = $(this).find('ul').height();
            scrollWindow = $(this).find('div.scrollWindow').height();

            if (heightUL <= scrollWindow) {
                $(this).find('div.scrollWindow').css({ 'height': scrollWindow - (scrollWindow - heightUL) + 'px' });
            }

            $(dropOuts).removeClass('active');
        }

        if (dropOutsNumber < 4) {
            clearTimeout(enableHover);
            dropOutsNumber++;
            enableHover = setTimeout(function() { dropOutsNumber = 0 }, 500);
            $(dropOuts).slideDown(500);
        }
        else {
            clearTimeout(enableHover);
            enableHover = setTimeout(function() { dropOutsNumber = 0 }, 500);
        }
        $(dropOuts).addClass('heightSet');
						
		if (listItems > 5)
		{
			$(this).find('div.scrollWindow').jScrollPane(
			{
				scrollbarWidth: 15,
				dragMaxHeight: 15,
				animateTo: true
			});
		}
		
		menuOpen = true;

    });

    $('div#mainMenu ul li').not('div#mainMenu ul li ul li').mouseleave(function() {
        activeMenu = $(this);
        activeHover = setTimeout(hoverOut, hoverDelay);
    });

    $('div#mainMenu ul li div.scrollWindow a').click(function() {
        var parent = $(this).parents('ul li').eq(1);
        var index = $('div#mainMenu ul li').not('div#mainMenu ul li ul li');
        var result = index.index(parent);

        var clicked = $(this).text();
        Cufon.replace($('div#mainMenuBottom ul li a').eq(result).text(clicked));

        activeMenu = $(this).parents('ul li');

        //hoverOut();
    });
	
	$(document).keydown(function(event)
	{
		if (menuOpen == true)
		{
			clearTimeout(filtering);
			keyDown = keyDown + String.fromCharCode(event.keyCode);
			filter = new RegExp('\\b' + keyDown, 'i');
			
			if (event.keyCode >= 65 && event.keyCode <= 90 || event.keyCode >= 48 && event.keyCode <= 57)
			{
				$('div#SiteContainer div#SearchInput').remove();
				$('div#SiteContainer').append('<div id="SearchInput"><div class="text">' + keyDown + '</div></div>');
			}
			
			filtering = setTimeout(function(){jumpToItem(); keyDown = '';}, 500);
		}
	});
	
	$('input.productSearch').hover(function()
	{
		$(this).addClass('hover');
	},
	function()
	{
		$(this).removeClass('hover');
	});
	
	function jumpToItem()
	{
		$('div#SiteContainer div#SearchInput').remove();
		
		for (i = 0; i < listItems; i++)
		{
			listString = dropOuts.find('div.scrollWindow ul li a:eq(' + i + ')');
			listText = listString.text();
			listText = listText.replace(/ /gi,'');
			listText = listText.replace(/\./gi,'');
			listText = listText.replace(/\'/gi,'');
			listText = listText.replace(/-/gi,'');
			listText = listText.replace(/\*/gi,'');
			listText = listText.replace(/\//gi,'');
			listText = listText.replace(/&/gi,'');
			
			if ( listText.match(filter) && listString.text() != 'Toon alles')
			{
				scrollTop = listString.parent().position().top;
				scrollPane = listString.parents('div.jScrollPaneContainer').find('div.jScrollPaneTrack').height();
				scrollPaneTop = scrollTop * (scrollPane / heightUL);
				
				listString.parents('div.scrollWindow')[0].scrollTo(scrollTop);
				return;
			}
		}
	}

    //Uitgebreid product informatie tonen  -------------------------------------------------------

    var parent;
    var infoOpen = false;
    var even = false;
    var currentScroll;
    var currentProduct;
    var slideSpeed = 600;
	var smallInfo;
	var topPos;
	
	if ($('div#infoContainer').html() != null)
	{
		if ($('div#infoContainer').hasClass('productWide')) return
		
		var containerHeight = $('div#infoContainer').height();
		//var smallHeight = $('div.infoBox:eq(2)').position().top - $('div.infoBox:eq(0)').position().top;
		var smallHeight = $('div.infoBox:eq(0)').outerHeight();
	}

    /*$('div.infoBox:odd div.information a.info').click(function() {
        parent = $(this).parents('div.infoBox');
        even = false;
        showInformation();
        return false;
    });
    $('div.infoBox:even div.information a.info').click(function() {
        parent = $(this).parents('div.infoBox');
        even = true;
        showInformation();
        return false;
    });*/

    $('div.infoBox:odd div.information a.bestel').click(function() {
        if ($(this).parent().find('a.popup').html()) {
            parent = $(this).parents('div.infoBox');
            even = false;
			
			smallInfo = $(this).parents('div.infoBox');
			
            showInformation();
            return false;
        }
    });
    $('div.infoBox:even div.information a.bestel').click(function() {
        if ($(this).parent().find('a.popup').html()) {
            parent = $(this).parents('div.infoBox');
            even = true;
			
			smallInfo = $(this).parents('div.infoBox');
			
            showInformation();
            return false;
        }
    });

    function showInformation() {
		
		topPos = $(smallInfo).position().top;
		
		if (( containerHeight - topPos ) < ( smallHeight * 3 ))
		{
			topPos = containerHeight - ( smallHeight * 4 - 40 );
		}
		
        if (currentProduct) {
            $('div.opened').removeClass('opened');
            currentProduct.slideUp(0);
        }

        currentScroll = 'div.productInfo';
        currentProduct = $(parent).next('div.productInfo');
		
		$(currentProduct).css('top',topPos);

        createScroll();

        if (even == true)
            currentProduct.addClass('productRight');

        if (!infoOpen)
            currentProduct.slideDown(slideSpeed);
        else
            currentProduct.show(0);

        currentProduct.addClass('opened');
        infoOpen = true;

        currentProduct.find('a.closeWindow').click(function() {
            currentProduct.slideUp(slideSpeed);
            infoOpen = false;
            return false;
        });
    }
    function createScroll() {
        // Direct show en hide van productInfo om scrollbars toe te voegen
        currentProduct.show(0);
        makeScrollBars();
        currentProduct.hide(0);
    }


    //Wissel de merk informatie op de thuispagina -----------------------------------------------------
	
	if ($('div#homeElements').attr('class') == 'backoffice')
	{
		$('div#homeElements div.homeElement').css('display','block');
	}
	else
	{
		var infoMerken = $('div#homeElements div.homeElement');
		var aantalMerken = infoMerken.length;
		var firstMerk = 0;
		var	secondMerk = firstMerk + 1;
		var fadeDuration = 9000;
		var fadeSpeed = 400;
	
		$(infoMerken).eq(firstMerk).show(0);
		$(infoMerken).eq(secondMerk).show(0);
		
		if(aantalMerken > 2)
		{
			setTimeout(merkenFadeOut, fadeDuration);
		}
	}

	function merkenFadeOut()
    {		
		$(infoMerken).eq(firstMerk).fadeOut(fadeSpeed);
		$(infoMerken).eq(secondMerk).fadeOut(fadeSpeed);
		
		setTimeout(merkenFadeIn, fadeSpeed + 200);
    }	
    function merkenFadeIn()
    {
	    firstMerk = secondMerk + 1;
    	if(firstMerk >= aantalMerken)
	    {
		    firstMerk = 0;
	    }
		
		secondMerk = firstMerk + 1;
		if(secondMerk >= aantalMerken)
		{
			secondMerk = 0;
		}
		
		$(infoMerken).eq(firstMerk).fadeIn(fadeSpeed);		
		$(infoMerken).eq(secondMerk).fadeIn(fadeSpeed);
		
		setTimeout(merkenFadeOut, fadeDuration);
    }


    //Verwijder de border-bottom van het laatste Li item in ProductInformatie Type -----------------------------------------------------

    function removeBorder() {
        var lastLi = $('div.productInfo div.type ul.selectType').find('li');
        var countLi = lastLi.length;

        var removeBorder = lastLi.eq(countLi - 1);

        removeBorder.css(
		{
		    'borderBottom': 0
		});
    }


    //Rechter Menu ---------------------------------------------------------------------------------------

    if ($('ul.login li div#loginDropOut').html() != '') {
        $('ul.login li').not('ul.login li li').addClass('active');
        $('ul.login li a.title').toggle(
			function() {
			    $('div#loginDropOut').slideUp('slow');
			    $('ul.login li').removeClass('active');
			    $('ul.login li a.title').attr({ title: 'Inloggen Uitklappen' })
			},
			function() {
			    $('div#loginDropOut').slideDown('slow');
			    $('ul.login li').not('ul.login li li').addClass('active');
			    $('ul.login li a.title').attr({ title: 'Inloggen Inklappen' })
			});
    }
    else {
        $('ul.login').addClass('empty');
    }			   

    if ($('ul.happyHairService li').length > 1) {
        $('ul.happyHairService li').not('ul.happyHairService li li').addClass('active');
        $('ul.happyHairService li a.title').toggle(
			function() {
			    $('div#serviceDropOut').slideUp('slow');
			    $('ul.happyHairService li').removeClass('active');
			    $('ul.happyHairService li a.title').attr({ title: 'Happy Hair Service Uitklappen' })
			},
			function() {
			    $('div#serviceDropOut').slideDown('slow');
			    $('ul.happyHairService li').not('ul.happyHairService li li').addClass('active');
			    $('ul.happyHairService li a.title').attr({ title: 'Happy Hair Service Inklappen' })
			});
    }
    else {
        $('ul.happyHairService').addClass('empty');
    }

    if ($('ul.winkelMandje li').length > 1) {
        $('ul.winkelMandje li').not('ul.winkelMandje li li').addClass('active');
        $('ul.winkelMandje li a.title').toggle(
			function() {
			    $('ul#mandjeDropOut').slideUp('slow');
			    $('ul.winkelMandje li').removeClass('active');
			    $('ul.winkelMandje li a.title').attr({ title: 'Winkelmandje Uitklappen' })
			},
			function() {
			    $('ul#mandjeDropOut').slideDown('slow');
			    $('ul.winkelMandje li').not('ul.winkelMandje li li').addClass('active');
			    $('ul.winkelMandje li a.title').attr({ title: 'Winkelmandje Inklappen' })
			});
    }
    else {
        $('ul.winkelMandje').addClass('empty');
    }

    if ($('ul.cursussen li').length > 1) {
        $('ul.cursussen li').addClass('active');
    }
    else {
        $('ul.cursussen').addClass('empty');
    }


    // Scrollbar ----------------------------------------------------------------------------------------

    function makeScrollBars() {
        currentProduct.find('div.infoScrollable').jScrollPane(
		{
		    scrollbarWidth: 15,
		    dragMaxHeight: 15
		});
        currentProduct.find('ul.selectType').jScrollPane(
		{
		    scrollbarWidth: 15,
		    dragMaxHeight: 15
		});

        removeBorder();
    }
	
	$('div.productWide div.productInfo div.information div.infoScrollable').jScrollPane(
		{
		    scrollbarWidth: 15,
		    dragMaxHeight: 15
		});
	$('div.productWide div.productInfo div.type ul.selectType').jScrollPane(
		{
		    scrollbarWidth: 15,
		    dragMaxHeight: 15
		});


    // Selectboxes ----------------------------------------------------------------------------------------

    $('select').selectbox();


    // Input velden ----------------------------------------------------------------------------------------

    $("input.digits, input.tel").keydown(function(event) {

		if ($('span.maxpage').html())
		{
			var maxpage = parseInt($('span.maxpage').html());
		}
		
        // Allow only backspace and delete
        if (event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 16 || event.keyCode == 35 || event.keyCode == 36 || event.keyCode == 116) {
            // let it happen, don't do anything
        }
        else {
            // Ensure that it is a number and stop the keypress
            if ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105)) {
				
				var page = $(this).val();
				
				var newCode = String.fromCharCode(event.keyCode);
				
				if ((event.keyCode >= 96 && event.keyCode <= 105))
				{
					newCode = event.keyCode - 96;
				}
				
				page = page + '' + newCode;
				
				if (parseInt(page) > 0)
				{
					if ($(this).attr('class') == 'digits page' && parseInt(page) <= maxpage)
					{
						
					}
					else if ($(this).attr('class') == 'digits' || $(this).attr('class') == 'tel active')
					{
						
					}
					else
					{
						event.preventDefault();
					}
				}
				else if (parseInt(page) == 0 && $(this).attr('class') == 'tel active')
				{
					
				}
				else
				{
					event.preventDefault();
				}

            }
            else {
                event.preventDefault();
            }
        }
	});
	
/*	$("input.productNummer").focus(function () {
		if ($(this).val() == 'zoek op productnummer')
		{
			$(this).val('');
		}
		
	});
	$("input.productNummer").blur(function () {
		if ($(this).val() == '')
		{
			$(this).val('zoek op productnummer');
		}
		
	});*/


    // Cufon Font Replacement ----------------------------------------------------------------------------------------

    Cufon.replace('h1');
    Cufon.replace($('div#mainMenu ul li ul li a').get(), {
        hover: {
            color: '#d06b15'
        }
    });
    Cufon.replace($('div#mainMenu ul li a').get());
    Cufon.replace($('div#mainMenuBottom ul li a').get());
    Cufon.replace($('div.button').get());
    Cufon.replace($('ul.dropOutMenu li a.title').get(), {
        hover: {
            color: '#5d5d5d'
        }
    });
    Cufon.replace($('div#ContentContainer div#Steps div.step a').get());
	Cufon.replace($('input.productSearch'));
	
	// Validate new address form ---------------------------------------------------------------------------------------------
	$('div.address input').focus(function()
	{
		$(this).parents('div.row').find('div.error').html('');
		$(this).addClass('active');
	});
	
	$('input').blur(function()
	{
		$(this).removeClass('active');
		//validateField($(this));
	});
	
/*	$('a.validateButton').click(function()
	{
		validateForm();
		return false;
	});*/

	$('div#contentBox div.addressContainer div.newAddress div.radio input').click(function()
	{
		$(this).parents('div.newAddress').find('div.addressform').css('display','block');
		$(this).parents('div.newAddress').find('div.addressform select').selectbox();
	});
	
	$('div#ContentContainer div#Steps div.step.active a, div#ContentContainer div#Steps div.step.noclick a').click(function()
	{
		return false;
	});

    // End of jQuery ---------------------------------------------------------------------------------------------
});

function validateForm()
{
	var errors = $('div.row div.error').length;
	
}

function validateField(field)
{
	var tag = field.get(0).tagName.toLowerCase();
	var value = '';
	var error = '';
	var label = field.parents('div.row').find('div.label').html();
	label = label.replace(':','');
	
	//field.parent('div').removeClass('ok error');
	
	if (tag == 'input')
	{
		
		if (field.attr('type') == 'text')
		{
			value = field;
		}
		else if (field.attr('type') == 'radio')
		{
			value = field.parent('div').find(':checked');
		}
		else if (field.attr('type') == 'checkbox')
		{
			value = field.parent('div').find(':checked');
		}
		
	}
	/*else if (tag == 'select')
	{
		value = field.parent('div').find(':selected');
	}*/
	
	if (value.length > 0 && value.val().length > 1)
	{
		
		if (field.attr('validate'))
		{
			
			var check = field.attr('validate').split(';');
			
			for (iCheck = 0; iCheck < check.length; iCheck++)
			{
				var rule = check[iCheck].split('=');
				
				//Rules
				if (rule[0] == 'min')
				{
					
					if (field.val().length < rule[1])
					{
						alert('Min ' + rule[1]);
					}
					else
					{
						alert('Min ' + rule[1] + ' = OK');
					}
					
				}
				
				else if (rule[0] == 'email')
				{
					var filter = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
					
					if (!filter.test(value.val()))
					{
						error = 'Onjuist e-mail adres';
					}
					else
					{
						error = '';
					}
					
					showError(value, error);
					
				}
				
				/*else if (rule[0] == 'check')
				{
					var ref = $('div#Register input#' + rule[1]);
					
					if (value.val() == ref.val())
					{
						error = '';
					} 
					else
					{
						error = 'Passwords do not match';
					}
					
					showError(value, error);
				}*/

				/*else if (rule[0] == 'password')
				{
					var weak = /[A-Z0-9]/;
					var medium = /[0-9]/;
					var strong = /([a-z][A-Z][0-9])+([A-Z][0-9])+/;
					
					if (!weak.test(value.val()) && value.val().length < 4)
					{
						error = 'weak password';
					}
					else if (!medium.test(value.val()) && value.val().length >= 4)
					{
						error = 'medium password';
					}
					else if (!strong.test(value.val()) && value.val().length >= 6)
					{
						error = 'strong password';
					}
					else if (value.val().length > 4)
					{
						error = 'medium password';
					}
					else
					{
						error = 'weak password';
					}
					
					showError(value, error);
				
					field.parent().addClass('ok');
					error = '';
					
					return;
					
				}*/

			}
			
			if (error != '')
			{
				//field.parent().addClass('error');
				return;
			}
			
		}
		
		field.parent().addClass('ok');
		
		error = '';
		showError(field, error);
		
		return error;
		
	}
	else
	{
		//error = field.parents('div.row').find('div.label').html().replace(':','');
		error = '*'
		showError(field, error);
		
		//field.parent().addClass('error');
		//return 'error in ' + field.attr('name') + "\r\n";
	}
	
}

function showError(field, error)
{
	$(field).removeClass('active');
	$(field).parents('div.row').find('div.error').html(error);
}

function ObjClear(obj, defaultText) {
    if (obj.value == defaultText) {
        obj.value = '';
    }
}
function ObjSet(obj, defaultText) {
    if (obj.value == '') {
        obj.value = defaultText;
    }
}
