/* Gallery */
var iImagesCount;
var iGalleryCurrentImage = 0;

	function fGallerySwitch(iImageNumber) {
		if(iImageNumber != iImagesCount) $('.gallery-box .next').show(); else $('.gallery-box .next').hide();	
		if(iImageNumber != 0) $('.gallery-box .prev').show(); else $('.gallery-box .prev').hide();	
			
		jQuery(".images-normal img").fadeOut("slow");  	 
		jQuery(".images-normal img:eq("+iImageNumber+")").fadeIn("slow");  	 
		
		jQuery(".images-thumbials img").hide();
		var i = iImageNumber-2;
		var iEnd = iImageNumber+2;
	
		if(i<0) i = 0;
		if(iEnd<4) iEnd = 4;
		if(iEnd>iImagesCount) { i= iImagesCount-3; iEnd = iImagesCount+1; }
		for(i; i < iEnd; i++ )
			jQuery(".images-thumbials img:eq("+i+")").fadeTo(0,0.4);
			
			
		jQuery(".images-thumbials img:eq("+iGalleryCurrentImage+")").fadeTo(0,1);
	}

$(document).ready(function(){

	/* Drop-menu */
	$(".nav-our-services, .sub-nav-our-services").hover(
		function() { $(".sub-nav-our-services").show(); $(".nav-our-services").addClass("nav-hover"); } , function() { $(".sub-nav-our-services").hide(); $(".nav-our-services").removeClass("nav-hover"); }
	);
	$(".nav-about-us, .sub-nav-about-us").hover(
		function() { $(".sub-nav-about-us").show(); $(".nav-about-us").addClass("nav-hover"); } , function() { $(".sub-nav-about-us").hide(); $(".nav-about-us").removeClass("nav-hover"); }
	);
	
	/* Forms */
	var sTempValue
	$("input, textarea").focus(
		function() {
			sTempValue = $(this).val();
			if(sTempValue == "Full name" || sTempValue == "Message" || sTempValue == "E-mail" || sTempValue == "Phone")
			{
				$(this).val("");
				}
		}
	);
	
	$("input, textarea").blur(
		function() {		
			if($(this).val() == "" )
				$(this).val(sTempValue);
		}
	);

	/* Gallery */
	$('.gallery-box .prev, .gallery-box .next').fadeTo(0,0.70);
	$('.gallery-box .prev').hide();
	
	jQuery(".images-normal img").hide(); 
	jQuery(".images-thumbials img").hide();
	
	iImagesCount = jQuery(".images-normal > img").length-1;
	jQuery(".images-normal img:eq("+iGalleryCurrentImage+")").fadeIn("slow");	
	
	var iStop;
	if(iImagesCount > 3)
		iStop = 3;
	else
		iStop = iImagesCount;
		
	for(var i = 0;i <= iStop; i++)
		jQuery(".images-thumbials img:eq("+i+")").fadeTo(0,0.4);
	
	jQuery(".images-thumbials img:eq("+iGalleryCurrentImage+")").fadeTo(0,1);
	jQuery(".images-thumbials img").hover(
		function() {
			$(this).stop(true,true).fadeTo(0,1);
		}
		,
		function() {
			$(this).stop(true,true).fadeTo(0,0.4);
			jQuery(".images-thumbials img:eq("+iGalleryCurrentImage+")").fadeTo(0,1);
		}
	);
	
	if(iImagesCount == 0) {
		$('.gallery-box .prev').hide();
		$('.gallery-box .next').hide();
	}
	
	$('.gallery-box .next').click(
		function() {
			if(iGalleryCurrentImage != iImagesCount) {
				iGalleryCurrentImage++;
				fGallerySwitch(iGalleryCurrentImage);
			}
			if(iGalleryCurrentImage == iImagesCount)
				$('.gallery-box .next').hide();			
		}
	);	
	
	$('.gallery-box .prev').click(
		function() {		
			if(iGalleryCurrentImage != 0) {
				iGalleryCurrentImage--;
				fGallerySwitch(iGalleryCurrentImage);
			}
			
			if(iGalleryCurrentImage == 0)
				$('.gallery-box .prev').hide();
						
		}
	);
	
	$('.images-thumbials a').click(
		function() {
			iGalleryCurrentImage = $(this).index();
			fGallerySwitch(iGalleryCurrentImage);
		}
	);
	
	$('.gallery-box .next').hover(
		function() { if(iGalleryCurrentImage != iImagesCount) $(this).fadeTo('fast',1);	}
		,
		function() { if(iGalleryCurrentImage != iImagesCount) $(this).stop(true,true).fadeTo('fast',0.70); }
	);	
	
	$('.gallery-box .prev').hover(
		function() { if(iGalleryCurrentImage != 0) $(this).fadeTo('fast',1); }
		,
		function() { if(iGalleryCurrentImage != 0) $(this).stop(true,true).fadeTo('fast',0.70); }
	);
});
