// JavaScript Document
$(document).ready(function() {
	$('#fontControls').jfontsizer({
			applyTo: 'body',
			changesmall: '1',
			changelarge: '3',
			changedefault: '1.0',
			expire: 50
	});
	$('#slider ul').attr('id','uslider');
	$('#slider ul').attr('class','uslider');
	$('#uslider').uSlider();
	sliderpictitle();
});
$(function(){ 
	$('input[title!=""], textarea[title!=""]').hint();
});
function windowwidth() {
	var htmlwidth = $(document).width();
	var difference = (htmlwidth - 1024) / 2;
	if(difference <= 0) {
		$('td.contleft, td.contright').css('width', 0);
	}
	else {
		$('td.contleft, td.contright').css('width', difference);
	}
}
function windowheight() {
	$('td.contbottom').css('height', '0px');
	browser = navigator.userAgent;
	browser_ie7 = browser.indexOf("MSIE 7.0");
	if(browser_ie7 > -1) {
		var docheight = $('body').height();
	}
	else {
		var docheight = $(document).height();
	}
	var conttopheight = $('td.conttop').height();
	var contmiddleheight = $('td.contmiddle').height();
	var contbottomheight = $('td.contbottom').height();
	var withouttherest = conttopheight + contmiddleheight;
	var difference = docheight - withouttherest;
	if(difference <= contbottomheight) {
		$('td.contbottom').css('height', contbottomheight);
	}
	else {
		$('td.contbottom').css('height', difference);
	}
}
$(window).load(function() {
	windowwidth();
	windowheight();
});
$(window).resize(function() {
	windowwidth();
	windowheight();
});
$(function(){
	$('table.eraser').each(function(index) {
		$(this).attr('cellpadding','0');
		$(this).attr('cellspacing','0');
		$(this).attr('border','0');
	});
});
$(function(){
	var logoimgwidth = $('#logo img').width();
	$('#logo').css('width',logoimgwidth);
	var toplinkswidth = 765 - (logoimgwidth + 271);
	$('#toplinks').css('width',toplinkswidth);
	var nosunwidth = $('#nosun').width();
	var adresswidth = 1024 - (251 + nosunwidth);
	$('#adress').css('width',adresswidth);

});
$(function() {
	var anzahl = $('#sitemap ul');
	var maxanzahl = anzahl.length;
	z = 1;
	$('#sitemap ul').each(function(index) {
		if (z == maxanzahl) {
			$(this).attr('class','last');
		}
		else {
			z++;
		}
	});
});
$(function() {
	var anzahl = $('#content .news');
	var maxanzahl = anzahl.length;
	z = 1;
	$('#content .news').each(function(index) {
		if (z == maxanzahl) {
			$(this).attr('class','news last');
		}
		else {
			z++;
		}
	});
});
$(function() {
	z = 0;
	$('#content ul#offers li.offer').each(function(index) {
		if (z == 1) {
			$(this).attr('class','offer last');
			z = 0;
		}
		else {
			z++;
		}
	});
});
$(function() {
		   $('#content .news .box').evenHeight();
		   $('#content ul#offers .box').evenHeight();
});
function sliderpictitle() {
	$('#slider ul li img').each(function(index) {
		var titletext = this.title;
		var alttext = this.alt;
		if(titletext != "" || alttext != "") {
			$(this).parent().prepend('<div class="pictitle" style="display:none;"><h1>' + titletext + '</h1><p>' + alttext + '</p></div>');
		}
	});
	$('#slider ul > li:first-child').children('div.pictitle').css('display','');
}
$(function() {
	var anzahl = $('#icons img');
	var wert = 5;
	var iconanzahl = anzahl.length;
	var zeilen = iconanzahl / wert;
	var aufrunden = Math.ceil(zeilen).toFixed(0);
	var imgheight = $('#icons img:first-child').height();
	var zusatzwert = (aufrunden - 1) * 5;
	var rechnung = (imgheight * aufrunden) + zusatzwert;
	$('#icons').css('height',rechnung);
});
$(function() {
	$('ul#offers li.offer .box').each(function(index) {
		var wert = $(this).children('div:first').text();
		if(wert == '1') {
			$(this).children('p:first').css('display','block');
		}
	});
});
$(function() {
	var z = 0;
	var y = 0;
	totalheight = 0;
	$('ul.alben li').each(function(index) {
		if (z == 0) {
			$(this).attr('class','album first line' + y);
			z++;
			$('ul.alben li.line' + y + ' .albumname p').evenHeight();
		}
		else if (z == 1) {
			$(this).attr('class','album second line' + y);
			z++;
			$('ul.alben li.line' + y + ' .albumname p').evenHeight();
		}
		else if (z == 2) {
			$(this).attr('class','album last line' + y);
			z = 0;
			$('ul.alben li.line' + y + ' .albumname p').evenHeight();
			y++;
		}
	});
	for (x = 0; x <= y; x++) {
		totalheight = totalheight + $('ul.alben li.album.first.line' + x).height() + 7;
	}
	var listtag = $('ul.alben li.album.first');
	var listanzahl = listtag.length;
	var rechnung = totalheight;
	$('ul.alben').css('height',rechnung);
	$('ul.alben .albumname a').css('position','absolute');
	$('ul.alben .albumname a').css('bottom','0px');
});
$(function() {
	var z = 0;
	$('ul.gallery li').each(function(index) {
		if (z == 0) {
			$(this).attr('class','first');
			z++;
		}
		else if (z == 1) {
			$(this).attr('class','second');
			z++;
		}
		else if (z == 2) {
			$(this).attr('class','last');
			z = 0;
		}
	});
	var listtag = $('ul.gallery li.first');
	var listanzahl = listtag.length;
	var hoehe = $('ul.gallery li.first').height();
	var rechnung = (listanzahl * hoehe) + (7 * (listanzahl - 1)) + 7;
	$('ul.gallery').css('height',rechnung);
});
$(function() {
	var bildlink = $('.bgimage img').attr('src');
	$('body').css('background-image','url(' + bildlink + ')');
});

