var submit_button;
var allreadydone = false;
var submit_shown = false;
var allreadydone = false;
var allow_switch=true;
var base_our_price = 109;
var base_sale_price = 79;
var base_comp_price= 99;
window.addEvent('domready', function() {
	
	settips('.Tips_Colors');
	submit_button = new Fx.Style('donebutton', 'opacity', {duration:1000,wait: true});	
	hide_submit();
	//get the tool tip	
	var fb_mooTip = new mooTips($$('.toolTipImgDOM'));		

});	

function settips(where){
var Tips2 = new Tips($$(where), {
	initialize:function(){
		this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
	},
	onShow: function(toolTip) {
		this.fx.start(1);
	},
	onHide: function(toolTip) {
		this.fx.start(0);
	}
});
}


function switch_image(img,id){
	if (!allow_switch){
			return;
	};
	
	if (img != ''){
		$(id).setHTML('<img src="/prodimages/' + img + '" alt="" \/>');
	}else if(id != 'img1'){
			$(id).setHTML('');
	}
}

//show the button
function show_submit(){
	if (!allreadydone){
		$('donebutton').setStyles({
			display: 'block'
		});
	}

	if (!submit_shown){
		submit_button.start(0,1);
		submit_shown = true;
	}
	
	allreadydone = true;
}

function updateprice(priceToAdd){
	$('our_price').setHTML('<s>Our Price: $' + eval(base_our_price + priceToAdd).numberFormat()  + '<\/s>');
	$('sale_price').setHTML('Your Sale Price: $' + (eval(base_sale_price + priceToAdd)).numberFormat());
	$('comp_price').setHTML('Competitors Price: $'+ (eval(base_comp_price + priceToAdd)).numberFormat());
	$('our_price2').setHTML('<s>Our Price: $' + eval(base_our_price + priceToAdd).numberFormat()  + '<\/s>');
	$('sale_price2').setHTML('Your Sale Price: $' + (eval(base_sale_price + priceToAdd)).numberFormat());
	$('comp_price2').setHTML('Competitors Price: $'+ (eval(base_comp_price + priceToAdd)).numberFormat());

}

//fade out the submit button
function hide_submit(){
if (submit_shown){
 submit_button.start(1,0);
}
 submit_shown = false;
}

Number.extend({

	/*
	Property: numberFormat
		Format a number with grouped thousands.

	Arguments:
		decimals, optional - integer, number of decimal percision; default, 2
		dec_point, optional - string, decimal point notation; default, '.'
		thousands_sep, optional - string, grouped thousands notation; default, ','

	Returns:
		a formatted version of number.

	Example:
		>(36432.556).numberFormat()  // returns 36,432.56
		>(36432.556).numberFormat(2, '.', ',')  // returns 36,432.56
	*/

	numberFormat : function(decimals, dec_point, thousands_sep) {
		decimals = Math.abs(decimals) + 1 ? decimals : 2;
		dec_point = dec_point || '.';
		thousands_sep = thousands_sep || ',';

		var matches = /(-)?(\d+)(\.\d+)?/.exec((isNaN(this) ? 0 : this) + ''); // returns matches[1] as sign, matches[2] as numbers and matches[2] as decimals
		var remainder = matches[2].length > 3 ? matches[2].length % 3 : 0;
		return (matches[1] ? matches[1] : '') + (remainder ? matches[2].substr(0, remainder) + thousands_sep : '') + matches[2].substr(remainder).replace(/(\d{3})(?=\d)/g, "$1" + thousands_sep) + 
				(decimals ? dec_point + (+matches[3] || 0).toFixed(decimals).substr(2) : '');
	}


});