// JavaScript Document
$(document).ready(function() {
	$('a[rel=external]').each(function(){
		$(this).attr('target','_blank');
	})
	
	
	
	$('input[type=text],input[type=password],textarea').each(function(){
		if($(this).attr('fail') != 1){
			$(this).attr('textvalue', $(this).val());
		}
	})
	$('input[type=text],input[type=password],textarea').bind('focus', function(){
		//$(this).val('');
		if($(this).val() == $(this).attr('textvalue')){
			$(this).val('');
			if($(this).is('.textField') || $(this).is('.textArea')){
				$(this).css('color', '#353434');
			}
		}
	})
	
	$('input[type=text],input[type=password], textarea').bind('blur', function(){
		//$(this).val('');
		if($(this).val() == ''){
			$(this).val($(this).attr('textvalue'));
			if($(this).is('.textField') || $(this).is('.textArea')){
				$(this).css('color', '#7d7b7a');
			}
		}
	})
	
	
	

	$('.play').hide();
	//var count=1;
	$('.slider .photocontainer .noFrame').cycle({ 
		fx:     'fade', 
		speed:  'fast',
		pauze:	1
	});
	
	$('.slider.noplay .photocontainer .noFrame').cycle('pause');
	$('.slider.noplay .slidernav .pauze').hide();
	$('.slider.noplay .slidernav .play').show();
	
	$('.pauze').bind('click', function(){
		$(this).parent('div').parent('.slidernav').parent('.slider').find('.photocontainer').find('.noFrame').cycle('pause');
		$(this).hide();
		$(this).parent('div').find('.play').show();
	})
	
	$('.play').bind('click', function(){
		$(this).parent('div').parent('.slidernav').parent('.slider').find('.photocontainer').find('.noFrame').cycle('resume');
		$(this).hide();
		$(this).parent('div').find('.pauze').show();
	})
	
	$('.next').bind('click', function(){
		$(this).parent('div').parent('.slidernav').parent('.slider').find('.photocontainer').find('.noFrame').cycle('pause');
		$(this).parent('div').find('.pauze').hide();
		$(this).parent('div').find('.play').show();
		$(this).parent('div').parent('.slidernav').parent('.slider').find('.photocontainer').find('.noFrame').cycle('next');
	})
	
	$('.prev').bind('click', function(){
		$(this).parent('div').parent('.slidernav').parent('.slider').find('.photocontainer').find('.noFrame').cycle('pause');
		$(this).parent('div').find('.pauze').hide();
		$(this).parent('div').find('.play').show();
		$(this).parent('div').parent('.slidernav').parent('.slider').find('.photocontainer').find('.noFrame').cycle('prev');
	})
	
	$('.max').bind('click', function(){
		$(this).parent('div').parent('.slidernav').parent('.slider').find('.photocontainer').find('.noFrame').cycle('pause');
		$(this).parent('div').find('.pauze').hide();
		$(this).parent('div').find('.play').show();
		$(this).parent('div').parent('.slidernav').parent('.slider').find('.photocontainer').find('.noFrame').find('a').each(function(){
			if($(this).css('opacity') == 1){
				$(this).trigger('click');
			}
		});
	})
	
	$(".slidernav img").hover(function () {
		$(this).attr('src', $(this).attr('src').replace($(this).attr('rel'), $(this).attr('rel')+'_hover'));
		}, function () {
		$(this).attr('src', $(this).attr('src').replace($(this).attr('rel')+'_hover', $(this).attr('rel')));
	});
	
	$(".photocontainer a").fancybox({
		'overlayOpacity': 0.9,
		'hideOnContentClick' : false
	});
	
	$("a.fancylarge").fancybox({
		'overlayOpacity': 0.9,
		'hideOnContentClick' : false
	});
	
	$('a[href=#video]').fancybox({
		'overlayOpacity': 0.9,
		'frameWidth': 640,
		'frameHeight': 363,
		'hideOnContentClick' : false,
		'callbackOnClose': function() {
			$("#fancy_content").empty();
		},
		'callbackOnShow' : function() {
			$("#fancy_content").html('<div id="video_content"></div>')
			loadVideo("video_content", "/media/flv/fashion_show.flv");
		}
	});
	$('a[href=#video2]').fancybox({
		'overlayOpacity': 0.9,
		'frameWidth': 640,
		'frameHeight': 363,
		'hideOnContentClick' : false,
		'callbackOnClose': function() {
			$("#fancy_content").empty();
		},
		'callbackOnShow' : function() {
			$("#fancy_content").html('<div id="video_content"></div>')
			loadVideo("video_content", "/media/flv/MarieClaireShowH264-Clip0.flv");
		}
	});
	$('a[href=#video3]').fancybox({
		'overlayOpacity': 0.9,
		'frameWidth': 640,
		'frameHeight': 363,
		'hideOnContentClick' : false,
		'callbackOnClose': function() {
			$("#fancy_content").empty();
		},
		'callbackOnShow' : function() {
			$("#fancy_content").html('<div id="video_content"></div>')
			loadVideo("video_content", "/media/flv/mczoute-nvhz-2011.flv");
		}
	});
	
	$('a.productImage').fancybox();
	
	$('img[alt=noslide]').tooltip({
		showURL: false
	});
	
	$('#bookbtn, #nvhzbtn, #zgpbtn').tooltip({showURL: false});
	
	$(document).pngFix();
	
	//loginform
	var lf = $('#loginform input');
	lf.focus(function(){$(this).select();});
	lf.blur(function(){
		if($(this).val() == ''){
			$(this).val('Code');
		};
	});
	
	$('#newsLetter').focus(function(){
		if($(this).val() == 'uw e-mailadres'){
			$(this).val('');
			/*$(this).css({'color':'#282828'})*/
		}
	})
	
	$('#newsLetter').blur(function(){
		if($(this).val() == '' || $(this).val() == 'uw e-mailadres'){
			$(this).val('uw e-mailadres');
			/*$(this).css({'color':'#bbb'})*/
		}
	})
	
	$('#newsLetterBtn').bind('click', function(){
		var email = $('#newsLetter').val();
        var lang = $('html').attr('lang');
		if(!validMail(email)){
            if(lang == 'nl'){
                $('#error').html('Uw e-mailadres is niet correct.');
            }else if(lang == 'fr'){
                $('#error').html('Votre e-mail n\'est pas correct.');
            }else if(lang == 'en'){
                $('#error').html('Your e-mail wasn\'t correct.');
            }
		}else{
			$.ajax({
				url		: '/ajax.php',
				type	: 'POST',
				data	: {
					emailAdres : email
				},
				success	: function(){
					$('#newsLetter').attr('disabled', 'disabled');
					$('#newsLetter').css({
						'color'	: '#ffffff',
						'background' : '#00aa00'
					})
					$('#error').html('');

					if(lang == 'nl'){
                        $('#newsLetter').val('U bent ingeschreven voor de nieuwsbrief.')
                    }else if(lang == 'fr'){
                        $('#newsLetter').val('Vous êtes maintenant inscrit à la newsletter')
                    }else if(lang == 'en'){
                        $('#newsLetter').val('You are now subscribed for the newsletter')
                    }
				}

			})
		}
	})
	
	$('#nvhzsubmit').bind('click', function() {
		
		var confcode = $('#confirmationCode').val();
		var lang = $('html').attr('lang');
		
		$.ajax({
				url		: '/ajax.php',
				type	: 'POST',
				data	: {
					confirmationcode : confcode
				},
				success	: function(data){
					eval(data);
					
					if(data.ID){
						
						$('#nvhz').find('form').remove();
						
						if(lang == 'nl'){
							$('#nvhz').append("<p style='text-align:right;font-size:14px;color:#838991;margin:20px 0 0 0'>Hallo " + data.voornaam + " " + data.naam + ",<br />Met hoeveel personen zal u aanwezig zijn?</p>");
							$('#nvhz').append('<form action="/" method="post"><input type="hidden" name="klantnr" id="klantnummer" value="'+data.klantnr+'"><div id="bookbutton"><span>Bevestigen</span></div><select id="aantal" name="amount"><option value="1">Alleen</option><option value="2">2 Personen</option></select></form>');
						}else if(lang == 'fr'){
							$('#nvhz').append("<p style='text-align:right;font-size:14px;color:#838991;margin:20px 0 0 0'>Bonjour " + data.voornaam + " " + data.naam + ",<br />Combien de personnes serez-vous là?</p>");
							$('#nvhz').append('<form action="/" method="post"><input type="hidden" name="klantnr" id="klantnummer" value="'+data.klantnr+'"><div id="bookbutton"><span>Confirmer</span></div><select id="aantal" name="amount"><option value="1">Seule</option><option value="2">2 Personnes</option></select></form>');
						}else if(lang == 'en'){
							$('#nvhz').append("<p style='text-align:right;font-size:14px;color:#838991;margin:20px 0 0 0'>Hello " + data.voornaam + " " + data.naam + ",<br />With how many people will you be there?</p>");
							$('#nvhz').append('<form action="/" method="post"><input type="hidden" name="klantnr" id="klantnummer" value="'+data.klantnr+'"><div id="bookbutton"><span>Confirm</span></div><select id="aantal" name="amount"><option value="1">Alone</option><option value="2">2 People</option></select></form>');
						}
					
					}else{
						
						if(lang == 'nl'){
							$('#confirmationCode').attr('value','Verkeerde code');
						}else if(lang == 'fr'){
							$('#confirmationCode').attr('value','Code incorrect');
						}else if(lang == 'en'){
							$('#confirmationCode').attr('value','Incorrect code');
						}
					}
				}

			})
		
		return false;
	
	});

	
	$('#bookbutton').live('click', function(){
		
		var klant = $('#klantnummer').val();
		var aantal = $('#aantal').val();
		var lang = $('html').attr('lang');
		
		$.ajax({
				url		: '/ajax.php',
				type	: 'POST',
				data	: {
					amount : aantal,
					klantnr : klant
				},
				success	: function(data){
					if(data == 1){
						$('#nvhz').find('form').remove();
						$('#nvhz').find('p').remove();
						
						if(lang == 'nl'){
							$('#nvhz').append("<p style='text-align:right;font-size:14px;color:#838991;margin:20px 0 0 0'>Dank u om u in te schrijven.</p>");
							$('#nvhz').append("<p style='text-align:right;font-size:14px;color:#838991;margin:20px 0 0 0'>Toegangsbandjes kunnen worden afgehaald bij Marie-Claire Zoute op woensdag 03, donderdag 04 en vrijdag 05 augustus 2011 tot 19.00u. Gelieve uw uitnodiging en bevestiging mee te brengen.</p>");
						}else if(lang == 'fr'){
							$('#nvhz').append("<p style='text-align:right;font-size:14px;color:#838991;margin:20px 0 0 0'>Merci pour votre inscription.</p>");
							$('#nvhz').append("<p style='text-align:right;font-size:14px;color:#838991;margin:20px 0 0 0'>Les bracelets d'accès pourront &ecirc;tre retir&eacute;s chez Marie-Claire Zoute le mercredi 03, le jeudi 04 et le vendredi 05 ao&ucirc;t 2011 jusqu'&agrave; 19h00.</p>");
						}else if(lang == 'en'){
							$('#nvhz').append("<p style='text-align:right;font-size:14px;color:#838991;margin:20px 0 0 0'>Thank you for subscribing.</p>");
							$('#nvhz').append("<p style='text-align:right;font-size:14px;color:#838991;margin:20px 0 0 0'>Toegangsbandjes kunnen worden afgehaald bij Marie-Claire Zoute op woensdag 03, donderdag 04 en vrijdag 05 augustus 2011 tot 19.00u. Gelieve uw uitnodiging en bevestiging mee te brengen.</p>");
						}
					}else{
						$('#nvhz').find('form').remove();
						$('#nvhz').find('p').remove();
						
						if(lang == 'nl'){
							$('#nvhz').append("<p style='text-align:right;font-size:14px;color:#838991;margin:20px 0 0 0'>U bent reeds ingeschreven.</p>");
							$('#nvhz').append("<p style='text-align:right;font-size:14px;color:#838991;margin:20px 0 0 0'>Toegangsbandjes kunnen worden afgehaald bij Marie-Claire Zoute op woensdag 03, donderdag 04 en vrijdag 05 augustus 2011 tot 19.00u. Gelieve uw uitnodiging en bevestiging mee te brengen.</p>");
						}else if(lang == 'fr'){
							$('#nvhz').append("<p style='text-align:right;font-size:14px;color:#838991;margin:20px 0 0 0'>Vous êtes déjà abonné.</p>");
							$('#nvhz').append("<p style='text-align:right;font-size:14px;color:#838991;margin:20px 0 0 0'>Les bracelets d'accès pourront &ecirc;tre retir&eacute;s chez Marie-Claire Zoute le mercredi 03, le jeudi 04 et le vendredi 05 ao&ucirc;t 2011 jusqu'&agrave; 19h00.</p>");
						}else if(lang == 'en'){
							$('#nvhz').append("<p style='text-align:right;font-size:14px;color:#838991;margin:20px 0 0 0'>You are already subscribed.</p>");
							$('#nvhz').append("<p style='text-align:right;font-size:14px;color:#838991;margin:20px 0 0 0'>Toegangsbandjes kunnen worden afgehaald bij Marie-Claire Zoute op woensdag 03, donderdag 04 en vrijdag 05 augustus 2011 tot 19.00u. Gelieve uw uitnodiging en bevestiging mee te brengen.</p>");
						}
					}
					
				}

			})
		
		return false;
		
	});
		
})

function loadVideo(id, flv){
		
	var params = {wmode: "transparent"};
	var flashvars = {flvurl: flv, skinurl: "/media/swf/ClearOverPlaySeekMute.swf"};
	swfobject.embedSWF("/media/swf/video.swf", id, "100%", "100%", "9.0.0", "/media/swf/expressInstall.swf", flashvars, params);
}

function validMail(str){
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if(str.indexOf(at)==-1){return false;}
	if(str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){return false;}
	if(str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){return false;}
	if(str.indexOf(at,(lat+1))!=-1){return false;}
	if(str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){return false;}
	if(str.indexOf(dot,(lat+2))==-1){return false;}	
	if(str.indexOf(" ")!=-1){return false;}
	return true;		
}
