var current = 1;
var hidden = 2;
var slideshow_image = 2;
$(document).ready
( function()
  {
    setTimeout('slideshow()', 2000);
		  $(".frame_box").corner("5px");
		  $(".rc").corner("5px");
		  $(".rc_top ").corner("6px");
		  //$(".rc_footer").corner("top 6px").corner("bottom 3px");
    align_gallery_boxes();
		  $(".nav_hover").hover
				( function()
				  {
						  $(this).children().toggle();
						},
						function()
						{
						  $(this).children().toggle();
						}
				);
		  $('.hover_galleries').hover
				( function()
						{
						  var gallery_id = $(this).attr('id').slice(8);
								//$(this).children().children(":first").css('background-color', '#444444');
								$(this).children().children(":first").css('background-color', '#666666');
								//$('#gallery_name_background_' + gallery_id).css('background-color', '#000000'); 
								//$('#gallery_name_background_' + gallery_id).css('background-color', '#cccccc'); 
								$('#gallery_name_text_' + gallery_id).css('color', '#000000'); 
						},
						function()
						{
						  var gallery_id = $(this).attr('id').slice(8);
								$(this).children().children(":first").css('background-color', '#ffffff');
								$('#gallery_name_background_' + gallery_id).css('background-color', '#cccccc'); 
								$('#gallery_name_text_' + gallery_id).css('color', '#444444'); 
						}
				);
		}
);
function pavlaquinn_enquire(product_image_id)
{
  $.post
  ( "/toffsystems_clients_pavlaquinn_ajax.php",
	   { task: 'pavlaquinn_enquire',
	     name: $("#name_" + product_image_id).val(),
	     email: $("#email_" + product_image_id).val(),
	     phone: $("#phone_" + product_image_id).val(),
	     message: $("#message_" + product_image_id).val(),
						image_id: product_image_id
	 		},
	 		function(data)
	 		{
				  eval(data);
	   }
	 );
}
function align_gallery_boxes()
{
  var i = 1;
  $(".gallery_box").each
		( function()
		  {
		    if(i == 5)
				  {
				    $(this).css('margin-right','0px');
				  		i = 1;
				  }
				  else
				  {
						  if(i == 2 || i == 4)
								{
				     // $(this).css('margin-right','18px');
        }
				    ++i;
				  }
    }
		);
}
function slideshow()
{
  $("#image_slideshow_" + current).fadeOut
		( 2000,
		  function()
				{
      $("#image_slideshow_" + hidden).fadeIn
	     ( 3000,
		      function()
		      {
          setTimeout("slideshow()", 1000);
				    }
		    );
				  var url = slideshow_images[slideshow_image];
						var padding_left = slideshow_images_margin[slideshow_image];
				  $("#image_slideshow_" + current).attr('src', url);
				  //$("#image_slideshow_" + current).css('left', padding_left);
      current = hidden;
      hidden = current == 1 ? 2 : 1;
						++slideshow_image;
						slideshow_image = slideshow_image == 19 ?  0 : slideshow_image;
				}
		);
}
function show_large(image_id, src, image_width, image_height)
{
  var h_max = $(window).height();
  var w_max = $(window).width();
		var img_h = 0;
		var img_w = 0;
		var left = 0;
		var top = 0;

  hide_large();

		$("#enlarged_img").attr('src',src);
		if(image_width > image_height)
		{
		  img_w = w_max;
				img_h = Math.round(image_height * img_w / image_width);
				left = 0;
				top = Math.round((h_max - img_h) / 2);
				if(img_h > h_max)
				{
				  img_h = h_max;
      img_w = Math.round(image_width * h_max / image_height);
				  left = Math.round((w_max - img_w) / 2);
			  	top = 0;
				}
		}
		else
		{
		  img_h = h_max;
				img_w = Math.round(image_width * img_h / image_height);
				left = Math.round((w_max - img_w) / 2);
				top = 0;
				if(img_w > w_max)
				{
				  img_w = w_max;
						img_h = Math.round(imgage_height * w_max / image_width);
				  left = 0;
				  top = Math.round((h_max - img_h) / 2);
				}
  }
		$("#enlarged_img").css('width',img_w + "px");
		$("#enlarged_img").css('height',img_h + "px");
		$("#enlarged_img").css("left",left + "px");
		$("#enlarged_img").css("top",top + "px");

		$("#enlarged_img").show();
		$("#enlarged_bg").show();
		$("#enlarged_close").show();
  
		$(".text_image").hide();
		$("#text_image_" + image_id).show();
}
function hide_large()
{
  $("#enlarged_bg").hide();
  $("#enlarged_img").hide();
  $("#enlarged_img").attr('src','');
  $("#enlarged_close").hide();
		$("#enlarged_img").css('width',0 + "px");
		$("#enlarged_img").css('height',0 + "px");
		$("#enlarged_img").css("left",0 + "px");
		$("#enlarged_img").css("top",0 + "px");
		$(".text_image").hide();
}

