/**
 * Environment
 * http://www.dotfly.de
 *
 * Copyright (c) 2009 Adrian Kirchner
 *
 * Date: 2009-09-01
 */


function Showcase() {
	
	this.screen =   { width : $(document).width(),
                      height: $(document).height() };

	this.dice =  	{ width: 83,
					  height: 80};
					  
	this.navList = 	{ width: 0,
					  height: 0};
					
	this.showElement = $('#productShowcase');
	
	this.showList = $('#productImgList');
	
	this.getEnvData();
	
	this.bindArrows();
	
	this.iPosition = 3;
}

Showcase.prototype =  {
	
	// Calculating Data for current screen setup
	getEnvData : function() {
		
		$_oSelfShow = this;
		
		iLeftPos = (this.screen.width / 2) - (527 / 2);
		
		$('div#productShowcase .arrow').css('opacity', 0.3);
		
		if( ! this.showElement.is(':visible')) {
			this.showElement.fadeIn(800);
		
		} else {
			//this.showElement.animate({left: iLeftPos}, 500, function() {
				$_oSelfShow.showElement.fadeIn(800);	
			//});
		}
		
		$('div#productShowcase').hover(function() {
			$('div#productShowcase .arrow').animate({'opacity': 1});			
		}, function() {
			$('div#productShowcase .arrow').animate({'opacity': 0.3});
		});
		
	},
	
	bindArrows : function() {
		
		
		$('#arLeft').unbind().click(function() { $_oSelfShow.moveRight() });
		$('#arRight').unbind().click(function() { $_oSelfShow.moveLeft() });
		
	},
	
	moveLeft : function() {
		
		this.iPosition += 1;
		
		if(this.iPosition == 4) {
			$('#arLeft').css('background-position', '0 -42px');
			this.showList.animate({marginLeft: "-=443px"}, 800);
		}
		else if(this.iPosition == 0) {
			$('#arLeft').css('background-position', '0 -42px');
			this.showList.animate({marginLeft: "-=443px"}, 800);
		}
		else if(this.iPosition == 6) {
			$('#arRight').css('background-position', '0 -84px');
			this.showList.animate({marginLeft: "-=443px"}, 800);
		}
		else if(this.iPosition == 7) {
			this.showList.animate({marginLeft: "0px"}, 800);
			$('#arRight').css('background-position', '-42px -42px');
			$('#arLeft').css('background-position', '-42px -84px');
			this.iPosition = 3;	
		}
		else {
			this.showList.animate({marginLeft: "-=443px"}, 800);
		}
		
		
	},
	
	moveRight : function() {
		
		this.iPosition -= 1;
		
		if(this.iPosition == 3) {
			$('#arLeft').css('background-position', '-42px -84px');
			$('#arRight').css('background-position', '-42px -42px');
			this.showList.animate({marginLeft: "+=443px"}, 800);
		}
		else if(this.iPosition == 2) {
			$('#arLeft').css('background-position', '0 -42px');
			$('#arRight').css('background-position', '0 -84px');
			this.showList.animate({marginLeft: "-1329px"}, 800);	
			this.iPosition = 6;
		}
		else {
			$('#arRight').css('background-position', '-42px -42px');
			this.showList.animate({marginLeft: "+=443px"}, 800);
		}
		
	}
	
}