var mySite = {
	
	curpage : '',
	curtext : '',
	curEl : '',
	pageWidth : 900,
	hiddenEls : ['h2','h3','ul','ol','p','table','form','embed','iframe','.biopics','blockquote','#bio-instruct','img.commentpic','div.slider1','div.indicator','#comments-next', 'div.comment'],
	spos: [950,2350,3400,4400,5400,6400,7330],
	// beware of upper / lower case in next line!
	nlinks : ['Das KulturWerk', 'Projekte 2008', 'Projekt 2009', 'Home', 'Projekt 2010', 'Buchung', 'Kontakt'],
	pages : ['kwg','proj2008','proj2009','Home','proj2010','order','contact'],
	currentComment : 0,
	innerFadeSettings : '',
	innerFadeElements : '',
	innerFadeCurrent : '',
	innerFadeLast : '',
	
	
	weekButtonsLocked : 0,
	leftpos : 0,
	topLogo : '/images/KWG_logo_trans.gif',
	
		
	elList : function ( parent )
	{
		var string = [];
		var he = mySite.hiddenEls;
		
		for (var i = 0, n = he.length; i < n; i++) {
			string.push(parent + ' ' + he[i]);
		}
		return string.join(', ');
	},

	changePage : function()
	{		
//		$('#imprtext').hide();
		$('#impressum a').show();
		
		var nav = $(this).attr('title') == 'Home' ? $('#n-home a') : $(this);
		var idx = mySite.nlinks.indexOf(nav.attr('innerHTML'));
		var p = mySite.pages[idx];
		var Win = getSize();
		var slide = -(mySite.spos[idx] - (Win.width/2));
		var cp = mySite.curpage;
		
//		if (cp != '') $('#' + cp.attr('innerHTML').toLowerCase() + ' .hiddenEl').hide();
//		$('#' + p.toLowerCase() + ' .hiddenEl').show();

		$('#content').animate({left: slide}, 1000);
		mySite.idx = idx;

		nav.addClass('cur');		
		if (cp != '' ) cp.removeClass('cur');
		mySite.curpage = nav;
		return false;
	},
	
	changeFrame : function()
	{
		var nav2 = $(this);
		var curt = mySite.curtext;
		mySite.curtext = nav2.addClass('cur2');
		if (curt != '') curt.removeClass('cur2');
	},
	
	showImpressum : function()
	{
		$('#imprtext').show();
		$('#impressum a').hide();
		return false;
	},

	build : function()
	{
		$(mySite.elList('div.block')).addClass('hiddenEl');
		
		$('div.block .hiddenEl').hide();
		$('#home .hiddenEl').show();
		$('body, div.block').css('overflow','hidden');
		$('#imprtext').hide();

		mySite.curpage = $('#n-home a').addClass('cur');
		mySite.curtext = $('#n2-hintergrund').addClass('cur2');


		var nav = $('#n-home a');
		var Win = getSize();
		var slide = -(mySite.spos[mySite.nlinks.indexOf('Home')] - (Win.width/2));
		
		// Cache positions and DOM elements
		mySite.leftpos = slide;
		
		$('#content').css({'left': slide + 'px'});
		
		// Event handlers:
		$('#nav a').click(mySite.changePage);
		$('#nav2 a').click(mySite.changeFrame);
//		$('#impressum a').click(mySite.showImpressum);

		$(window).resize(function(){
			var Win = getSize();
			var slide = -(mySite.spos[mySite.idx] - (Win.width/2));
//			var slide = (mySite.leftpos - (Win.width/2));

			$('#content').animate({left: slide}, 100);

			mySite.leftpos = slide;

		});
	}
}



$('a').click(function(){
	this.blur();
});

Array.prototype.indexOf = function( v, b, s ) {
	for( var i = +b || 0, l = this.length; i < l; i++ ) {
		if( this[i]===v || s && this[i]==v ) { return i; }
 	}
 	return -1;
};

function getSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
	myWidth = window.innerWidth;
	myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
  }
  return {width: myWidth, height: myHeight};
}

$(document).ready(function() {
	mySite.build();
});


var bgsleight	= function() {
	
	function addLoadEvent(func) {
		$(document).ready(function() {
			func();
		});
	}
	

	return {
		
		init: function() {
			
		}
	}
	
}();

bgsleight.init();
