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


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

	this.dice =  	{ width: 83,
					  height: 80};
					  
	this.navList = 	{ width: 0,
					  height: 0};
					
	this.navElement = $('#mainNavList');
	
	//this.iDiceToAdd = 0;
	
	this.getEnvData();
	
	////this.arrangeDices();
	
	////$oShowcase = new Showcase;
}

Navigation.prototype =  {
	
	// Calculating Data for current screen setup
	getEnvData : function() {
		
		$iCntList = this.navElement.children('li').length;
		
		this.navList.width = $iCntList * this.dice.width + 3;
		
		this.iDiceToAdd = Math.floor((this.screen.width - this.navList.width) / this.dice.width);
		
	},
	
	arrangeDices : function() {
		
		iDicesSites = this.getSiteDiceCnt(false);
		
		if(iDicesSites.left > 0) {
			
			//$('#openingHours').after(this.getDiceMarkup(iDicesSites.left, 'left'));
			$('#logo').after(this.getDiceMarkup(iDicesSites.right, 'right'));
			
			this.transformAllDices();
			
		}
		else if(iDicesSites.left < 0) {
			
			iDicesSites = this.getSiteDiceCnt(true);
			
			iDicesSites.left *= -1;
			iDicesSites.right *= -1;
			
			for(i = 0; i < iDicesSites.left; i++) {
				
				$('#mainNavList .dir-left:last').addClass('to-delete').removeClass('dir-left');
				
			}
			
			for(i = 0; i < iDicesSites.right; i++) {
				
				$('#mainNavList .dir-right:last').addClass('to-delete').removeClass('dir-right');
				
			}
			
			this.hideDices();
			
		}
		
	},
	
	transformAllDices : function() {
		
		$_oSelf = this;
		
		$('#mainNavList .hidden-dice').animate({width: 80, marginRight: 3}, 500, function() {
			$_oSelf.displayDices();
		});
		
	},
	
	displayDices : function() {
		
		$_oSelf = this;
		
		$('#mainNavList .hidden-dice:first').css('opacity', 0).css('visibility', 'visible').animate({opacity : 1}, 35, function() {
			
			$(this).removeClass('hidden-dice').addClass('added-dice');
			
			$_oSelf.displayDices();
			
		});
		
	},
	
	hideDices : function() {
		
		$_oSelf = this;
		
		$('#mainNavList .to-delete').remove();
			
	},
	
	getSiteDiceCnt : function(oNegative) {
		
		iHalf = this.iDiceToAdd / 2;
		
		if( ! oNegative) {
			return {left: Math.floor(iHalf), right: Math.floor(this.iDiceToAdd)};
		}
		else {
			return {left: Math.ceil(iHalf), right: Math.floor(this.iDiceToAdd)};
		}
		
	},
	
	getDiceMarkup : function(iCnt, sDirection) {
		
		sReturnHtml = '';
		
		for(i = 0; i < iCnt; i++) {
			
			sReturnHtml += '<li class="hidden-dice dir-' + sDirection + '" style="visibility: hidden; width: 0; margin-right: 0;"></li>';
			
		}
		
		return sReturnHtml;
		
	}
	
}