window.addEvent('domready', function() {
	
	// rollOvers pour les images
	// Application : class="roll"

	//preload images
	var aPreLoad = new Array();
	var aPreLoadi = 0;
	
	//do rollover
	$$('img.roll', 'input.roll').each(function(el){
		//let's preload
		aPreLoad[aPreLoadi] = new Image();
		aPreLoad[aPreLoadi].src = el.src.replace(el.src.replace(/_off([._])/, '_on$1'));
		aPreLoadi++;
	
		el.addEvent('mouseover',function(){
			this.setAttribute('src',this.src.replace(/_off([._])/, '_on$1'));
		});
	
		el.addEvent('mouseout',function(){
			this.setAttribute('src',this.src.replace(/_on([._])/, '_off$1'));
		});
	});


	// tooltip on apple
	var appleHelpTips = new RedTips('.help', {offsets: {x: -100, y: 0}, fixed: true });
	
	// tooltip on apple
	var bigAppleHelpTips = new RedTips('.helpbig', {offsets: {x: -80, y: 17}, fixed: true });

});

// rollOvers for Text
// Application : class="rollText"
window.addEvent('domready',function() {
	$$('.rollText').each(function(el){
		var original = el.getStyle('color');
		var morph = new Fx.Morph(el,{ 'duration':'300' });
		el.addEvents({
			'mouseenter' : function() { morph.start({ 'color':'#ff8c00' }) },
			'mouseleave' : function() { morph.start({ 'color': original }) }
		});
	});
});


// Shadowbox
Shadowbox.loadSkin('btfs', '../_java/shadowbox/skin'); // use the "classic" skin
Shadowbox.loadLanguage('en', '../_java/shadowbox/lang'); // use the English language
Shadowbox.loadPlayer(['iframe', 'html', 'img', 'swf'], '../_java/shadowbox/player'); // use img and qt players

window.addEvent('domready', function() {
	var options = {
		animate: false,
		modal: true,
        handleOversize:     'none',
        handleUnsupported:  'remove',
        autoplayMovies:     false
    };

	Shadowbox.init(options);
});

var current_popup = false;
var isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
function show_popup(id) {
	document.getElementById('overlay').style.display = 'block';
	document.getElementById('popups').style.display = 'block';
	document.getElementById(id).style.display = 'block';
	document.getElementById(id).style.visibility = 'visible';
	current_popup = id;
	if (isIE6) toggleSelects('none');
	
}
function hide_popup() {
	document.getElementById('overlay').style.display = 'none';
	document.getElementById('popups').style.display = 'none';
	if (current_popup != false) {
		document.getElementById(current_popup).style.display = 'none';
		document.getElementById(current_popup).style.visibility = 'hidden';
	}
	if (isIE6) toggleSelects('');
}

function toggleSelects(action) {
	var selects = document.getElementsByTagName('select');

	for(var i=0; i < selects.length; i++) {
		selects[i].style.display=action;
	}
}


function to2DecWithComma(num) {
	num="" + Math.floor(num*100.0 + 0.5)/100.0;

	var i=num.indexOf(".");

	if ( i<0 ) {
		num+=",00";
	} else {
		num=num.substring(0,i) + "," + num.substring(i + 1);
		var nDec=(num.length - i) - 1;
		if ( nDec==0 ) {
			num+="00";
		} else if ( nDec==1 ) {
			num+="0";
		} else if ( nDec>2 ) {
			num=num.substring(0,i + 3);
		}
	}
	return num;
}

function to2DecWithDot(num) {
	num="" + Math.floor(num*100.0 + 0.5)/100.0;

	var i=num.indexOf(".");

	if ( i<0 ) {
		num+=".00";
	} else {
		num=num.substring(0,i) + "." + num.substring(i + 1);
		var nDec=(num.length - i) - 1;
		if ( nDec==0 ) {
			num+="00";
		} else if ( nDec==1 ) {
			num+="0";
		} else if ( nDec>2 ) {
			num=num.substring(0,i + 3);
		}
	}
	return num;
}


function adjustQuote(c, v) {
	if (c == false) {
		$('item_qty_'+v).set('text', 0);
		$('quote_top').set('text', to2DecWithDot(parseFloat($('quote_top').get('text')) - parseFloat($('removable_item_total_'+v).value)));
		$('quote_bottom').set('text', to2DecWithDot(parseFloat($('quote_bottom').get('text')) - parseFloat($('removable_item_total_'+v).value)));
		//alert('REMOVE ' + $('removable_item_total_'+v).value);
	} else {
		$('item_qty_'+v).set('text', $('removable_item_qty_'+v).value);
		$('quote_top').set('text', to2DecWithDot(parseFloat($('quote_top').get('text')) + parseFloat($('removable_item_total_'+v).value)));
		$('quote_bottom').set('text', to2DecWithDot(parseFloat($('quote_bottom').get('text')) + parseFloat($('removable_item_total_'+v).value)));
	}
}
