$(document).ready(function() {
	//declare array to remember data
	var data = new Array();
    
    //hide left arrow if below photos count
    $("div[total_photos!='']").each(function() {
       var total_photos = $(this).attr('total_photos');
       var id = $(this).attr('id');
       var production = id.substr(12, 15);

       	if (total_photos <= 4) {
            $(".left_arrow[production='"+production+"']").hide();
       }
    });
	
	//left arrow
	$(".left_arrow").click(function() {
		var production = $(this).attr('production');
		var div_name = 'list_photos_'+production;
		var total_photos = $('#'+div_name).attr('total_photos');
		
		if (data[div_name] == null || data[div_name] == 0) {
			var start_limit = 5;
			$(".right_arrow[production="+production+"]").show();
		} else {
			var start_limit = data[div_name] + 5;
		}
		    
		start_limit--;
		var url = '/index/ajaxphotos/production/'+production+'/start/'+start_limit;
		$.ajax({
            type: 'GET',
            url: url,
            success: function(html) {
                if (html != 'null') {
            		$('#'+div_name).html(html);        
            		data[div_name] = start_limit;
                }
            }
        });	
        
        
        var end_limit = start_limit + 5;
        if (end_limit >= total_photos) {
            $(this).hide();
        }
                
	});
	
	//right arrow
	$(".right_arrow").click(function() {
		var production = $(this).attr('production');
		var div_name = 'list_photos_'+production;
		
		var start_limit = data[div_name] - 5;
		
		if (start_limit <= 0) {
            $(this).hide();
            start_limit = 0;
        }
		
        var url = '/index/ajaxphotos/production/'+production+'/start/'+start_limit;

		$.ajax({
            type: 'GET',
            url: url,
            success: function(html) {
                if (html != 'null') {
            		$('#'+div_name).html(html);        
            		data[div_name] = start_limit;
                     $('.leftzz_arrow[production='+production+']').show();
              }
            }
        });	             
	});
	   // Validate Forms
       $("#fj_send").submit(function() {
               if($("#fj_name")[0].value.length>0) {
                       alert("�� ���� ���� ����� ������ ����");
                       return false;
                       }
               if( $("#fj_phone")[0].value.length>0) {
                       alert("����� ���� ����� �� �����");
                       return false;
                       }

               if( $("#fj_email")[0].value.length>0) {
                       alert("���� �������� ���� ����");
                       return false;
                       }
               if( $("#fj_title")[0].value.length>0) {
                       alert();
                       return false;
                       }
               if(  $("fj_brief")[0].value.length>0) {
                       alert();
                       return false;
                       }
			  if(  $("fj_target")[0].value.length>0) {
                       alert();
                       return false;
                       }
			 if(  $("fj_method")[0].value.length>0) {
                       alert();
                       return false;
                       }
			 $.ajax({
                        type: "GET",
                        url: "",
                        data: "",
                        success: function(msg){
                        alert( "Data Saved: " + msg );
                       }
                });
	   


            });
       });
