// JavaScript Document

$(document).ready(function(){	
		
	Cufon.replace('h1', { fontFamily: 'Gravur-Condensed' });
	Cufon.replace('h2',  { fontFamily: 'Gravur-Condensed'});
	Cufon.replace('h3', { fontFamily: 'Gravur-Condensed' });		
	Cufon.replace('div#blocks p', { fontFamily: 'Gravur-Condensed' });
	Cufon.replace('ul.mainNav li a', { fontFamily: 'Gravur-Condensed' });			

	// alleen uitvoren bij kerst	

	if ( $('body.kerst').length ) {
		$kerstAnimate = 'off';
		
		$(window).scrollTop(0);	
		var p = $("div#boom");
		var position = p.position();
		$top = position.top;
		$left = position.left;
		
		$(window).scroll(function () {
			$scroll = ($(window).scrollTop());		
			$('body.kerst div#boom').css('top',($top - $scroll)+'px');
		});
			
		$(window).resize(function () {
			if ($kerstAnimate == true) {		
				$left = ($(window).width()/2)+50;
				$('body.kerst div#boom').css('left',$left+'px');
			}
		});
		
		$('div#actieTweets').cycle({timeout: '8000'});
		
		$('div.link, div#boom div').click(function () {
			$active = $(this).attr('tabindex');
			kerstSelect($active);
		});
		function kerstSelect($_active){				
			$kerstAnimate = true;
			
			$active = $_active;
			$('div.group').hide();
			$('input#groupID').val($active);
			$('div#group'+$active).show();
			
			$('body.kerst div#boom').css('left',$left);
			
			$left = ($(window).width()/2)+50;
			$('body.kerst div#boom').animate({	    
				left:$left+'px'
			  },2000, function() {
			    // Animation complete.
					$('div#actieInfo div.wrapActie1').hide();
					$('div#actieInfo div.wrapActie2').show();
					$('div#actieInfo div.wrapActie3').hide();
			});			
			$('div#alpha').hide();		
		}	
	}
	// alleen uitvoren bij kerst	

	
	$('.accordion h5').click(function() {
		$(this).next().toggle('slow');
		return false;
	}).next().hide();
    
	$('#nr1, #nr2, #nr3, #nr4, #nr5, #code, .code').autotab_filter('numeric');
	$('#nr1, #nr2, #nr3, #nr4, #nr5, #code').autotab_magic();
	
	if ( $('div.photo').length ) {
		var $container = $('div.photo').cycle({
			timeout: 5000,
		    before: function(){	    	
		    	active = $(this).index();	    	
		    	$('div.text div').removeClass("active");
		    	$('div.text div:eq('+active+')').addClass("active");
		    	Cufon.refresh();
		    }
		});
	}
	
	$('div.text a').hover(
			function(){
				setActive = $(this).index();
				$container.cycle(setActive);
				$container.cycle('pause');
			},
			function(){
				$container.cycle('resume');
			}
		);
	
	$("textarea#invitationText").hide();
	
	$("form.message3 input[name='radioText']").click(function(){
		if ($(this).val() == "other") {			
			$("textarea#invitationText").show();
			$("div#charlimitinfo").show();			 
		} else {
			$("textarea#invitationText").hide();
			$("div#charlimitinfo").hide();
		}
	});
	
	if ( $('form#order').length ) {
		// check if form is on page
		
	    // bind form using ajaxForm 
	    $('form#order').ajaxForm({ 
	        // target identifies the element(s) to update with the server response 
	        target: '#output', 
	 
	        // success identifies the function to invoke when the server response 
	        // has been received; here we apply a fade-in effect to the new content 
	        success: function() {
	    		$response = $('div#output').html();
	    		if (($('div#output').html() != "fout")|($('div#output').html() != "false")) {
	    			$('div#output').html($response+' > Bestelling is verzonden.');
	    			$('div.form, input.button').hide();
	    		} else {
	    			$('div#output').html($response+' > Bestelling is mislukt, probeer het opnieuw.');
	    		}
	    		 
	            $('div.output').show(); 
	        } 
	    });
    
	}
        
    $('div.output a').click(function(){
    	$('div.output').hide(); 
    	$('div.form, input.button').show();
    	return false;
	});
    
	$('input.waardeToggle').change(function(){
		$('dl.vaste').toggle();
		$('dl.vrije').toggle();		
	});
	
	$('input#aflever_adres_anders').change(function(){
		$('div#aflever_adres').toggle();
	});
	
	$('select#bedrijfToggle').change(function() {		
		if ($('select#bedrijfToggle').val() == 1) {
			$('dl.bedrijfsnaam').show();
		} else {			
			$('dl.bedrijfsnaam').hide();
			$('input#bedrijfsnaam').val('');
		}
	});
	
	if ($('select#bedrijfToggle').val() == 0) {
		$('dl.bedrijfsnaam').hide();
	}
	
	$('select.waardeSelect').change(function(){
		$('input.waarde').val($('select.waardeSelect').val());
	});
	
	$waardeToggle = $('input#waardeToggle-Vrijewaarde').attr('checked');
	if ($waardeToggle == 1) {
		$('dl.vaste').toggle();
		$('dl.vrije').toggle();		
	} else {
		$('input.waarde').val('10,00');
	}
	
	$("map area").mouseover(function (){
		$rel = $(this).attr('rel');
		$("img#mapImage").attr('src', baseUrl+'/default/img/map_'+$rel+'.gif');
	});
	
	$anderAfleverChecked = $("input#aflevernrstatus").attr('checked');	
	if ($anderAfleverChecked == 'checked') {
		$("div#ander_afleveradres").show();
	}
	
	$("input#aflevernrstatus").click(function (){
		
		$checked = $("input#aflevernrstatus").attr('checked');
		
		if ($checked == 'checked') {
			$("div#ander_afleveradres").show();
		} else {
			$("div#ander_afleveradres").hide();
		}
	});	
	
	$("td.qty select, tr.package input").change(function () {
		//alert("ja");
		$("input#send").attr('name', 'update');
		$('#order2').submit();
	});
	$("div#overzichtUpdate a").click(function(){
		$("input#send").attr('name', 'update');
		$('#order2').submit();		
	});
	$('form#order2 input.aantal').focusout(function(){
		$("input#send").attr('name', 'update');
		$('#order2').submit();		
	});
	
	$("input#send").click(function () {
		//alert("ja");
		$("input#send").attr('name', 'submit');
		$('#order2').submit();
	}); 		
	
	
	$("ul.faq li").click(function () {
		   $(this).toggleClass("open");
	}); 	
 
	$("a.popup").click(function () { 	
		$("input#show").attr('value', $(this).attr('rel')); 
		$("a.popup").colorbox({width:"512px", inline:true, href:".inlineInvite", maxHeight:"600px", scrolling:false });
	});
	
	$("a.winkelmandjepopup").click(function () { 	
		$("input#regelnr").attr('value', $(this).attr('rel'));	
		$(".winkelmandjepopup").colorbox({width:"512px", inline:true, href:".inline", maxHeight:"600px", scrolling:false, current:"" });
	});

	$("_input.warning").click(function () { 	

		$("input.warning").colorbox({width:"512px", inline:true, href:".inlineWarning", maxHeight:"600px", scrolling:false, current:"" });

	});
	
	if ( $('a.winkelmandjeClear').length ) {
		$("a.winkelmandjeClear").colorbox({width:"512px", inline:true, href:".inlineClear", maxHeight:"600px", scrolling:false });
	}
	
	//	Example of preserving a JavaScript event for inline calls.
 	$("#click").click(function(){ 
	$('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");return false;					
		});

	//$("body").css({"background-image": "url("+baseUrl+"/default/img/Stage_0"+randomBck+".jpg)"})		
	
});
