// JavaScript Document

var bg = new function() {
	
	this.currmainnav = null;
	this.currtopnav = null;
	this.currtopnavid = null;
	
	this.currsubnav = null;
	this.currsubnavid = null;
	
	this.init = function() {
		
	}
	
	this.initmainnav = function() {
		$(".mainnavbutton").each(function(i) {
			//alert(this);
			$(this).data("imgstd",$(this).attr("src"));
			$(this).mouseover(function (i){
				$(this).attr("src",$(this).data("imgstd").replace(/\.gif/,"_o.gif"));
			});
			$(this).mouseout(function (i){
				if (bg.currmainnav != this) {
					$(this).attr("src",$(this).data("imgstd"));
				}
			});	
		});		
	}
	
	this.setmainnav = function(nr) {
			bg.currmainnav = $(".mainnavbutton")[nr];
			$(bg.currmainnav).attr("src",$(bg.currmainnav).data("imgstd").replace(/\.gif/,"_o.gif"));
	}
	
	
	this.createtopnav = function(nr) {
		var tempelem;
		for (var i=0; i< pic_topnav[nr].length; i++) {
			tempelem = $("<img />");
			tempelem.attr("src",pic_topnav_path+pic_topnav[nr][i][1]);
			tempelem.addClass("topnaviimage");
			tempelem.data("imgover",pic_topnav_path+pic_topnav[nr][i][1]);
			//tempelem.data("imgnorm",pic_topnav_path+pic_topnav[nr][i][0]);
			tempelem.data("mid",nr);
			tempelem.data("sid",i);
			tempelem.data("text",pic_topnav[nr][i][2]);
			tempelem.css( {opacity:0.5} ) 
			tempelem.mouseover(function (i){
				$(this).animate({opacity:1});
				//$(this).attr("src",$(this).data("imgover"));
			});
			tempelem.mouseout(function (i){
				if (bg.currtopnavid != $(this).data("sid")) {
					$(this).animate({opacity:.5});
				}
				//$(this).attr("src",$(this).data("imgnorm"));
			});
			tempelem.click(function(i) {
				if (bg.currtopnavid != $(this).data("sid")) {
					$(bg.currtopnav).animate({opacity:.5});
					$("#bigimagetext").html($(this).data("text"));
					bg.setmainimage(pic_cont[$(this).data("mid")][$(this).data("sid")][0][1]);
					bg.createsubnavigation($(this).data("mid"),$(this).data("sid"));
					bg.currtopnav = $(this);
					bg.currtopnavid = $(this).data("sid");
				}
			});
			if (i==0) {
				$("#bigimagetext").html(tempelem.data("text"));
				bg.setmainimage(pic_cont[tempelem.data("mid")][tempelem.data("sid")][0][1]);
				bg.createsubnavigation(tempelem.data("mid"),tempelem.data("sid"));
				bg.currtopnav = tempelem;
				bg.currtopnavid = 0;
				$(bg.currtopnav).animate({opacity:1});
			}
			tempelem.appendTo($("#topnavigation"));
		}
		
		
		
	}
	
	this.createsubnavigation = function(mid,sid) {
		var tempelem;
		$("#subnavigation").html("");
		for (var i=0; i< pic_cont[mid][sid].length; i++) {
			tempelem = $("<img />");
			tempelem.attr("src",pic_cont_path+pic_cont[mid][sid][i][0]);
			tempelem.data("mainimg",pic_cont[mid][sid][i][1]);
			tempelem.addClass("subnaviimage");
			tempelem.click(function(i) {
				bg.setmainimage($(this).data("mainimg"));				
			});
			tempelem.appendTo($("#subnavigation"));
		}
	}
	
	this.setmainimage = function(src) {
		var tempelem;
		tempelem = $("<img />");
		tempelem.attr("src",pic_cont_path+src);
		$("#bigimage").html("");
		tempelem.appendTo($("#bigimage"));
		tempelem.css({width:"auto",height:"auto"});
	}


}
