$(document).ready(function() {
	
	// ---- Slider starts here ---- //
	
	// Positioning slider info boxes
	alignSliderInfo();	
	
	// Positioning slider arrows
	
	elmax = 0-(4-2)*417;
	
	pos = $("#Slider").offset();
	leftpos = parseInt(pos.left)-15;
	rightpos = parseInt(pos.left)+880-45;
	
	if ($.browser.msie) {
		toppos = parseInt(pos.top)+110;	
	} else {
		toppos = parseInt(pos.top)+190;
	}
	
	
	$(".LeftArrow").css({left: leftpos, top: toppos, display: 'none'});
	$(".RightArrow").css({left: rightpos, top: toppos, display: 'block'});
	
	// Move slider to left
	
	$(".LeftArrow").click(function() {
		
		if (parseInt($("#SliderContainer").css("marginLeft"))+417 >= 0) {
			$(".LeftArrow").css({display: 'none'});
		}
		else {
			$(".LeftArrow").css({display: 'block'});
		}
		
		if (parseInt($("#SliderContainer").css("marginLeft"))+417 <= elmax) {
			$(".RightArrow").css({display: 'none'});
		}
		else {
			$(".RightArrow").css({display: 'block'});
		}		

		$("#SliderContainer").clearQueue();
		newleft = parseInt($("#SliderContainer").css("marginLeft"))+417;
		$("#SliderContainer").animate({marginLeft: newleft});
		
	});
	
	// Move slider to right
	
	$(".RightArrow").click(function() {
	
		if (parseInt($("#SliderContainer").css("marginLeft"))-417 <= elmax) {
			$(".RightArrow").css({display: 'none'});
		}
		else {
			$(".RightArrow").css({display: 'block'});
		}
		
		if (parseInt($("#SliderContainer").css("marginLeft"))-417 >= 0) {
			$(".LeftArrow").css({display: 'none'});
		}
		else {
			$(".LeftArrow").css({display: 'block'});
		}

		$("#SliderContainer").clearQueue();
		newleft = parseInt($("#SliderContainer").css("marginLeft"))-417;
		$("#SliderContainer").animate({marginLeft: newleft});
		
	});	
	
	// Expand slider items info box 
	
	$("div.SliderFrame").children("div.HoverZone").mouseenter(function() {
		$(this).children("div.SliderInfo").clearQueue();
		$(this).children("div.SliderInfo").animate({marginTop: '0px'}, 300);		
	}).mouseleave(function() {
		newtop = 195-parseInt($(this).children("div.SliderInfo").children("h2").height());
		$(this).children("div.SliderInfo").animate({marginTop: newtop}, 200);		
	});		
	
	// ---- Contact start here ---- //
	
	// Open contact window
	
	$("#ContactButt").click(function() {
		
		$("#ContactButt").animate({left:-50}, 400);
		
		$("#ContactBackground").css({opacity:0, display: 'block'});
		$("#ContactBackground").animate({opacity:0.8}, 200);
		
		$("#ContactWindow").css({left:-650, display: 'block'});
		$("#ContactWindow").animate({left:325}, 600);
		
		$("#CloseButton").css({left:-100, display: 'block'});
		$("#CloseButton").animate({left:875}, 600);
		
		$("#CloseButton").animate({left:925}, 400);
				
	});
	
	// Close contact window
	
	$("#CloseButton").click(function() {
		
		$("#ContactBackground").animate({opacity:0}, 200).hide(0);
		$("#ContactWindow").animate({left:-650}, 600).hide(0);
		$("#CloseButton").animate({left:-100}, 600).hide(0);
		
		$("#ContactButt").delay(550).animate({left:0}, 400);
		
		
		$("#firstandlastname, #email, #message").removeClass("empty");
		$("#firstandlastname, #email, #message").val("");
		$("#Error").fadeOut(0);
		$("#Success").fadeOut(0);
		
	});
	

	// ---- Button hovers starts here ---- //
	
	// Action button
	
	$(".ActionButton").mouseover(function() {		
		$(this).children("img").attr("src","images/actionbutton_on.png");
	}).mouseout(function() {
		$(this).children("img").attr("src","images/actionbutton.png");
	});	
	
	// Sliders read more buttons
	
	$(".SliderFrame").children(".HoverZone").children(".SliderInfo").children("p").children("a").children("img").mouseover(function() {
		$(this).attr("src","images/seemore_on.png");
	}).mouseout(function() {
		$(this).attr("src","images/seemore.png");
	});			
	
	// Close contact window button
	
	$("#CloseButton").mouseover(function() {
		$(this).children("img").attr("src","images/close_on.png");
	}).mouseout(function() {
		$(this).children("img").attr("src","images/close.png");
	});		

	// Open contact window button
	
	$("#ContactButt").mouseover(function() {
		$(this).children("img").attr("src","images/contactbutt_on.png");
	}).mouseout(function() {
		$(this).children("img").attr("src","images/contactbutt.png");
	});			
	
	// Contact send button
	
	$(".SendButt").mouseover(function() {
		$(this).attr("src","images/send_on.png");
	}).mouseout(function() {
		$(this).attr("src","images/send.png");
	});		
	
	$(".SendButt").click(function() {
		
		$("#firstandlastname, #email, #message").removeClass("empty");
		$("#Error").fadeOut(0);
		$("#Success").fadeOut(0);
		
	});
	
	$("#ContactFormSubmit").ajaxForm(function() { 
		
		var status = '';
		
		
		if ($("#firstandlastname").val() == '') {
			$("#firstandlastname").addClass("empty");
			status = 'fail';
		}
		if ($("#email").val() == '') {
			$("#email").addClass("empty");
			status = 'fail';
		}		
		if ($("#message").val() == '') {
			$("#message").addClass("empty");
			status = 'fail';
		}		
		
		if (status == 'fail') {
			$("#Error").fadeIn(200);
		} else {
			$("#Success").fadeIn(200);
		}
		
	});    
	
	
});


function alignSliderInfo() {
	
	$("div.SliderInfo").each(function(index) {
		nr = index+1;
		newtop = 195-parseInt($("#SliderInfo"+nr).children("h2").height());
		$("#SliderInfo"+nr).css({marginTop: newtop});
	});
	
	
}
