/* Author: Silverfish AG, Marcel Stadelmann
   Date: 15. September 2011
*/

debugArr = [];
debugObj = {};

$(function() {

    // detect ie
    isIE  = ($.browser.msie) ? true : false;
    isIE6 = ($.browser.msie && parseInt(jQuery.browser.version) == 6) ? true : false;
    isIE7 = ($.browser.msie && parseInt(jQuery.browser.version) == 7) ? true : false;
    isIE8 = ($.browser.msie && parseInt(jQuery.browser.version) == 8) ? true : false;
		
	$(".prev").click(function(e){
		e.preventDefault();
		$(this).historyPrev();
	});

	$(".next").click(function(e){
		e.preventDefault();
		$(this).historyNext();
	});	
	
	$(document).keydown(function(e) {
		if ($(".history-item").length > 0) {
		    if (e.keyCode == 37) {
				$(this).historyPrev();
		    }
		    if (e.keyCode == 39) {
				$(this).historyNext();
		    }
		}
	});	
	
	$.fn.historyPrev = function() {
		// define items		
		var current = $(".current");
		if (current.prev(".history-item").length > 0) {
			var next = current.prev(".history-item");
		}
		// redefine if first item
		if (current.hasClass("first")) {
			var next = $(".last");
		}
		// do the change
		next.addClass("current").show();
		current.removeClass("current").hide();
	}
	
	$.fn.historyNext = function() {
		// define items		
		var current = $(".current");
		if (current.next(".history-item").length > 0) {
			var next = current.next(".history-item");
		}

		// redefine if last item
		if (current.hasClass("last")) {
			var next = $(".first");
		}
		next.addClass("current").show();
		current.removeClass("current").hide();
	}
	
	$(".prev").hover(function(){
		if ($(this).hasClass("prev-en")) {
			$(this).html("previous");
		} else {
			$(this).html("zurück");
		}
	}, function(){
		$(this).html('<img src="img/icon-prev.png" width="20" height="16" alt="" />');
	});

	$(".next").hover(function(){
		if ($(this).hasClass("next-en")) {
			$(this).html("next");
		} else {
			$(this).html("weiter");
		}
	}, function(){
		$(this).html('<img src="img/icon-next.png" width="20" height="16" alt="" />');
	});
	
	$.fn.preload = function() {
	    this.each(function(){
	        $('<img/>')[0].src = this;
	    });
	}
	
	$(['img/history-1.jpg',
	   'img/history-2.jpg',
	   'img/history-3.jpg',
	   'img/history-4.jpg',
	   'img/history-5.jpg',
	   'img/history-5.jpg',
	   'img/history-6.jpg',
	   'img/history-7.jpg',
	   'img/history-8.jpg',
	   'img/history-9.jpg']).preload();		
      
});

