/*--------------------------------------------------------------------
Basic Javascript Sheet - Frontoffice

Version: 1.0
Copyright: 2010, dicode® VOF - understanding internet
W: www.dicode.nl
E: info@dicode.nl
T: 0570-750680
--------------------------------------------------------------------*/

/* Global
--------------------------------------------------------------------*/

/* remove url dotted border */
$(document).ready(function() {
	
	$('a').bind('focus', function() {
		this.blur();
	});
	
	$('*').ifixpng();
	
	$('.eo').emptyonclick();
	
});

/* Project
--------------------------------------------------------------------*/
( function($) {
	$.fn.fixPosition = function(px, minheight) {
		var currentTallest = 0;
		$(this).each(function(){
			if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
		});
		
		if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
		
		return $('div.products div.product').each(function() {
			// for ie6, set height since min-height isn't supported
			if ( ($.browser.msie && $.browser.version == 6.0) || !minheight)
				$(this).css({'padding-bottom': currentTallest});
			else
				$(this).css({'padding-bottom': currentTallest}); 
		});
	};
})(jQuery);

var $switch = true;
function switchColor( $colorid ) {
	
	if( typeof $colors != 'undefined' ) {
		$switch = false;
		$('#id_image').fadeOut('fast', function() {
			$('#id_image').attr('src', $.sprintf('%s%s', siteurl, $colors[$colorid]["image"]));
			$('#id_showproductid').html($colors[$colorid]["productid"]);
			$('#id_productid').val($colors[$colorid]["productid"]);
			$('#id_price').html($.sprintf("&euro; %s", $colors[$colorid]["price"]));
			$('#id_imagelink').attr('href', $.sprintf("%s%s", siteurl, $colors[$colorid]["large"] ));

			$('#id_action').html('');
			if( $colors[$colorid]["action"] != "" )
				addAction($colors[$colorid]["action"]);
			if( $colors[$colorid]["delivery"] != "" )
				addDelivery($colors[$colorid]["delivery"]);

			$('#id_image').fadeIn();
			$('#id_colorid').getSetSSValue($colorid);	
			
			if ( $('#id_sizeid') ) {
				$('#id_sizeid').html("");
				
				for( i=0; i < $colors[$colorid]["sizes"].length; i++ ) {
					var obj = $('<option/>');
					obj.attr('value', $colors[$colorid]["sizes"][i].sizeid);
					obj.html($colors[$colorid]["sizes"][i].title);
					$('#id_sizeid').append( obj );
					obj.data("price", $colors[$colorid]["sizes"][i].price);
				}
				if ( $('#id_sizeid').resetSS )
					$('#id_sizeid').resetSS();
				else
					$('#id_sizeid').sSelect({ddMaxHeight: '300px'});
				$('#id_sizeid').trigger('change');
			}
			
		});
	}
	
}

function addAction($action) {
	$('#id_action').html($.sprintf('<div class="labelLeft">Actie prijs:</div><div class="valueRight">&euro; %s</div><div class="clear"></div>', $action));
}
function addDelivery($delivery) {
	$('#id_delivery').html($.sprintf('<div class="labelLeft">LEvertijd:</div><div class="valueRight">%s</div><div class="clear"></div>', $delivery));
}


var $items = null;
var $obj = null;
function checkForm( $frm, $items) {
	var $list = "";
	
	$.each($items, function($index, $value) {
		if( $($.sprintf('#%s', $index)).val() == "" ) {
			$list += $.sprintf("<li>%s</li>", $value);
			if( ! $obj ) $obj = $($.sprintf('#%s', $index));
		}
	});
	
	if( $list != "" ) {
		$.prompt($.sprintf('<h1>Verplichte velden</h1><p>U heeft de volgende verplichte velden niet ingevuld:</p><ul>%s</ul>', $list), {
					callback: function() {
						$obj.focus();
						$obj = null;
					}});
		return false;
	}
	else
		return true;
	
}

