jQuery(function($) {
	
	//List
	$itemList = $('#product-list .item');
	for (var i=0;i<=$itemList.length;i+=4) {
		$itemList.slice(i,i+2).addClass('odd');
	}
	
	//Single
	$single = $('#single');
	
	//Single-images
	$images = $('.image', $single);
	$images.prepend('<div id="big"></div>');
	$big = $('#big');
	
	$images.bind('click', function(event){
		var $link = $(event.target).closest('a');
		
		if (!$link.parent().is('#big')){ //prevent this when clicking the big image
			_oldHeight = $big.height();
			$big.height(_oldHeight).html($link.clone(true));
			$bigImage = $big.find('img');
			$bigImage.fadeTo(1,.01).load(function(){ 
				_newHeight = $bigImage.height();
				$big.animate({ height: _newHeight }, 300);
				$bigImage.fadeTo(300,1);
			});
			$big.find('a')[0].onclick = '';
		} else {
			$.facebox(function() {
				$.get($link[0].href, function(data) {
				    data = data.substring(data.indexOf('<img'));
				    data = data.substring(0,data.indexOf('/>')+2);
				    $.facebox(data);
				});
			}); 
		}
		
		//Do not follow the link
		event.preventDefault();
		return false;
		
	}); 
	
	$('#singleForm').find('.img a').each(function(){
		this.onclick = '';
		var $link = $(this);
		$link.click(function(){
			$.facebox(function() {
				$.get($link[0].href, function(data) {
				    data = data.substring(data.indexOf('<img'));
				    data = data.substring(0,data.indexOf('/>')+2);
				    $.facebox(data);
				});
			});
			return false;
		});
	});
	
	$link = $('a', $images);
	$link.each(function(){
		$(this)[0].onclick = '';
	}).eq(0).click(); //opening the first image by default
	
	
	//Datepicker
	$('#deliverydate').datepicker({
		dateFormat: 'dd-mm-yy',
		minDate: '1'
	});
	
	//Disable submit button
 	//Until the user agreed to the terms
 	var $singleForm = $('#singleForm');
 	var $basketSubmit = $('.submitBtn-check', $singleForm);
 	var $checkbox = $('.check', $singleForm);
 	
 	$singleForm.submit(function(el){
          if (el.originalEvent.explicitOriginalTarget.value != 'update') {
            if (!$checkbox.is(':checked')) {
              switch (document.getElementById('langbox').value) {
              	case '1':
              		alert('U dient akkoord te gaan met de algemene voorwaarden');
              		break
              	case '2':
              		alert('Sie m\u00FCssen sich mit den Gesch\u00E4ftsbedingungen einverstanden erkl\u00E4ren');
              		break;
              	case '3':
              		alert('You are kindly requested to agree to the conditions');
              		break;
              	default:
              		alert('U dient akkoord te gaan met de algemene voorwaarden');
              		break;
              }
              return false;
            }
          }
        });
	
	//Tooltip
	$('.info').qtip({
		show: 'click',
		position: {
	      corner: {
	         target: 'topRight',
	         tooltip: 'bottomLeft'
	      }
	    },
		style: {
	    	width: 200,
	        padding: 10,
	        color: 'white',
	        border: {
	           width: 7,
	           radius: 5,
	           color: '#000'
	        },
	        tip: { // Now an object instead of a string
	            corner: 'bottomLeft', // We declare our corner within the object using the corner sub-option
	            color: '#000',
	            size: {
	               x: 20, // Be careful that the x and y values refer to coordinates on screen, not height or width.
	               y : 8 // Depending on which corner your tooltip is at, x and y could mean either height or width!
	        	}
	        },
	        name: 'dark' // Inherit from preset style
	     }
	});
	
	
});
