function Magazin(){
	
	var current_image = 0;
	var images = new Array();
	var image_sources = new Array();

    this.init = function(){
    	(function($) {
			if ($('#magazin')) {
				images = $('#magazin > div');
				self.showArrows();
				magazin.preload();
			}
    	})(jQuery);
    }
	
	this.showArrows = function(){
		(function($) {
			
			if (images.length > 1) {
				$('#arrowLeft').css('display', "block");
				$('#pageArrowLeft').css('display', "block");
				$('#arrowRight').css('display', "block");
				$('#pageArrowRight').css('display', "block");
			}
			else {
				$('#arrowLeft').css('display', "none");
				$('#pageArrowLeft').css('display', "none");
				$('#arrowRight').css('display', "none");
				$('#pageArrowRight').css('display', "none");
			}
			
			/*
			if (current_image > 0) {
				$('#arrowLeft').css('display', "block");
				$('#pageArrowLeft').css('display', "block");
			}
			else {
				$('#arrowLeft').css('display', "none");
				$('#pageArrowLeft').css('display', "none");
			}
			
			if (current_image < images.length - 1) {
				$('#arrowRight').css('display', "block");
				$('#pageArrowRight').css('display', "block");
			}
			else {
				$('#arrowRight').css('display', "none");
				$('#pageArrowRight').css('display', "none");
			}
			*/
			
		})(jQuery);
	}
    
	this.showNext = function(){
		(function($) {

			if ($.browser.msie) 
			$(images[current_image]).css('display', "none");
			else 
			$(images[current_image]).fadeOut();
			
			if(current_image < images.length - 1)
				current_image++;
			else 
				current_image = 0;
			
			
			if ($.browser.msie) 
			$(images[current_image]).css('display', "block");
			else 
			$(images[current_image]).fadeIn();
			
						
			magazin.preload();
			magazin.showArrows();
			
			//alert(current_image);
			
		})(jQuery);
	}
	
	this.showPrevious = function(){
		(function($) {
			if ($.browser.msie) 
			$(images[current_image]).css('display', "none");
			else 
			$(images[current_image]).fadeOut();
			
			
			if(current_image > 0)
				current_image--;
			else 
				current_image = images.length - 1;
		
			if ($.browser.msie) 
			$(images[current_image]).css('display', "block");
			else 
			$(images[current_image]).fadeIn();
			
			//alert(current_image);
			
			magazin.preload();
			magazin.showArrows();
			
		})(jQuery);
	}
	
	this.preload = function(){
		// current
		if(images[current_image])
		$('#'+ images[current_image].id + ' img')[0].src = image_sources[current_image];
		
		if(current_image < images.length - 2)
		$('#'+ images[current_image + 2].id + ' img')[0].src = image_sources[current_image + 2];
		
		if(current_image < images.length - 1)
		$('#'+ images[current_image + 1].id + ' img')[0].src = image_sources[current_image + 1];
	} 
	
	this.setImageSources = function(is){
		image_sources = is;
	}
	
	this.goToPage = function(PageNr){
		(function($) {
			if(PageNr < images.length){
				if ($.browser.msie) 
				$(images[current_image]).css('display', "none");
				else 
				$(images[current_image]).fadeOut();
				
				current_image = PageNr;
				
				if ($.browser.msie) 
				$(images[current_image]).css('display', "block");
				else 
				$(images[current_image]).fadeIn();
				
							
				magazin.preload();
				magazin.showArrows();
				
				//console.log(current_image);
			}
		})(jQuery);
	}

    var self = this;
}

var magazin = new Magazin();


(function($) {
	$(document).ready(function(){
		magazin.init();
	});

})(jQuery);
