function slide() {
	$('#thumbs' + currg).fadeOut(400);
	$('#embiggen' + currg).hide();
	$('#texts' + currg).fadeOut(400);
	currg++;
	if (currg > maxg)
		currg = 1;
	$("#gallerycounter").html(currg);
	$('#thumbs' + currg).delay(500).fadeIn(400);
	$('#embiggen' + currg).show();
	$('#texts' + currg).delay(500).fadeIn(400);
}

function slidenext() {
	$('#thumbs' + currg).stop(true).hide();
	$('#embiggen' + currg).hide();
	$('#texts' + currg).stop(true).hide();
	currg++;
	if (currg > maxg)
		currg = 1;
	$("#gallerycounter").html(currg);
	$('#thumbs' + currg).delay(100).show(0);
	$('#embiggen' + currg).show();
	$('#texts' + currg).delay(100).show(0);
	clearInterval(timevar);
	timevar = setInterval ("slide()", 5000);
}

function slideprev() {
	$('#thumbs' + currg).stop(true).hide();
	$('#embiggen' + currg).hide();
	$('#texts' + currg).stop(true).hide();
	currg--;
	if (currg == 0)
		currg = maxg;
	$("#gallerycounter").html(currg);
	$('#thumbs' + currg).delay(100).show(0);
	$('#embiggen' + currg).show();
	$('#texts' + currg).delay(100).show(0);
	clearInterval(timevar);
	timevar = setInterval ("slide()", 5000);
}

$(document).ready(function(){
	$.ajaxSetup ({  
    	cache: false,
		type: "POST"
	});
	
	$("#sendsmallcontact1").click(function(){
		if ($("#fullname").val().length < 2) {
			alert('נא להכניס את השם');
			$("#fullname").focus();
			return false;
		}
		if ($("#email").val().length < 6) {
			alert('נא להכניס את האי-מייל');
			$("#email").focus();
			return false;
		}
		if ($("#phone").val().length < 7) {
			alert('נא להכניס את הטלפון');
			$("#phone").focus();
			return false;
		}
		
		var maskHeight = $(document).height();  
        var maskWidth = $(window).width();   
        $('#mask').css({'width':maskWidth,'height':maskHeight});         
        $('#mask').fadeIn(500);      
        $('#mask').fadeTo("fast",0.8);      
        var winH = $(window).height();  
        var winW = $(window).width();
        $('#smallcontactcont').css('top',  winH/2-$('#smallcontactcont').height()/2);
        $('#smallcontactcont').css('left', winW/2-$('#smallcontactcont').width()/2);
        $('#smallcontactcont').fadeIn(500);
		
	});
    
	$("#t1").change(function(){
		$("#t2holder").load("/t2.php", {id: $("#t1").val()}, function(responseText){  
            $("#t2holder").html(responseText); 
        });
	});
	
	$("#sendsmallcontact2").click(function(){
		if ($("#t1").val().length < 1) {
			alert('נא לבחור את התחום בו הינך מעוניין');
			$("#t1").focus();
			return false;
		}
		$("#send2holder").html('שולח...');
		$("#smallcontactcont").load("/sendmail.php", {fullname: $("#fullname").val(), email: $("#email").val(), phone: $("#phone").val(), t1: $("#t1").val(), t2: $("#t2").val(), comment: $("#comment").val()}, function(responseText){  
            $("#smallcontactcont").html(responseText);
			$("#closemodal").click(function(){
				$('#mask, #smallcontactcont').hide();
				$("#fullname, #email, #phone").val('');
				return false;
			});
        });	
	});
	
	$("#smallcontactcontclose").click(function(){
		$('#mask, #smallcontactcont').hide();
		return false;
	});
	
	$("#sendsmallcontact3").click(function(){
		if ($("#fullname").val().length < 2) {
			alert('נא להכניס את השם');
			$("#fullname").focus();
			return false;
		}
		if ($("#email").val().length < 6) {
			alert('נא להכניס את האי-מייל');
			$("#email").focus();
			return false;
		}
		if ($("#phone").val().length < 7) {
			alert('נא להכניס את הטלפון');
			$("#phone").focus();
			return false;
		}
		if ($("#t1").val().length < 1) {
			alert('נא לבחור את התחום בו הינך מעוניין');
			$("#t1").focus();
			return false;
		}
		
		$("#send3holder").html('שולח...');
		$("#send3holder").load("/sendmail.php", {fullname: $("#fullname").val(), email: $("#email").val(), phone: $("#phone").val(), t1: $("#t1").val(), t2: $("#t2").val(), comment: $("#comment").val()}, function(responseText){  
			$("#send3holder").html('<strong>תודה, הודעתך נשלחה</strong>');
			$("#fullname, #email, #phone, #comment, #t1, #t2").val('');
        });	
	});
	
	$("#sendsmallcontact4").click(function(){
		if ($("#fullname").val().length < 2) {
			alert('נא להכניס את השם');
			$("#fullname").focus();
			return false;
		}
		if ($("#email").val().length < 6) {
			alert('נא להכניס את האי-מייל');
			$("#email").focus();
			return false;
		}
		if ($("#phone").val().length < 7) {
			alert('נא להכניס את הטלפון');
			$("#phone").focus();
			return false;
		}
		
		$("#send3holder").html('שולח...');
		$("#send3holder").load("/sendmail.php", {fullname: $("#fullname").val(), email: $("#email").val(), phone: $("#phone").val(), comment: $("#comment").val()}, function(responseText){  
			$("#fullname, #email, #phone, #comment, #t1, #t2").val('');
			window.location = "contact-thankyou.php";
        });	
	});
	
	if ($("#gallerycontainer").length) {
		$("a[rel=gallery]").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'outside',
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<table class="subgtitle"><tr><td class="subgtitle1">' + title + '</td><td class="subgtitle2"></td><td class="subgtitle3">תמונה ' + (currentIndex + 1) + ' מתוך ' + currentArray.length + '</td></tr></table>';
			}
		});
		
		$("a[rel=gallery2]").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'outside',
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<table class="subgtitle"><tr><td class="subgtitle1">' + title + '</td><td class="subgtitle2"></td><td class="subgtitle3">תמונה ' + (currentIndex + 1) + ' מתוך ' + currentArray.length + '</td></tr></table>';
			}
		});
	}
	
	if ($("#gallerynext").length) {
		currg = 1;
		maxg = parseInt($("#gallerytotal").html());
		timevar = setInterval ("slide()", 5000);
		
		$("#gallerynext").click(slidenext);
		$("#galleryprev").click(slideprev);
	}
	
	if ($("#gallerycontent-2").length) {
		$("a[rel=gallery]").fancybox({
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'titlePosition' 	: 'outside',
			'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<table class="subgtitle"><tr><td class="subgtitle1">' + title + '</td><td class="subgtitle2"></td><td class="subgtitle3">תמונה ' + (currentIndex + 1) + ' מתוך ' + currentArray.length + '</td></tr></table>';
			}
		});
	}
	
	
	
});
