$(document).ready(function(){
	$("#header_menu li:last-child").addClass("last");
	
	//docs: http://www.professorcloud.com/mainsite/carousel-integration.htm					   
	//This initialises carousels on the container elements specified, in this case, carousel1.
	$("#carousel1").CloudCarousel(		
		{			
			reflHeight: 70,
			reflGap:0,
			reflOpacity:0.1,
			altBox: $('#alt-text'), 
			buttonLeft: $('#right-but'),
			buttonRight: $('#left-but'),
			yRadius:-0.1,
			xRadius:115,
			xPos: 255,
			yPos: 20,
			speed:0.15,
			minScale: 0.7,
			mouseWheel:true 
		}
	);
	
	
	//classe les options dans le cart à l'affichage
	if($(".checkout_cart_optionszone").length>0)
	{
		
		
		$(".checkout_cart_optionszone").each(function() 
		{
			new_data = new Array();
		
			if($("table.opt_1",this).length>0) { new_data.push($("table.opt_1",this)); } //Type of power
			if($("table.opt_2",this).length>0) { new_data.push($("table.opt_2",this)); } //Power cord
			if($("table.opt_3",this).length>0) { new_data.push($("table.opt_3",this)); } //SS7
			if($("table.opt_4",this).length>0) { new_data.push($("table.opt_4",this)); } //Sigtran
			if($("table.opt_10",this).length>0) { new_data.push($("table.opt_10",this)); } //TMG - TMS
			if($("table.opt_9",this).length>0) { new_data.push($("table.opt_9",this)); } //TMG - CTRL
			if($("table.opt_5",this).length>0) { new_data.push($("table.opt_5",this)); } //Support bank
			if($("table.opt_6",this).length>0) { new_data.push($("table.opt_6",this)); } //Remote installation
			if($("table.opt_7",this).length>0) { new_data.push($("table.opt_7",this)); } //Extended warranty
			if($("table.opt_8",this).length>0) { new_data.push($("table.opt_8",this)); } //Onsite packages
			
			for(var i=0;i<new_data.length+1;i++)
			{
				$(this).append(new_data[i]);
			}	
		});
	}
	
	//ajuste la hauteur du contenu quand la page est trop courte
	if($("#main_container").length>0 && $(".wrapper").length>0)
	{
	   $("#main_container").height($(window).height());
	   $(".wrapper").height($(window).height() - 150); //150 = la hauteur du #header
	}
	
	//sert à ajuster la position des Qty Selector vs le label dans le cart 
	//nécéssaire car le design ne permettait pas de le faire seulement en HTML
	if($('.lbQuantite').length>0)
	{
	    var p = $('.lbQuantite').position();
	    new_left = p.left - 35;
    	
	    $('.cartQty').each(function() {
    	    
	        var p = $(this).parent();
	        p = p.position();
	        new_top = p.top;
    	    
	        $(this).css({ 
	            'position' : 'absolute', 
	            'left' : new_left, 
	            'top' :  new_top
	        });   
	    })
	}
	
	
	$('.row select').change(function() 
	{ 
	    $('option:selected', this).attr('value');
	    var selector = $(this).parent();
	    selector = '.'+selector.attr('class').replace(' ','.');
	    $(selector+' select').val($(this).val());
	});
	
	
	$(".more_images a").click(function(){
	    $(".main_img a").click();
	}).css('cursor', 'pointer');
	
    $(".opt .opt_body .row_3 .carac_label:contains('SS7')").each(
	    function () {
	        $(this).append('<div style="position:absolute; display:none;" class="opt_tooltip">SS7: MTP2, MTP3, ISUP</div>');	        
    	    $(this).append('<span class="opt_help"></span>')
    	    
    	    $('.opt_help',this).hover( 
                function() { $('.opt_tooltip',$(this).parent()).fadeIn(300); }, 
                function() { $('.opt_tooltip',$(this).parent()).fadeOut(200); }
            );
	    }
	);
	   
	$(".opt .opt_body .row_4 .carac_label:contains('SIGTRAN')").each(
	    function () {
	        $(this).append('<div style="position:absolute; display:none;" class="opt_tooltip">SIGTRAN Relay: M2UA, M3UA<br />SIGTRAN Termination: M2PA, M2UA, M3UA, ISUP</div>');	        
    	    $(this).append('<span class="opt_help"></span>')
    	    
    	    $('.opt_help',this).hover( 
                function() { $('.opt_tooltip',$(this).parent()).fadeIn(300); }, 
                function() { $('.opt_tooltip',$(this).parent()).fadeOut(200); }
            );
	    }
	);
	
	$('.checkout_btnzone .validation_ctrl').prepend($('.step_validation .envoiCart'));
	
});

