$(function() {
	/** Allow no js style */
	$('body').addClass('js');
	/** Slideshow */
    var slideshow	= $('#slideshow'), 
		speed		= 5000, //rotation speed and timer
		run			= setInterval('rotate()', speed), 
		list		= $('ul', slideshow), 
		items		= $('li', slideshow),
		item_width	= items.outerWidth(), //grab the width and calculate left value
		left_value	= item_width * (-1); 
    //move the last item before first item, just in case user click prev button
    $('li:first', list).before($('li:last', list));
    //set the default item to the correct position 
    list.css({width: items.length*item_width, 'left': left_value})
    .after('<a href="#previous" class="previous"></a><a href="#next" class="next"></a>');
    //prev button
    $('a.previous', slideshow).click(function() {
        //get the right position            
        var left_indent = parseInt(list.css('left')) + item_width;
        //slide the item            
        list.animate({'left': left_indent}, 800, 'swing', function(){    
            //move the last item and put it as first item               
            $('li:first', list).before($('li:last', list));           
            //set the default item to correct position
            list.css({'left': left_value});
        });
        //cancel the link behavior            
        return false;
    });
    //next button
    var next = $('a.next', slideshow).click(function() {
        //get the right position
        var left_indent = parseInt(list.css('left')) - item_width;
        //slide the item
        list.animate({'left': left_indent}, 800, 'swing', function () {
            //move the first item and put it as last item
            $('li:last', list).after($('li:first', list));                  
            //set the default item to correct position
            list.css({'left': left_value});
        });
        //cancel the link behavior
        return false;
    });

	//a timer will call this function, and the rotation will begin :)  
	window.rotate = function () {
		next.click();
	}
    //if mouse hover, pause the auto rotation, otherwise rotate it
    slideshow.hover (
        function() {
            clearInterval(run);
        }, 
        function() {
            run = setInterval('rotate()', speed);   
        }
    );

	/** Forms styling */
	$('span.checkbox :input').change(function(){
		var self= $(this);
		self.parents('span.checkbox')[(self.is(':checked') ? 'add' : 'remove') + 'Class']('checked');
		if (self.is(':radio:checked'))
			$(':input[name='+this.name+']').not(this).parents('span.checkbox').removeClass('checked');
	}).change();
	$('span.checkbox').click(function(){
		$(':input',this).change();
	});
	
	$('span.select').each(function(){
		var self		= $(this)
			selected	= $('<span class="selected"></span>').prependTo(self),
			select		= $('select', this).css({
				opacity: 0,
				width: self.width(),
				height: self.height()
			});
		select.change(function(){
			$(this).prev('.selected').text($(':selected',this).text());
		}).change();
	});

	/** Colorbox */
	$('a[href=#login]').colorbox({width: '400px', inline: true, href: '#login', opacity: .5});
	$('a[href=#lost]').colorbox({width: '400px', inline: true, href: '#lost', opacity: .5});
	$('a[href=#popup]').colorbox({width: '400px', inline: true, href: '#popup', opacity: .5});
	$('#cboxOverlay,#colorbox').prependTo('#page'); // move colorbox in DOM

	/** Corners for IE */
	$('#logo').corner('top 5px');
	$('#navigation .box.last').corner('bottom 5px');
	$('#content .box, #cboxContent, #content.default_index .block').corner('5px');

	$('#content.boutique .product').hover(
		function(){$(this).css('z-index',1).find('.details').addClass('hover').animate({height:326});},
		function(){$(this).css('z-index',0).find('.details').animate({height:133},function(){$(this).removeClass('hover')});}
	);

	$('#content.boutique_panier select[name=qt]').change(function(){
		this.form.submit();
	});
	
});
//*
$.tk.notifybox.defaults.hPos = 'center';
$.tk.notifybox.defaults.vPos = 48;
$.tk.notify.defaults.effectShow = 'myshow';
$.fn.myshow = function(){
	$(window).scrollTop(0);
	$(this).show();
}
//*/
