// HeaderNews
var $j = jQuery.noConflict();
var position = 0;
var direction = -1;
var newsWidth = 280;
var newsCount = 8;

function moveHeaderNews() {
	//Richtungswechsel?
	if (position == 1-newsCount) {
		direction = 1;
	} else if (position == 0) {
		direction = -1;
	}
	$j('#homenews div').each(function(){	
		//Bewegen
		if (direction == -1 && position > 1-newsCount) {
			$j(this).animate({left:newsWidth*(position-1)+'px'},1000);
		}
		if (direction == 1 && position < 0) {
			$j(this).animate({left:newsWidth*(position+1)+'px'},1000);
		}
	});
	//Position setzen.
	if (position > 1-newsCount && direction == -1) {
		position--;
	}
	if (position < 0 && direction == 1) {
		position++;
	}
}

//cookie function
function setCookie(value) {
	var date = new Date();
	date.setTime(date.getTime()+(14*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	document.cookie = "fontsize="+value+expires+"; path=/";
}
function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

// Höhe von main und right setzen
jQuery.event.add(window, "load", resizeContent);
jQuery.event.add(window, "resize", resizeContent);

function resizeContent() 
{
    var h = $j(window).height();
    $j("#main").css('height', h - 168);
    $j("#right").css('height', h - 168);
}

// DOM ready function
$j(function(){
	//start HeaderNews
	window.setInterval('moveHeaderNews()',10000);
	
	$j("a[rel^=lightbox]").each(function() {
		bildurl = $j(this).attr("href");
		$j(this).addClass('thickbox').attr('rel','galery').attr("href", "http://motus.hotelfachschule-berlin.de/"+bildurl);	
	}) 
	
	$j("#suchfeld input.textfeld").attr("value", "suchen...").focus(function(){
		$j(this).attr("value","");
	});
	
	$j("#plus").click(function(){
		size = parseInt($j("body").css("font-size").replace(/px/,""));
		if (size < 23) {
			size++;
		}
		$j("body").css({fontSize : size+"px"});
		// store size in cookie
		setCookie(size);
		
	});
	$j("#minus").click(function(){
		size = parseInt($j("body").css("font-size").replace(/px/,""));
		if (size > 12) {
			size--;
		}
		$j("body").css({fontSize : size+"px"});
		// store size in cookie
		setCookie(size);
	});
	//load cookie, set style accordingly
	var size = readCookie("fontsize");
	if (size) {
		$j("body").css({fontSize : size+"px"}); 
	}
});
