
var rolloverimg;
var orgimg;
$(document).ready(function() {

$(".bt1").hover(
	function(){
	$(".bt1").addClass("hbt1");
	},
	function(){
	$(".bt1").removeClass("hbt1");
	}
	);
	$(".bt2").hover(
		function(){
		$(".bt2").addClass("hbt2");
		},
		function(){
		$(".bt2").removeClass("hbt2");
		}
		);
$(".bt3").hover(
			function(){
			$(".bt3").addClass("hbt3");
			},
			function(){
			$(".bt3").removeClass("hbt3");
			}
			);
$(".bt4").hover(
				function(){
				$(".bt4").addClass("hbt4");
				},
				function(){
				$(".bt4").removeClass("hbt4");
				}
);



$(".ro").hover(
		function(){
			orgimg = $(this).attr('src');
			 rolloverimg = 'img/work/thumbs/'+$(this).attr('rel');
			$(this).attr('src', rolloverimg );
		},
		function(){
			$(this).attr('src',orgimg);
		}
	)

var lr = "l";
	$('#wthumbs').mousemove(function(e) {

	    var posX = e.clientX;
	    var posY = e.clientY;
	    var p = $("#wthumbs");
			var offset = p.offset();

	    var newLeft = posX-offset.left;
	    var lessthan= 150 + offset.left;
	    if (newLeft < 150){

	    if (lr == "r"){
		 lr = "l";
	    $('#thumbcontainer').animate({right:"0px"},1000);
	    }  }

	    if (newLeft >= 700){
	    if (lr == "l"){
			 lr = "r";
		    $('#thumbcontainer').animate({right: "600px"},1000);
	    }
	    }
	    $('#x').text(newLeft+","+lr)
	    });
	

$("#thumbcontainer img").click(
	function(){
		var imgname = $(this).attr('src').match(/^.*\/(.*?)$/)[1];
		var wholeSrc = "img/work/"+$(this).attr('src').match(/^.*\/(.*?)$/)[1];
		
		if (imgname.match(/_on\.jpg$/)){
			 newSrc = $(this).attr("src").replace("_on.jpg","_off.jpg");
			 wholeSrc = "img/work/"+newSrc.match(/^.*\/(.*?)$/)[1];
			$('#lightson').show();
			$('#lightson h3').text("Turn the lights on.")
			
		}
		else{
			$('#lightson').hide();
		}
//		alert(newSrc+" "+wholeSrc)
		$("#theimg img").attr("src",wholeSrc)
	}
	)

$("#lightson h3").click(
	function(){
		
		if ($(this).text() == "Turn the lights on."){
		 var thenewSrc = $("#theimg img").attr("src").replace("_off.jpg","_on.jpg");
	
		$("#theimg img").attr("src",thenewSrc);
		$(this).text("Turn the lights off.")
		//alert(thenewSrc)
		}
		else if ($(this).text() == "Turn the lights off."){
			 var thenewSrc = $("#theimg img").attr("src").replace("_on.jpg","_off.jpg");

			$("#theimg img").attr("src",thenewSrc);
			$(this).text("Turn the lights on.")
		}
	}
	)
$("#submit").click(	function(e){
	var name = $('#fname').val();
	var tel = $('#ftel').val();
	var email = $('#femail').val();
	var message = $('#fmess').val();
	
	$("#contactf").fadeOut();
	$("#message").text("Sending your message...");
	$.post("send.php", {n:name ,t:tel ,e:email ,m:message}, 
		function(data){
			if (data=="1"){$("#message").text('Your message has been sent!')}
			else if (data=="2"){$("#message").html('<b>There was an error while sending your message. Please try again.</b>');$("#contactf").fadeIn();}
			else if (data=="3"){$("#message").html('<b>You have not entered a valid E-Mail address. Please try again.</b>');$("#contactf").fadeIn();}
		}
	, "html");
return false;
}

)

$("#thumbcontainer img:eq(0)").click();


//end of doc
});
