$(document).ready(function()
				  {
					$(".fancyImage").fancybox({
											   "overlayShow"   : true,
											   "transitionIn"  : "elastic",
											   "transitionOut" : "elastic"
											  });
					
				    $(".menu_item > a").hover(function()
											{
											  $(this).parent()
											  		 .addClass("menu_item_hover");
											},
											function()
											{
											  $(this).parent()
											  		 .removeClass("menu_item_hover");
											});
					
					$(".language").hover(function()
										 {
										   $(this).addClass("active_lang");
										 },
										 function()
										 {
										   $(this).removeClass("active_lang");
										 });
					
					selectActiveLanguage();
					selectActiveMenu();
					
					$("#menu_"+ID_PRODUCTS).bind("mouseover",function()
															 {
															   $(this).next("div")
												   		   			  .show();
															 })
										   .bind("mouseout",function()
														    {
															  $(this).next("div")
														   			 .hide();
															});
					$(".product_cats_in_menu").hover(function()
													 {
													   $(this).show();
													   $(this).parent()
											  		 		  .addClass("menu_item_hover");
													 },
													 function()
													 {
													   $(this).hide();
													   if ( TOPSECTION != ID_PRODUCTS )
													      $(this).parent()
											  		 		     .removeClass("menu_item_hover");
													 });
					
					$("#productsCarousel").jcarousel({
													  scroll : 1
													 });
					$("#worksCarousel").jcarousel({
												   scroll : 1
												  });
					$("#homeCarousel").jcarousel({
												  scroll : 3
												 });
				  });

function selectActiveLanguage()
{
  $("#lang_"+LANG).parent()
  				  .addClass("active_lang")
				  .unbind();
}

function selectActiveMenu()
{
  $("#menu_"+TOPSECTION).parent()
  						.addClass("menu_item_hover");
  $("#menu_"+TOPSECTION).unbind();
}

function loadProductImage( img, k )
{
  $("#productZoomImage").html("<center><img src='images/loading.gif' style='margin:200px 0 200px 0'></center>");
  $("#productsCarousel li div.product_carousel_active").hide();
  activeImageIndex=k;
  $(".product_texts").hide();
  $("#productTexts_"+k).show();
  $("#productZoomImage").load("ajax.php?action=1",
							  {
							   image : images[k]
							  },
							  function( res )
							  {
							  });
  $(img).parent()
  		.next("div")
  		.show();
}

function slideProductsImages( action )
{
  if ( action=="prev"  )
  {
	if ( activeImageIndex==0 )
	   activeImageIndex=num-1;
	else
	  activeImageIndex--;
  }
  else
  {
	if ( activeImageIndex==num-1 )
	   activeImageIndex=0;
	else
	  activeImageIndex++;
  }
var obj=$("#productsCarousel li:eq("+activeImageIndex+") div:eq(0) img");
  
  loadProductImage(obj,activeImageIndex);
}

function loadWorkImage( img, k )
{
  $("#workZoomImage").html("<center><img src='images/loading.gif' style='margin:100px 0 100px 0'></center>");
  $("#worksCarousel li div.work_carousel_active").hide();
  activeImageIndex=k;
  $("#workZoomImage").load("ajax.php?action=2",
							  {
							   image : images[k]
							  },
							  function( res )
							  {
							  });
  $(img).next("div")
  		.show();
}

function slideWorksImages( action )
{
  if ( action=="prev"  )
  {
	if ( activeImageIndex==0 )
	   activeImageIndex=num-1;
	else
	  activeImageIndex--;
  }
  else
  {
	if ( activeImageIndex==num-1 )
	   activeImageIndex=0;
	else
	  activeImageIndex++;
  }
var obj=$("#worksCarousel li:eq("+activeImageIndex+") img");
  
  loadWorkImage(obj,activeImageIndex);
}

function sendContactsEmail()
{
var name=$.trim( $("#Name").attr("value") ),
	subject=$.trim( $("#Subject").attr("value") ),
	text=$.trim( $("#Message").attr("value") );
  
  if ( name=="" )
  {
	alert(contactsErrors[0]);
	$("#Name").focus();
	return false;
  }
  if ( subject=="" )
  {
	alert(contactsErrors[1]);
	$("#Subject").focus();
	return false;
  }
  if ( text=="" )
  {
	alert(contactsErrors[2]);
	$("#Message").focus();
	return false;
  }
  
  return true;
}

function activeHomeTopSlide( index )
{
  activeSlideIndex=index;
  
  $("#homeImage").attr("src",topSlideImages[index].src);
  
  $(".home_ramkaner img").attr("src",images[0].src);
  $("#homeRamka_"+index).attr("src",images[1].src);
  
  $(".home_texts_top").hide();
  $("#homeTexts_"+index).show();
}

function autoChangeSlide()
{
  if ( activeSlideIndex==(n-1) )
  	 activeHomeTopSlide(0);
  else
    activeHomeTopSlide(activeSlideIndex+1);
}
