$(document).ready(function(){

	//Initialize
	$("#video").hide();
	$("#button-screenshots img").attr("src","images/button-screenshots-active.jpg");

	//Video hide function
	function showvideo() {
		$("#video").show();
	};
	
	//Preload images function
	jQuery.preloadImages = function() {
  		for(var i = 0; i<arguments.length; i++) {
			jQuery("<img>").attr("src", arguments[i]);
		}
	}
	
	//Preload images
	$.preloadImages("images/button-screenshots.jpg", "images/button-screenshots-down.jpg", "images/button-screenshots-active.jpg", "images/button-screenshots-active-down.jpg", "images/button-video.jpg", "images/button-video-down.jpg", "images/button-video-active.jpg", "images/button-video-active-down.jpg");
	
	//Button path function
	function buttonpath(oldpath) {
		var newpath;
		if(oldpath=="images/button-screenshots.jpg") { newpath="images/button-screenshots-down.jpg"; }
		else if(oldpath=="images/button-screenshots-active.jpg") { newpath="images/button-screenshots-active-down.jpg"; }
		else if(oldpath=="images/button-screenshots-down.jpg") { newpath="images/button-screenshots.jpg"; }
		else if(oldpath=="images/button-screenshots-active-down.jpg") { newpath="images/button-screenshots-active.jpg"; }
		else if(oldpath=="images/button-video.jpg") { newpath="images/button-video-down.jpg"; }
		else if(oldpath=="images/button-video-active.jpg") { newpath="images/button-video-active-down.jpg"; }
		else if(oldpath=="images/button-video-down.jpg") { newpath="images/button-video.jpg"; }
		else if(oldpath=="images/button-video-active-down.jpg") { newpath="images/button-video-active.jpg"; }
		return newpath;
	};

	//Click on button screenshots
	$("#button-screenshots").click(function(event){
	
		$("#video").hide();
	
		$("#section2-block").animate({
			left: "0"
		}, 600 );
		
		$("#button-screenshots img").attr("src","images/button-screenshots-active.jpg");
		$("#button-video img").attr("src","images/button-video.jpg");

	});
   
   	//Click on button video
	$("#button-video").click(function(event){
		
		$("#section2-block").animate({ 
				left: "-1022px"
		}, 600, showvideo );
		
		$("#button-screenshots img").attr("src","images/button-screenshots.jpg");
		$("#button-video img").attr("src","images/button-video-active.jpg");

	});

    //Button up/down
    $("#section2 .button").mouseup(function(){
    	var oldpath = jQuery("img", this).attr("src");
    	var newpath = buttonpath(oldpath);
		jQuery("img", this).attr("src", newpath);	
    }).mousedown(function(){
    	var oldpath = jQuery("img", this).attr("src");
    	var newpath = buttonpath(oldpath);
		jQuery("img", this).attr("src", newpath);
    });
    

 });