
var height;
var width;
var subnavheight;
function browserDimensions() {
		if (Prototype.Browser.IE) {
            height = document.documentElement.clientHeight;
            width = document.documentElement.clientWidth;   
        } else {
            height = window.innerHeight;
            width = document.width || document.body.offsetWidth;
        }
	}

function setImgSize(imgheight, imgwidth) {
	
	
	
		var factor = imgheight/height;
		var newWd = Math.round(parseFloat(imgwidth/factor));
		var newHt = height;
	
	

	if (factor>1) {
		
		$('scalebild').setStyle({height:newHt+'px'});
		$('scalebild').setStyle({width:newWd+'px'});
	}
	
	
}


function setAllImgSizes(maxheight, anzimg, toppadding, padding){
	height=height-toppadding;
	var newWd;
	var newHt;
	var X=0;
	if(maxheight>height){
		var factor = maxheight/(height-20);
		
		if (factor>1) {
			for(i=0;i<anzimg;i++){
					
					newWd = Math.round(parseFloat($("display"+i).getStyle('width'))/factor);
					newHt = Math.round(parseFloat($("display"+i).getStyle('height'))/factor);
					
					//alert($("display"+i).getStyle('height'));
					$("display"+i).setStyle({height:newHt+'px'});
					$("display"+i).setStyle({width:newWd+'px'});
					//$("img"+i).setStyle({width:newWd+'px'});
					$("img"+i).setStyle({left:X+'px'});
					//alert(X);
					X=X + newWd+padding;
					
					
			}
			if($("backblock")){
				
				var pos=X-padding-20+230;
				$("backblock").setStyle({left:pos+'px'});
			}
		}
	}
}

function handleText(){
	//alert(height);
	subnavheight=height-300;
	if($('subnav')){
		if($('subnav').offsetHeight > subnavheight){
				$('subnav').setStyle({height:(subnavheight)+'px'});
				$('subnav').setStyle({overflow:'hidden'});
				$('slider_track').setStyle({height:subnavheight+'px'});
				$('slider_track').setStyle({visibility:'visible'}); 
				
		}
	}
	
}

/**
 * ADD/REMOVE PARAM URL
 * --------------------
 * class handling addition or removal of parameter to/from url
 */
var AlterUrl = Class.create();
AlterUrl.prototype = {
	initialize: function(currentUrl) {
		this.qs = {};
		this.filepath = '';
		var s = currentUrl.replace( /^\?|#.*$/g, '' );
		
		if (s) {
			var f = s.split('?');
			if (f[0]!=undefined && f[1]!=undefined) {
				this.filepath = f[0];
				var qsParts = f[1].split('&');
				var i, nv;
				for (i = 0; i < qsParts.length; i++) {
					nv = qsParts[i].split('=');
					this.qs[nv[0]] = nv[1];
					//alert(nv[0]);
				}
			}
		}
	},
	add: function(name, value) {
		if( arguments.length == 1 && arguments[0].constructor == Object ) {
			this.addMany( arguments[0] );
			return;
		}
		this.qs[name] = value;
	},
	remove: function(name) {
		if( arguments.length == 1 && arguments[0].constructor == Array ) {
			this.removeMany( arguments[0] );
			return;
		}
		delete this.qs[name];
	},
	readVar: function(name) { // returns value of variable
		return this.qs[name];
	},
	get: function() {
		var nv, q = [];
		for( nv in this.qs ) {
			q[q.length] = nv+'='+this.qs[nv];
		}
		return this.filepath + '?' + q.join( '&' );
	}
} // AlterUrl



/**
 * walks through all list elements and alters href attribute
 * by adding scrollpos parameter
 */
function alterSubNavUrls(listNodes, scrollY) {

	listNodes.each(function(item) { // 
		if (item.down('a')!=undefined) {
			var currentUrl = item.down('a').getAttribute('href');
			var au = new AlterUrl(currentUrl);
			au.remove('scrolly'); // prevent adding wpos parameter more than once
			au.add('scrolly', scrollY );
			item.down().setAttribute('href', au.get());
		} // if
	});

} // alterSubNavUrls()
