// XXX not sure if the line below should be committted - but i needed it now to
// get js working - kh
$ = jq;

$(function() {
	$("#header ul li:last-child").addClass("last-item");
	$(".sidebar-204 dl:first-child").addClass("first-dl");
	$("#home .slide-list li a").prepend("<img src='images/globals/more-info.gif' class='more-info' alt='' />");
	$("#slide1 ul li:last-child, #slide2 ul li:last-child, #slide3 ul li:last-child").addClass("margin-10-left");
	$("#home .slide-list li.sold-out a").prepend("<img src='images/globals/soldout.gif' class='sold-img' alt='' />");
	$(".get-ticket fieldset p.radio-group:first-child").addClass("first-p-form");
	$(".progress li:first-child").addClass("progess-margin");
	$(".trade-options li:first-child").addClass("trade-margin");
	$(".detail-info li em:last-child").addClass("no-bg-em");
  
	// Clear inputs on blur in search field
	$("#main-search input,#livesearch0 input, #newsletter input#mail-nl").focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});
	
	$('.side-nav li a').hover(function() {  
		$(this).stop().animate({ paddingLeft: '10px' }, 300);  
	}, function() {   
		$(this).stop().animate({ paddingLeft: 0 }, 300);  
	});
	
	// Animate the "meer informatie" button
	$('.slide-list li').hover(function(){
		$(this).find('img.more-info').animate({left:'35px'},{queue:false,duration:300});
	}, function(){
		$(this).find('img.more-info').animate({left:'-160px'},{queue:false,duration:300});
	});
	
	$('.media-right img, .media-left img').each(function(){
		width = this.width + 2;
		$(this.parentNode).css('width', width + 'px');
		
		this.onload = function(){
			width = this.width + 2;
			$(this.parentNode).css('width', width + 'px');
		}
	});
// LAST	
	$(".trade-table tr").hover(function(){
		$(this).addClass('table-hover'); // Place a extra class when hover
	},function(){
		$(this).removeClass('table-hover'); // Remove a class on mouseout
	});
	$(".trade-table td").click(function(){
		window.location=$(this).find("a").attr("href");return false; // href attribute value
	});

	
	// Slideshow home
	var imgWrapper = $('#slideshow > div');
			// only show the first div, hide the rest
			imgWrapper.hide().filter(':first').show();
			imgWrapper.hide().filter(':first').addClass('current');
			
			$('.slide-list li a').click(slidefunc = function () {
				// check if this item doesn't have class "current"
				// if it has class "current" it must not execute the script again
				if (this.className.indexOf('current') == -1){
					imgWrapper.hide();
					imgWrapper.filter(this.hash).fadeIn(500);
					$('.slide-list li a').removeClass('current');
					$(this).addClass('current');
				}
				return false;
			});
			$('.slide-list li a').each(slidefunc);
	
	// Open link in new window
	$(".external").attr("target","_blank");
	
	
	// Show price-table
	$(".show-table").click(function() {
        $("#price-table").animate({ opacity: 'show' }, "slow")
    });
    
    $(".hide-table").click(function() {
        $("#price-table").animate({ opacity: 'hide' }, "slow")
    });
    
    //
    $("#add-review").hide()
	$(".show-hide-form").click(function() {
		$("#add-review").slideToggle("slow");
	});
	
	// Write print link when javascript is enabled
  /* Disabled, client doesn't like it - KH
  	$('.page-options').prepend('<li class="print"><a href="#print">Print pagina</a></li>');
	$('.page-options li.print a').click(function() {
		window.print();
		return false;
	});
  */
	
	// Set the scroll to anchor
	anchor.init()

});

anchor = {
	init : function()  {
		$("a.anchorLink").click(function () {	
			elementClick = $(this).attr("href")
			destination = $(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100 );
		  	return false;
		})
	}
}

