var slideshow_pause_start = 4000;
var menu_disappear = 2000;
var slideshow_pause = 2500;// was 1250 before 04/09/2011
var slideshow_fade = 300;
var slideshow_current = 1;
var slideshow_timeout;
var menu_timeout;
var pause_play_v = 'pause';
var slideshow_light = 1;

$(document).ready
( function()
  {
		  //
				var viewport_width = $("body").width();// -25
				var viewport_height = $("body").height();
    var dummy = 0;
				if($(".fp_button").length > 0)
				{
				  $('.fp_button').each
						( function()
						  {
								  //the idea would be to center the whole system and break it in four areas
										//top left would be :e#

								  var w = $(this).width();
										var h = $(this).height();
										$(this).width(w).height(h);
								}
      );
    }
				if($("#navigation_area").length > 0)
				{
						var img_height = viewport_height - 50 - 50;
						$("#slideshow").width(viewport_width);
						$("#slideshow_image_1").height(img_height).show();
						$("#slideshow_image_2").height(img_height);

      dummy = Math.round((viewport_width - 1150) / 2);
				  $("#navigation_area").css("left",dummy + 'px').show();

      dummy = Math.round((viewport_width - 1150) / 2) + 290;
						$("#back_to").css('left',dummy).show();
      $("#slideshow_image_1").fadeIn(200);

		    menu_timeout = setTimeout("$('#navigation_area').fadeOut(300);",menu_disappear);
		    slideshow_timeout = setTimeout("slideshow_fetch_image();",slideshow_pause_start);
				}
				//
		  $('.my_hover').hover
				( function()
						{
								//$(this).children().children().toggle();
								var id = $(this).attr("id");
        $("#" + id + "_1").hide();
        $("#" + id + "_2").show();
								//$("." + id + "_k").toggle();
						},
						function()
						{
								//$(this).children().children().toggle();
								var id = $(this).attr("id");
        $("#" + id + "_2").hide();
        $("#" + id + "_1").show();
								//$("." + id + "_k").toggle();
						}
				);
		  $('.hover_galleries').hover
				( function()
						{
								$(this).children().children(":first").toggle();
						},
						function()
						{
								$(this).children().children(":first").toggle();
						}
				);
				$('.client_hover').hover
				( function()
						{
						  var id = $(this).attr('id').slice(6);
								$(".logo_" + id).toggle();
								$("#popup_" + id).show();
						},
						function()
						{
						  var id = $(this).attr('id').slice(6);
								$(".logo_" + id).toggle();
								$("#popup_" + id).hide();
						}
				);
				$('.credits').hover
				( function()
				  {
						  $(this).css('color','#66ccff');
						},
						function()
						{
						  $(this).css('color','#666666');
						}
				);
		}
);
function slideshow_fetch_image()
{
		if(slideshow_light == 0)
		{
		  return;
		}
		$("#slide_arrow_right").show();
  $("#slideshow_image_" + slideshow_current).fadeOut
	 ( slideshow_fade,
	   function callback()
	 		{
      $("#slideshow_image_" + slideshow_current).hide();
	 				slideshow_current = slideshow_current == 1 ? 2 : 1;
						var counter = my_current + 1;
						if(counter == 1)
						{
						  $("#slide_arrow_left").hide();
						}
						else
						{
						  $("#slide_arrow_left").show();
						}
						if(counter == my_max + 1)
						{
						  $("#slide_arrow_right").hide();
						  clearTimeout(slideshow_timeout);
						  slideshow_light = 0;
				    $("#slide_pause_play_one").attr('src','./elements/slide_play.png');
				    $("#slide_pause_play_two").attr('src','./elements/slide_play_mouseover.png');
						  pause_play_v = 'play';
						}
						else
						{
						  $("#slide_arrow_right").show();
						}
						$("#slideshow_counter_current").html(counter);
						var key = counter - 1;
						var caption_clean = my_captions[key].replace(' ','&nbsp;');
						$("#caption").html(caption_clean);
      $("#slideshow_image_" + slideshow_current).fadeIn
						( slideshow_fade,
		      function callback()
								{
								  slideshow_timeout = setTimeout("slideshow_fetch_image();",slideshow_pause);
										//var key = counter - 1;
										//$("#caption").html(my_captions[key]);
        }
						);
	 				var temp = slideshow_current == 1 ? 2 : 1;
						++my_current;
						if(my_current > my_max)
						{
						  my_current = 0;
						}
    		$("#slideshow_image_" + temp).attr('src',my_images[my_current]);
	 		}
	 );
 //var slideshow_pause = 1500;
}
function slideshow(item)
{
  switch(item)
		{
		  case -4:
			   clearTimeout(slideshow_timeout);
						slideshow_light = 0;
				  $("#slide_pause_play_one").attr('src','./elements/slide_play.png');
				  $("#slide_pause_play_two").attr('src','./elements/slide_play_mouseover.png');
						pause_play_v = 'play';
						--my_current;
						if(my_current <= 0)
						{
						  my_current = my_max + 1;
						}
						$("#slideshow_counter_current").html('');
						$("#slide_arrow_left").show();
						$("#slide_arrow_right").show();
						var key = my_current - 1;
		    $("#caption").html('');
    		$("#slideshow_image_" + slideshow_current).hide();
	 				var temp = slideshow_current == 1 ? 2 : 1;
    		$("#slideshow_image_" + temp).attr('src',my_images[key]);
						$("#slideshow_counter_current").html(my_current);
						$("#caption").html(my_captions[key]);
    		$("#slideshow_image_" + temp).fadeIn
						( slideshow_fade,
						  function callback()
								{
								}
						);
				  break;
				case 'pause':
						clearTimeout(slideshow_timeout);
						slideshow_light = 0;
				  $("#slide_pause_play_one").attr('src','./elements/slide_play.png');
				  $("#slide_pause_play_two").attr('src','./elements/slide_play_mouseover.png');
						pause_play_v = 'play';
						break;
				case 'play':
						clearTimeout(slideshow_timeout);
						slideshow_light = 1;
		    slideshow_timeout = setTimeout("slideshow_fetch_image();",slideshow_pause);
				  $("#slide_pause_play_one").attr('src','./elements/slide_pause.png');
				  $("#slide_pause_play_two").attr('src','./elements/slide_pause_mouseover.png');
						pause_play_v = 'pause';
				  break;
				case -1:
			   clearTimeout(slideshow_timeout);
						slideshow_light = 0;
				  $("#slide_pause_play_one").attr('src','./elements/slide_play.png');
				  $("#slide_pause_play_two").attr('src','./elements/slide_play_mouseover.png');
						pause_play_v = 'play';
						++my_current;
						if(my_current > my_max + 1)
						{
						  my_current = 1;
						}
						$("#slideshow_counter_current").html('');
						$("#slide_arrow_left").show();
						$("#slide_arrow_right").show();
						var key = my_current - 1;
		    $("#caption").html('');
    		$("#slideshow_image_" + slideshow_current).hide();
	 				var temp = slideshow_current == 1 ? 2 : 1;
    		$("#slideshow_image_" + temp).attr('src',my_images[key]);
						$("#slideshow_counter_current").html(my_current);
						$("#caption").html(my_captions[key]);
    		$("#slideshow_image_" + temp).fadeIn
						( slideshow_fade,
						  function callback()
								{
								}
						);
				  break;

		}
}
function clientsarea_login()
{
  $("#login_feedback").html('');
  $.post
		( "/veronikareps_melyates_ajax.php",
		  { task: 'clientsarea_login',
				  client_username: $('#clientsarea_username').val(),
						client_password: $('#clientsarea_password').val()
				},
				function(data)
				{
      eval(data);
				}
		);
}
function clientsarea_update_comment(image_id, client_id)
{
		var comment_body = $("#comment_body_" + image_id).val();
  $.post
		( "/veronikareps_melyates_ajax.php",
		  { task: 'melyates_clientsarea_comment',
						image_id: image_id,
						client_id: client_id,
				  comment_body: comment_body
				},
				function(data)
				{
      eval(data);
						$("#comments_" + image_id).append("<div>" + comment_body + "</div>");
						$("#comments_" + image_id).append("<div class='comment_signature'>by " + clientsarea_username + "</div>");
						$("#comment_body_" + image_id).val('');
				}
		);
}
function clientsarea_images_update(image_id)
{
  $("#clientsarea_images_updating_" + image_id).css('color','red');
  $.post
		( "/veronikareps_melyates_ajax.php",
		  { task: 'melyates_clientsarea_images_update',
						image_id: image_id,
						image_is_selected: $("#image_is_selected_" + image_id).attr("checked") ? 'yes' : 'no'
				},
				function(data)
				{
      eval(data);
      $("#clientsarea_images_updating_" + image_id).css('color','white');
				}
		);
}
function clientsarea_show_all()
{
  $('.image_block').show();
}
function clientsarea_show_selected()
{
  clientsarea_show_all();
  $(".image_block").each
		( function()
		  {
				  var id = $(this).attr("id").slice(12);
						if(!$("#image_is_selected_" + id).attr("checked"))
						{
						  $(this).hide();
						}
				}
		);
}
function clientsarea_show_high_res()
{
  clientsarea_show_all();
  $(".image_block").each
		( function()
		  {
				  var id = $(this).attr("id").slice(12);
						var content = $.trim($("#is_high_res_" + id).html());
						if(content == '')
						{
        $(this).hide();
						}
				}
		);
}
function toggle_navigation()
{
  $("#navigation_area").toggle();
}
function set_navigation_hide()
{
  setTimeout("$('#navigation_area').hide();", 5000);
}

