var currentimage = 1;
var images = new Array();
jQuery(document).ready(function($){
	 
	$('#main-menu .sub-menu').each(function ()
	{
		$(this).parent().eq(0).hover(function ()
		{
			$('.sub-menu:eq(0)', this).show();
		}, function () {
			$('.sub-menu:eq(0)', this).hide();
		});
	});
	
	$('.gallery img:gt(0)').each(function ()
	{
		$(this).hide();
	});
	
	
	$('.gallery img').each(function ()
	{	
		images.push($(this).attr("src"));
	});
	
	if(images.length>1)
	{
	var output = "";
	
	window.setInterval(changeImage, 5000);
	
	for(var i = 0; i<images.length; i++)
	{
		output = output + '<a href="' + images[i] + '">' + (i+1) + '</a>';
	
	}
	$('.gallery').after('<div class="gallery-selector"><span class="gallery-selector-title">' + e_images + '</span>' + output + '</div>');
	}

		$('.gallery-selector a').click(function(event)
		{
			currentimage = parseInt($(this).text())-1;
			$('.gallery img:eq(0)').attr('src', $(this).attr('href'));
			event.preventDefault();
		});
		
	 $('#s').focus(function() {
		if($('#s').val() == e_search)
		{
			$('#s').val('');
		}
	 });
	 
	 $('#s').blur(function() {
		if($('#s').val() == '')
		{
			$('#s').val(e_search);
		}
	 });		

});

function changeImage()
{
	if(currentimage>=images.length)
	{
		currentimage = 0;
	}
	jQuery('.gallery img:eq(0)').attr('src', images[currentimage]);
	currentimage++;
}
