// no conflcit with other library
jQuery.noConflict();


/******************************************************************************* Functions Zone ***/

/* re-organize the menu into 3 columns */
function divideMenuByFourColumns(){
	jQuery('<div />', {
		id:'column-1',
		className:'first column',
		css:{
			width: '33%',
			float:'left'	
		}
	}).appendTo('#mainstore-menu');
	
	jQuery('<div />', {
		id:'column-2',
		className:'column',
		css:{
			width: '33%',
			float:'left'		
		}
	}).appendTo('#mainstore-menu');
	
	jQuery('<div />', {
		id:'column-3',
		className:'column last',
		css:{
			width: '33%',
			float:'left'	
		}
	}).appendTo('#mainstore-menu');
	
	jQuery('<div />', {
		className:'clear'
	}).appendTo('#mainstore-menu');
	

	jQuery(".nav-1, .nav-2, .nav-3").appendTo('#column-1');
	jQuery(".nav-4, .nav-5, .nav-6").appendTo('#column-2');
	jQuery(".nav-7, .nav-8").appendTo('#column-3');
}

/* adjust column height to the longest content */
function adjustColumnHeight(){
	 	var columnheight = new Array();
	 	jQuery('.column').each(function(){
	 		columnheight.push(jQuery(this).height());
	 	})
	 	columnheight.sort().reverse();
		jQuery('.column').each(function(){
	 		jQuery(this).css('height', columnheight[0]+'px');
	 	})
	}

// dom ready
jQuery(document).ready(function(){
	
	/* Call corner plugin */
	if (navigator.appName == 'Microsoft Internet Explorer'){		
		jQuery('.rbox-block, .block-content, .block-compare').each(function(){
			// those have a title
			if (jQuery(this).prev().hasClass('rbox-title') || jQuery(this).prev().hasClass('block-title') || jQuery(this).parent().hasClass('tabs-block') || jQuery(this).parent().hasClass('rbox-tabs')){
				jQuery(this).corner('tr bottom');
			}else{
			// those are independant blocks
				jQuery(this).corner();
			}
		});
	}

	/* Set the menu into 4 columns */
	divideMenuByFourColumns();
	
	
	/******************************************************************************* Binding Zone ***/
	
	/* bind hover event to navigation links */
	jQuery('#rbox-nav > li')
		.hover(
			function(){
			 	jQuery(this).addClass('over');
			 	adjustColumnHeight();
			}, 
			function(){
				jQuery(this).removeClass('over');
			}
		);
		
 	/* hide blue panel when leaving it (inutile)
	jQuery('html').not('#mainstore-menu').click(function(){
 		jQuery('#mainstore-menu').parent().removeClass('over');
 	}); */
	
	/* Principal navigation : over class on 2nd level */
 	jQuery('#rbox-nav li.level0 ul.level0 li.level1').hover(
 		function(){
 			jQuery(this).addClass('over');
 		
 	}, function(){
 			jQuery(this).removeClass('over');
 	});
	
	/* Make default text disappear in newsletter field */
	jQuery('input#newsletter')
		.focus(function(){
			jQuery(this).val('').removeClass('input-text-default');
		})
		.blur(function(){
			if (jQuery(this).val() == ''){
				jQuery(this).val(jQuery(this).attr('defaulttext')).addClass('input-text-default');
			}	
		});
	
 	/* Emule an hover behavior on button element */
	jQuery('.catalog-category-link-cart')
		.hover(
			function(){
			 	jQuery(this).children().children().addClass('hover');
			}, function(){
				jQuery(this).children().children().removeClass('hover');
			}
		);
		
	
	/**************************** Plugin Zone ***/
	/* tabs */
	jQuery("#product-informations").tabs({
		prefixtabs:"tab",
		prefixcontent:"content",
		classcontent:"tabs-content",
		tabinit:"1",
		fadespeed:"fast"
	});
	
    
});
