/*
 *
 *	jQuery Timer plugin v0.1
 *		Matt Schmidt [http://www.mattptr.net]
 *
 *	Licensed under the BSD License:
 *		http://mattptr.net/license/license.txt
 *
 */
 
 jQuery.timer = function (interval, callback)
 {
 /**
  *
  * timer() provides a cleaner way to handle intervals  
  *
  *	@usage
  * $.timer(interval, callback);
  *
  *
  * @example
  * $.timer(1000, function (timer) {
  * 	alert("hello");
  * 	timer.stop();
  * });
  * @desc Show an alert box after 1 second and stop
  * 
  * @example
  * var second = false;
  *	$.timer(1000, function (timer) {
  *		if (!second) {
  *			alert('First time!');
  *			second = true;
  *			timer.reset(3000);
  *		}
  *		else {
  *			alert('Second time');
  *			timer.stop();
  *		}
  *	});
  * @desc Show an alert box after 1 second and show another after 3 seconds
  *
  * 
  */

	var interval = interval || 100;

	if (!callback)
		return false;
	
	_timer = function (interval, callback) {
		this.stop = function () {
			clearInterval(self.id);
		};
		
		this.internalCallback = function () {
			callback(self);
		};
		
		this.reset = function (val) {
			if (self.id)
				clearInterval(self.id);
			
			var val = val || 100;
			this.id = setInterval(this.internalCallback, val);
		};
		
		this.interval = interval;
		this.id = setInterval(this.internalCallback, this.interval);
		
		var self = this;
	};
	
	return new _timer(interval, callback);
 };

$(document).ready(function() {
  // put all your jQuery goodness in here.
  
 var moveImage = new Array(4);
 var counter = 0;
 var buttonPress = false;
 
 for (var x =0; x<2; x++)
 {
	 moveImage[counter] = -(counter * 672);
	 counter++;
 }
 counter = 0;
 
$.timer(5000, function (timer) {
		if(buttonPress == false){
			imageMove();
			
		} else {
			timer.reset(5000);
			buttonPress=false;
		}
	});
 
 function imageMove() {
	 counter ++;
	 $('#move-images').stop().animate({ 
			left: moveImage[counter]+'px'
			},'slow');
	 if (counter == 1) {
		 counter = -1;
	 } 
 };

	$('#move-images').css({'width':'2688px'});
	$('#show1').click(function () {
		 counter = -1;
		imageMove();
		buttonPress=true;
	});
	$('#show2').click(function () {
		 counter = 0;
		imageMove();
		buttonPress=true;
	});
	$('#show3').click(function () {
		 counter = 1;
		imageMove();
		buttonPress=true;
	});
	$('#show4').click(function () {
		 counter = 2;
		imageMove();
		buttonPress=true;
	});
	
	$('.image-btn').mouseenter(function () {
		$(this).children('.hide').fadeIn();
		$(this).children('.absolute').fadeOut();
	});
	
	$('.image-btn').mouseleave(function () {
		$('.image-btn').children('.hide').fadeOut();
		if($('.image-btn').hasClass('on')) {
		} else {
			$('.image-btn').children('.absolute').fadeIn();
		}
	});
	
	$('div.showCont').click(function () { 
	$('.show').removeClass('show');
		$('.on').removeClass('on');
		$('.showCont').children('.hover').fadeOut();
		$('.showCont').children('.norm').fadeIn();
		$(this).addClass('on');
		$('.on').children('.hover').fadeIn();
		$('.on').children('.norm').fadeOut();
		var ID = $(this).attr('id');
		ID = ID.replace("show-", "view_");
		$('div.fadeCont').fadeOut('slow');
		$('#'+ID).fadeIn('slow');
	});

});

