function buOv(id)
{
	document.getElementById(id).className = 'menuBuOv';
}

function buOut(id)
{
	document.getElementById(id).className = 'menuBu';
}

function bu2Ov(id)
{
	document.getElementById(id).className = 'menuBubOv';
}

function bu2Out(id)
{
	document.getElementById(id).className = 'menuBub';
}

function clearDefault(id)
{
  if(id.defaultValue == id.value)
  {
  	id.value = "";
  }
}

function setDefault(id)
{
  if(id.value == "")
  {
  	id.value = id.defaultValue;
  }
}

var images = [];
var currentImage = 0;
	
$(document).ready(
function()
{

	// gallery hovers
	$(".galleryBlock").hover(
	function()
	{
		$(this).find("a").addClass("hover");
	},
	function()
	{
		$(this).find("a").removeClass("hover");
	}
	);
	
	// gallery clicks
	
	$(".galleryBlock").click(
	function()
	{
		var url = $(this).find("a").attr("href");
		window.location=url;
	}
	);
	
	// left sidebar rollover
	$("div.rollover").hover(
	function()
	{
		$(".rollOverText").show();
	},
	function()
	{
		$(".rollOverText").hide();
	}
	);

	$('.qtip').each(
	function()
	{
		$(this).qtip(
		{
	      	content: '<img src="' + $(this).find("img.thumbImage").attr("src") + '" alt="">', 
	      	show: 'mouseover',
	     	style:
	     	{
	     		background: "transparent",
	     		border: 0
	     	},
			padding: 10,
	      	position: 
	  	 	{
	    		corner: 
	    		{
	        		target: 'topMiddle',
	        		tooltip: 'bottomMiddle'
	      		}
	   		}
   		}
   		);
   		
   		var imageSrc = $(this).find("img.newImage").attr("src");
   		if(typeof imageSrc != "undefined")
		{
			images.push(imageSrc);
			//imgPreload = new Image(); 
			//imgPreload.src = imageSrc;
		}
		
		
   		
   		$(this).click(function(){
   		var newImage = "url(\"" + $(this).find("img.newImage").attr("src") + "\") center center no-repeat";
   		
   		/*
$(".imageViewer").fadeOut(200, function(){
   		$(".imageViewer").css("background", newImage);
   		});
   		$(".imageViewer").fadeIn(200);
*/
		$(".imageViewer").css("background", newImage);
   		$("a.url").removeClass("active");
   		$(this).find("a").addClass("active");
   		
   		for (i=0;i<images.length;i++)
		{
			if(images[i] == $(this).find("img.newImage").attr("src"))
			{
				currentImage = i;
			}
		}
		if(currentImage === 0)
   		{
   			$(".btnLeft").hide();
   		}
   		if((currentImage + 1) != images.length)
   		{
   			$(".btnRight").show();
   		}
   		
   		if((currentImage + 1) == images.length)
   		{
   			$(".btnRight").hide();
   		}
   		if((currentImage + 1) != 1)
   		{
   			$(".btnLeft").show();
   		}
   		
   		});
   		
    }
    );

    
    $(".btnRight").click(function(){
    
		var i2 = 0;
    	for (i=0;i<images.length;i++)
		{
			if(i == currentImage && i2 === 0)
			{
				if((images.length - 1) == i)
				{
					nextImage = images[i];					
					currentImage = i;
				}
				else
				{
					nextImage = images[i + 1];					
					currentImage = i + 1;
				}
				
				i2++;
				//console.log("nextImage: " + nextImage);
			}
		
		} 
		
   		var newImage = "url(\"" + nextImage + "\") center center no-repeat";
   		$(".imageViewer").css("background", newImage);
   		$("a.url").removeClass("active");
   		$("#nav" + (currentImage + 1)).addClass("active");
   		if((currentImage + 1) == images.length)
   		{
   			$(this).hide();
   		}
   		if((currentImage + 1) != 1)
   		{
   			$(".btnLeft").show();
   		}
   	});  
   	
   	$(".btnLeft").click(function(){
    
		var i2 = 0;
    	for (i=0;i<images.length;i++)
		{
			if(i == currentImage && i2 === 0)
			{
				if(i === 0)
				{
					nextImage = images[i];				
					currentImage = currentImage
/* 					console.log('currentImage: ' + currentImage); */
				}
				else
				{
					nextImage = images[i - 1];					
					currentImage = i - 1;
				}
				
				i2++;
				//console.log("nextImage: " + nextImage);
			}
		} 
		
   		var newImage = "url(\"" + nextImage + "\") center center no-repeat";
   		$(".imageViewer").css("background", newImage);
   		$("a.url").removeClass("active");
   		$("#nav" + (currentImage + 1)).addClass("active");
   		if(currentImage === 0)
   		{
   			$(this).hide();
   		}
   		if((currentImage + 1) != images.length)
   		{
   			$(".btnRight").show();
   		}
   	});
   	
   	if(currentImage === 0)
   		{
   			$(".btnLeft").hide();
   		}
   	if((currentImage + 1) != images.length)
   		{
   			$(".btnRight").show();
   		}
	if((currentImage + 1) == images.length)
   		{
   			$(".btnRight").hide();
   		}  
/*
	console.log('currentImage: ' + currentImage);
	console.log('images.length: ' + images.length);
*/
});
