$(document).ready(function () {
	
	$('.color').tooltip({ 
	    track: true, 
		delay: 0, 
	    showURL: false, 
		extraClass: 'preview',
	    bodyHandler: function() { 
			$return = $("<img/>").attr("src", $(this).children("img").attr('title'));
			return $return;
	    }
	});
	
	
	$("#lightbox").bind("keypress click",function() {
	   	$("select").hide();
	});
	
	
	$("form#frmMenu, form.frmStones, form.frmCompanies").bind('submit', function () {
		var _url = $(this).attr('action');
		var _get = '';
		$(this).children('input,select').each(function () {
			if ($(this).val() != '' && $(this).attr('type') != 'image' && $(this).val() != 'keyword' && $(this).val() != 'state') {
				_get = _get + '/' + $(this).attr('name') + '/' + $(this).val().replace(/\//g,"%");
			}
		});
		
		$(this).children('div').children('input,select').each(function () {
			if ($(this).val() != '' && $(this).attr('type') != 'image' && $(this).val() != 'keyword' && $(this).val() != 'state') {
				_get = _get + '/' + $(this).attr('name') + '/' + $(this).val().replace(/\//g,"%");
			}
		});
		
		
		if ($("#order") != null) {
            _val = $("#order").val();			
            if (_val != '' && _val != undefined) {
				_get = _get + '/order/' + _val;
			}
		}
		
		if ($("#limit") != null) {
            _val = $("#limit").val();			
            if (_val != '' && _val != undefined) {
				_get = _get + '/limit/' + _val;
			}
		}
		
		if (_get != '') {
			_url = _url + '/get' + _get;
			_url = _url.replace(/\/\//gi,'/');
			_url = _url.replace(/http:\//,'http://');
		}
		
		document.location = _url;
		return false;
	});
	
	$('#advanced-search').toggle(
			function () {
				$('#advanced-search-div').slideDown('slow')
	        }, function () {
	           $('#advanced-search-div').slideUp('slow')
	        }
	)
	
	$("#order, #limit, #category").change(function () {
		$(this).parent('form').submit();
	});
	
	$(".error").tooltip({
	   top: -15
	});
	
	$(".lightbox").lightbox();
	
	
	$(".menhuRadio").click(function () {		
		formID = "#"+$(this).val();		
		$("#menuForm form").hide();
		$(formID).show();
	})
	
});
	
var t;
function banner() {
	var $prev = $('.banner').children('a:visible');
	var $next;
	if ($prev.length == 0 || $prev.next().length == 0) {
		$prev = $('.banner').children('a:first');
		$next = $('.banner').children('a:first');
	} else {
		$next = $prev.next();
	}
	$prev.fadeOut('slow', function () {$next.fadeIn('slow')})
}
t = window.setInterval("banner()", 5000);
