window.addEvent('domready', function() {



var xclicked = false;
		var xrating;
		
			function setRating(xvalue) {
				$$('.ratinglabel').removeClass('activerating');				
				var i = 1;
				for(i=1;i<=xvalue;i++) {
					$('rating_for_'+i).addClass('activerating');
				}
				if(xclicked) {
					noleave = true;
					xclicked = false;
				} else {
					noleave = false;
				}
			}
			
			$$('.ratinglabel').addEvent('mouseleave',function() {
				if(!noleave) {
					xrating = $$('#ratingblock input:checked').map(function(e) { return e.value; });
					setRating(xrating);				
				}
			});
			
			$$('.ratinglabel').addEvent('mouseover',function() {
				xrating = this.get('id').replace('rating_for_','');
				setRating(xrating);
			});
			
			$$('.ratinglabel').addEvent('click',function(){
				xclicked = true;
				xrating = this.get('id').replace('rating_for_','');
				setRating(xrating);
			});	



var totalImg = $$('#box2 img');
	if(totalImg.length > 1) {
		var nS2 = new noobSlide({
			box: $('box2'),
			items: totalImg,
			interval: 3000,
			fxOptions: {
				duration: 500,
				wait: false
			},
			addButtons: {
				previous: $('prev1'),
				next: $('next1')
			}
		});
	}
	
	if($('slideshow-container')){		
		/* settings */
		var showDuration = 4500;
		var container = $('slideshow-container');
		var images = container.getElements('.slideshowSlide');
		var currentIndex = 0;
		var interval;
		/* opacity and fade */
		images.each(function(img,i){ 
			if(i > 0) {
				img.set('opacity',0);
			}
		});
		/* worker */
		var show = function() {
			images[currentIndex].fade('out');
			images[currentIndex = currentIndex < images.length - 1 ? currentIndex+1 : 0].fade('in');
		};
		/* start once the page is finished loading */
		window.addEvent('load',function(){
			interval = show.periodical(showDuration);
		});
	}
	
	

//	if($('search')) {	
	
		/*
var hideTimer;
		
		var defaultText = 'Enter product descripion or name...';

		var updateSearch = new Request({				
			url: "/ajax.do.php?action=live-search", 
			link: 'cancel',
			onSuccess: function(response){
				$('live_search_results').setStyle('display','block');
				$('live_search_results').set('html',response);
			}
		});
*/
			
		/*
$('search').addEvent('keyup', function() {
			updateSearch.post($('searchform'));					
		});
*/

		
		/*
$('search').addEvent('focus', function() {
			hideTimer = $clear(hideTimer);
			if($('search').value == defaultText) {
				$('search').setStyle('color','black');
				$('search').value = "";
			}					
		});
*/
		
		/*

		function hideSearchResults() {
			hideTimer = $clear(hideTimer);
			$('live_search_results').set('html','');
		};
*/
		
		/*
$('search').addEvent('blur', function() {
			if($('search').value == '' || $('search').value == defaultText) {
				$('search').setStyle('color','gray');
				$('search').value = defaultText;
			};		
			hideTimer = hideSearchResults.delay(1000); 
		}).fireEvent('blur');
	};
*/
	


	$$('.navitem').addEvent('mouseenter',function() { 
		$(this.get('id').replace('navitem_','navsubitem_')).setStyle('display','block');
		this.addClass('active');
	});
	
	
	$$('.navitem').addEvent('mouseleave',function() { 
		$(this.get('id').replace('navitem_','navsubitem_')).setStyle('display','none');
		this.removeClass('active');
	});
	
});

function numberReplace(i) {
	i.value.replace(/[^0-9]/g, '');
	return true;
}

