// function to find style values by selectors
function $css2obj(selector, empty){
	if(!empty) empty = 0;
	var to = {};
	Array.each(document.styleSheets, function(sheet, j){
		var rules = sheet.rules || sheet.cssRules;
		Array.each(rules, function(rule, i){
			if (!rule.style || !rule.selectorText || !rule.selectorText.test('^' + selector + '$')) 
				return;
			Element.Styles.each(function(value, style){
				if (!rule.style[style] || Element.ShortStyles[style]) 
					return;
				if(!empty)
					value = rule.style[style];
				to[style] = (empty) ? '' : (value.test(/^rgb/)) ? value.rgbToHex() : value;
			});
		});
	});
	return to;
}
// extend Element.setStyles to accept CSS selectors
Element.implement({	
	setStyles: function(styles) {
		if(typeof styles == 'string')
			styles = $css2obj(styles);
		for (var style in styles) 
			this.setStyle(style, styles[style]);
		return this;
	}
});


window.addEvent('domready', function() {

	// main menu image preloader routine
	var menu_images = new Array(6);
	menu_images[0] = "/img/menu-about-on.gif";
	menu_images[1] = "/img/menu-access-on.gif";
	menu_images[2] = "/img/menu-demos-on.gif";
	menu_images[3] = "/img/menu-prices-on.gif";
	menu_images[4] = "/img/menu-security-on.gif";
	menu_images[5] = "/img/menu-support-on.gif";	
	
	for (i=0; i < menu_images.length; i++) {		
		var preload = new Image();
		preload.src = menu_images[i];	    
	}

	
	// Print action
	if($('print_link')) {
		$('print_link').addEvent('click', function(e){
			e.stop();
			if (window.print) {		
				window.print();	    	      
			}
		});
	}

	// Submit the forms of the dropdowns on home page when changed
	if($('sectionTwo')) {
		$$('#sectionTwo select').addEvent('change', function(){
			this.getParent('form').submit();
		});
	}
});