/*
	Bildspelet
*/
$(document).ready(function(){
	var $start=false;
	var playSlideshow='';
	if($('#slider').attr('slider:start')==1){
	$('#headerContent').animate({height:400},600,function(){
		slideSwitch();
		playSlideshow=setInterval("slideSwitch()",3500);
		$('#hide').click(function(){clearInterval(playSlideshow);out();});
		$('a[target!=_blank][class!=ob]').click(function(ev){ev.preventDefault();var $self=$(this);$('#hide').hide(1);clearInterval(playSlideshow);$('#headerContent div').animate({opacity:0.0},300);$('#headerContent').animate({height:160},300,function(){document.location = $self.attr('href');});});
		$('#hide').fadeIn(400);
	});
	}else{$('#show').fadeIn(400);}
	$('#show').click(function(ev){
		ev.stopPropagation();
		if($start == true)return false;
		$start=true;
		//document.cookie = 'sa_slider=on; path=/'; //COOKIE
		$('#show').fadeOut(400);
		$('#headerContent').animate({height:400},600,function(){
			slideSwitch();
			playSlideshow=setInterval("slideSwitch()",3500);
			$('#hide').click(function(){clearInterval(playSlideshow);out();});
			$('a[target!=_blank]').click(function(ev){ev.preventDefault();var $self=$(this);$('#hide').hide(1);clearInterval(playSlideshow);$('#headerContent div').animate({opacity:0.0},300);$('#headerContent').animate({height:160},300,function(){document.location = $self.attr('href');});});
			$start=false;
			$('#hide').delay(200).fadeIn(400);
		});
	});
});
function slideSwitch() {
    var $active=$('#slider div.active');
    if($active.length==0)$active=$('#slider div:last');
	//var $next = $('#intro div:random');
    var $next =  $active.next('div').length ? $active.next('div') : $('#slider div:first');
	$active.addClass('last-active');
	/*$('#slider div.title').fadeOut(200,function(){
		if($next.attr('title'))$('#slider div.title').text($next.attr('title')).delay(800).fadeIn(1000);});*/
	$next.css({opacity:0.0})
		.addClass('active')
		.animate({opacity:1.0},1500,function(){
			$active.removeClass('active last-active');
		});
	
}
function out() {
    var $active=$('#slider div.active');
    if($active.length==0)$active=$('#slider div:last');
	$active.stop();
	$('#hide').fadeOut(400);
	//$('#slider div.title').fadeOut(400);
	$active.animate({opacity:0.0},1000,function(){
            $active.removeClass('active last-active');
			$('#headerContent').animate({height:160},600,function(){$('#show').fadeIn(400);});
			//document.cookie = 'sa_slider=off; path=/'; //COOKIE
        });
}
function createCookie(name,value,days){
	if(days){
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
/*
	Overlay Box
*/
$(document).ready(function(){
	$(document).keydown(function(e){
		if(e.keyCode == 27){
			if($('#obOverlay').length>0){
				obClose();
				return false;
			}
		}
	});
});
function loadContent(){
	var data = $("form").serialize();
	$("#obContent").html('<h3>Loading...</h3>');
	$("#obBox").addClass('obLoading');
	$.post("katalog2012.php",data,function(data){
		$("#obBox").removeClass('obLoading');
		$("#obContent").html(data);
		});
}
function obClose(){
	$("#obBox").fadeOut(200,function(){$("#obBox").remove()});
	$("#obOverlay").fadeOut(600,function(){$("#obOverlay").remove()});
}
function obOpen(){
	if($('#obOverlay').length>0)return;
	$("body").append('<div id="obOverlay">&nbsp;</div>');
	$("#obOverlay").hide().fadeIn(400);
	$("#obOverlay").click(function(e){e.preventDefault();obClose();});
	$("body").append('<div id="obBox"><a id="obClose" class="close" href="#" onclick="obClose();return false;">X</a><div id="obContent"></div></div>');
	$("#obBox").hide().fadeIn(200);
	loadContent();
}
