$(function() {
		
	var $defaultValue = $('span#default-value');
	var $searchInput = $('input#join');
	
	$searchInput.focus(function() {$defaultValue.hide();});
	$defaultValue.click(function() {$(this).hide();$searchInput.focus();});
	$searchInput.blur(function() {if($(this).val().length === 0) {$defaultValue.fadeIn(250);}});
	
	if($searchInput.val().length > 0 ) {$defaultValue.hide();}
	
	$('.selector').click(function() {
		$currentDropbox = $(this).children('.dropbox');
		$currentDropbox.prev().toggleClass('arrow-up');
		$('.selector').css('zIndex', '1');
		$('.dropbox').not($currentDropbox).fadeOut(250);
		$(this).css('zIndex', '10');
		$currentDropbox.toggle();
	});
        
        var total_price = parseFloat($('#total-price').text().replace(',', '.'));
        var payment_type = 0;
        var delivery_method = 0;
	$('#cart3_payment_type a').click(function() {
            payment_type = parseFloat($(this).closest('li').attr('price').replace(',', '.'));
            updateOrderPrice();
        });
 
        $('#cart3_delivery_method a').click(function() {
            delivery_method = parseFloat($(this).closest('li').attr('price').replace(',', '.'));
            updateOrderPrice();
        });
        
        function updateOrderPrice()
        {
            var total = total_price + payment_type + delivery_method;
            $('#total-price').text(total.toFixed(2).replace('.', ',') + '€');
        }
        
	$('ul.select-list a').click(function() {
		var $this = $(this);
                var text = $this.text();
		var value = $this.closest('li').attr('class');
		var $target = $this.closest('.dropbox').parent().children().eq(0);
		$target.text(text);
		$('input[name="' + $target.attr('id') +'"]', $this.closest('form')).val(value);
		$('input[name="' + $target.attr('id') +'"]', $this.closest('form')).change();
		$('.dropbox').fadeOut(250);
                $(this).closest('.dropbox').prev().removeClass('arrow-up').addClass('arrow-down');
		return false;
	}); 

	$('.klarna-payment input.klarna-payment-type').change(function () {
			updateOrderPrice();
		});

        function isPartPayment() {
			var id = $('#paymentType').val();
			var $klarna = $('input.klarna-payment-type:checked');
	
			switch (parseInt(id)) {
				case 27: // Klarna
					return true;
			}
	
			return false;
		}
        
        function updateOrderPrice()
        {
        	if (isPartPayment()) {
				$('.cart-table .klarna').show();
				
				var $klarna = $('input.klarna-payment-type:checked');

				if ($klarna.length <= 0) {
					$('#klarna-payment-sub-type').attr('disabled', 'disabled');
				}
				else if ($klarna.val() == '-1') {
					$('#klarna-payment-sub-type').attr('disabled', 'disabled');
				}
				else {
					$('#klarna-payment-sub-type').removeAttr('disabled');
				}
			}
			else {
				$('.cart-table .klarna').hide();
			}
        	
            var total = total_price + payment_type + delivery_method;
            $('#total-price').text(total.toFixed(2).replace('.', ',') + '€');
        } 

	$('#carousel').cycle({timeout: 10000, speed: 3000});
	
	$('#slideshow').cycle({
    		speed:  'fast',
    		prev:    '#prev',
        	next:    '#next',
    		timeout: 0,
                after: function() { $('.cloud-zoom').CloudZoom(); },
    		pager:  '#slideshow-thumbs', 
    		pagerAnchorBuilder: function(idx, slide) {
                  var image = $(slide).attr('data-image-url');
                  return '<a href="#" class="link'+ idx +'"><span class="image-border" style="background: url('+ image +') no-repeat scroll center center white;">&nbsp;</span></a>';
    		}
	});

        $('#magnifier').click(function() {
           $('#slideshow').find('a:visible').click();
           return false;
        });

	$('a.fancybox').fancybox();

         $('a.fancytextbox').fancybox({
                'frameWidth':	600, 
		'frameHeight':	300,
'overlayShow': true
});   

        $('#menu-top li').each( function () {
            var here = document.location + "";
            var link = $(this).find('a').attr('href');
            
           
                 if (here == SERVER && link == '/') {
                   $(this).addClass('current');
                 } else {
                    if (link.length > 2 && here.indexOf(link) > 0) {
                       $(this).addClass('current');
                    }
                 }
                  
            
        });

/*$('#menu-top li').each( function () {
            var currentLocation = document.location.toString();
var currentLiUrl = $("a:first-child", this).attr('href');
if(currentLocation == currentLiUrl ) {
$(this).addClass('current');
}            
        });*/

	$('.product-list').each(function() {
		$(this).find('tr:first').addClass('first');
		$(this).find('tr:last').addClass('last');
	});

	$('.product-list tr').each(function() {
		$(this).find('td:first').addClass('first');
		$(this).find('td:last').addClass('last');
	});

});

