$(document).ready(function() {
	

	/*
	 * 
	 * GLOBAL SCOPE
	 * 
	 */
	
	/* search init */
	var searchStr = $('#searchbox label:first').text();
	$('#search_query').focus().keydown(function(){
		if ($(this).val()=='Recherche') {
			$(this).attr('value','');
		}
	}).attr('value', searchStr);
	
	
	/* basket hide fix */
	if (!$.browser.msie && $('#cart_block .products').length==0) {
		$('#cart_block').addClass('collapsed').hover(function() {
			$(this).fadeTo('fast', 1);
		},function() {
			$(this).fadeTo('fast', 0.3);
		}).fadeTo('fast', 0.3);
	}
		
	/* menu rollover */
	$('#left_column a:not(.selected)').css({
		'borderTopColor':'#000000', 
		'borderRightColor':'#000000', 
		'borderBottomColor':'#000000', 
		'borderLeftColor':'#000000' 
	}).hover(function(){
		$(this).animate({
			backgroundColor:'#2aabe4',
			'borderTopColor':'#2aabe4', 
			'borderRightColor':'#2aabe4', 
			'borderBottomColor':'#2aabe4', 
			'borderLeftColor':'#2aabe4' 
			}, 600);		
	}, function(){
		$(this).animate({
			backgroundColor:'#ffffff', 
			'borderTopColor':'#000000', 
			'borderRightColor':'#000000', 
			'borderBottomColor':'#000000', 
			'borderLeftColor':'#000000' 
		},400);		
	});
	
	
	/* quick order */
	$('#block_order').css('cursor', 'pointer').click(function(){
		window.location = $('#block_order a:first').attr('href');
		return false;
	});
	
	
	
	
	
	/*
	 * 
	 * SPECIAL PAGES
	 * 
	 */

	/* rollover products list */
	$('ul#product_list li .desc').hide();	
	$('ul#product_list li').hover(function(){
		$(this).find('.desc').slideDown();
	},function(){
		$(this).find('.desc').slideUp();
	});
	
	/* button global click */
	$('#buy_block.not(.oss)').css('cursor', 'pointer').click(function(){
		$('#buy_block').submit();
//		return false;
	});
	

	/*.css('cursor', 'pointer').click(function(){
		window.location = $('ul#product_list li a:first').attr('href');
		return false;
	})*/
	
	
	/* home page */
	$('#product_list div.item .desc p').css('cursor', 'pointer').click(function(){
		window.location = $('#product_list div.item a:first').attr('href');
		return false;
	});
	
	/*
	 * 
	 * EVERY PAGE DISPLAY SEQUENCING
	 * 
	 */
	
	
	/* main body fade */
	$('#logo, #header, #center_column, #right_column').hide();
	$('#footer').css({'opacity' : '0'});
	if (!$.browser.msie) {
		$('#left_column').hide();
	}		
	//	$('#left_column').css('opacity','0');

	
	$('#logo').fadeIn(function() {
		if ($.browser.msie) this.style.removeAttribute("filter",false);
		if($('#product').length>0) {
			if (!$.browser.msie) {
				$('#left_column').show().css({'opacity' : '0.3'}).hover(function(){
					$(this).fadeTo('slow',1);
				},function(){
					$(this).fadeTo('fast',0.2);
				});
				$('#search_block_left').show().css({'opacity' : '0.3'}).hover(function(){
					$(this).fadeTo('slow',1);
				},function(){
					$(this).fadeTo('fast',0.2);
				});
			}
			endDisplay();
		}
		else if($('#order').length>0 || $('#authentication').length>0 || $('#payment').length>0) {
			endDisplay();
		}
		else {
			$('#left_column').fadeIn(500, function() {
				if ($.browser.msie) this.style.removeAttribute("filter",false);
				endDisplay();
			});						
		}
	});	
});

function endDisplay() {
	$('#center_column').fadeIn(function() {
		if ($.browser.msie) this.style.removeAttribute("filter",false);
		$('#footer').hide().css({'opacity' : '1'}).fadeIn(function() {
			if ($.browser.msie) this.style.removeAttribute("filter",false);
			$('#header').fadeIn(function() {
				if ($.browser.msie) this.style.removeAttribute("filter",false);
				$('#right_column').fadeIn('slow', function() {
					if ($.browser.msie) this.style.removeAttribute("filter",false);					
				});
			});						
		});						
	});	
}
