/*
* Resize Background Image
*/
var bgImageRatio = 0;

$(document).ready(function(){
	
	//set image ration if bg image is loaded
	$("#imgBg").load(function() {
		bgImageRatio = $(this).width() / $(this).height();
		resizeBgImage();
		$(window).resize(resizeBgImage);
		$(this).css('visibility','visible');
	});										 
														 
});

function resizeBgImage(){
	var img = $('#imgBg');
	
	var dh = $(window).height();
	var dw = $(window).width();
	
	if(bgImageRatio > dw/dh){
		$(img).css('width','');
		$(img).css('height',dh + 'px');	
	}
	else {
		$(img).css('height','');
		$(img).css('width',dw + 'px');
	}
}









/*
* NAVIGATION
*/


function CNavigation(){
	var that = this;
	
	//init navigation entries
	var imgs = document.getElementsByTagName('img');
	for(var i=0;i<imgs.length;++i){
		var img = imgs[i];
		var id = img.id;
		
		if(id.indexOf('nav')!=0){
			continue;
		}
		
		img.imgLo = new Image();
		img.imgHi = new Image();
		
		img.imgLo.src = img.src;
		img.imgHi.src = img.src.replace('_lo','_hi');
		
		img.hi = function(){
			if(!this.locked)
				this.src = this.imgHi.src;
		}
		img.lo = function(){
			if(!this.locked)
				this.src = this.imgLo.src;
		}	
		
		//attache events
		$("#"+id).hover(img.hi,img.lo);
		$("#"+id).click(function(){
			if(that.active){
				that.active.locked = false;
				that.active.lo();
			}
			
			this.hi();					
			this.locked = true;
			that.active = this;	
			$('#divCnt').css('visibility','visible');
		});
		
		img.parentNode.img = img;
		
		img.locked = false;
		img.lo();
		
	}
}

CNavigation.prototype = {
	
	//set navigation
	set:function(_url){
		if(this.active){
			this.active.locked = false;
			this.active.lo();
		}
		
		var as = document.getElementsByTagName('a');
		for(var i=0;i<as.length;++i){
			var a = as[i];
			if(a.href.indexOf(_url) > -1){
				var img = a.img;
				
				if(this.active){
					this.active.locked = false;
					this.active.lo();
				}
				
				img.hi();		
				img.locked = true;			
				this.active = img;	
			}
		}
	}
};








