/* call jquery onload */
$(document).ready(function(){
	// class switch on hover
	$("#nav_ul li").hover(function(){
		$(this).children("ul").css({"display":"block"});        
	}, function(){
		$(this).children("ul").css({"display":"none"});        
	});
	
	// png fix
	$("body").pngFix( );
	
	// fade in content image
	$("#content_img").fadeIn(1000);

	// set container
	var bodyMiddle = ( $('body').width() - $('#container').width() ) / 2;
	var bodyHeight = $(document).height();
	$('#container').css({'margin-left': bodyMiddle + 'px'});
	createCookie('container_left',$("#container").css("margin-left"),7);

	// images change news navigation
	$("#first, #next, #prev, #text_video img").hover(
	 function(){ this.src = this.src.replace("_off","_on"); },
	 function(){ this.src = this.src.replace("_on","_off");}
	);
	// scroll news
	$('#news_nav #first').click(function() { scroll('first', '#news_ul', '#news', 337); });
	$('#news_nav #next').click(function() { scroll('right', '#news_ul', '#news', 337); });
	$('#news_nav #prev').click(function() { scroll('left', '#news_ul', '#news', 337); });

	$('#text_nav #first').click(function() { scroll('first', '#text_ul', '#text', 315); });
	$('#text_nav #next').click(function() { scroll('right', '#text_ul', '#text', 315); });
	$('#text_nav #prev').click(function() { scroll('left', '#text_ul', '#text', 315); });
		
	$("#nav_ul li").hover(function(){
		if($(this).attr('id').search('_current') == -1){
			$(this).removeClass($(this).attr("id"));
			$(this).addClass($(this).attr("id") + '_current');
		}
	}, function (){
		if($(this).attr('id').search('_active') == -1){
			$(this).removeClass($(this).attr("id") + '_current');
			$(this).addClass($(this).attr("id"));
		}          
	});
	$(".sub").hover(function(){
		if($(this).attr('id').search('_current') == -1){
			$(this).removeClass();
			$(this).addClass('sub_current');
		}
	}, function (){
		if($(this).attr('id').search('_active') == -1){
			$(this).removeClass();
			$(this).addClass('sub');
		}          
	});
	$(".last").hover(function(){
		if($(this).attr('id').search('_current') == -1){
			$(this).removeClass();
			$(this).addClass('last_current');
		}
	}, function (){
		if($(this).attr('id').search('_active') == -1){
			$(this).removeClass();
			$(this).addClass('last');
		}          
	});
	$("#portfolio").innerfade({ speed: 1000, timeout: 4000, type: "sequence", containerheight: "316px" }); 
	$("#text_video, #content_img_video, #content_video_box, #content_video_close").click(function(){
		if($("#content_video_box").css("display") == "none"){
			$("#content_video_box").show();
			$("#content_video").show();
			$("#content_img_video").hide();
		} else {
			$("#content_video_box").hide();
			$("#content_video").hide();
			$("#content_img_video").show();
		}
	});
	// fade in content image
	$("#content_title").fadeIn(1000);
	$("#subscribe_box .unsubscribe").click(function(){
		$("#subscribe_box .unsubscribe").css({"background-image":"url(/images/template/radio_on.gif)"});
		$("#subscribe_box .subscribe").css({"background-image":"url(/images/template/radio_off.gif)"});
		$("#subscribe_btn").attr('value', 'afmelden');

	});
	$("#subscribe_box .subscribe").click(function(){
		$("#subscribe_box .unsubscribe").css({"background-image":"url(/images/template/radio_off.gif)"});
		$("#subscribe_box .subscribe").css({"background-image":"url(/images/template/radio_on.gif)"});
		$("#subscribe_btn").attr('value', 'aanmelden');
	});
}); 

$(window).bind('resize', function(){
	// set swirl and container
	var bodyMiddle = ( $('body').width() - $('#container').width() ) / 2;
	var bodyHeight = $(document).height();
	$('#container').css({'margin-left': bodyMiddle + 'px'});
	createCookie('container_left',$("#container").css("margin-left"),7);
	// bgiframe
	$("li").bgiframe();
});

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=/";
}

function scroll(DIR, ID, IDC, scrollSpeed) {
	var col_left = $(ID).css("left").replace('px','');	
	if(DIR == 'left'){
		if( col_left < 0 ){ 
			col_left = parseInt( col_left );
			$(ID).animate({left:'+='+scrollSpeed+'px' }, { duration: 500, queue: false });
			$("#next").show();
		} else {
			$(ID).animate({left:'0px' }, { duration: 500, queue: false });
		}
	}
	if(DIR == 'right'){
		col_left = parseInt( col_left.replace('-','') );
		if( col_left <  ( $(ID).innerWidth() - $(IDC).innerWidth() - scrollSpeed ) ){ 
			$(ID).animate({left:'-='+scrollSpeed+'px' }, "fast");
			$("#first").show();
			$("#prev").show();
		}
	}
	if(DIR == 'first'){
		$(ID).animate({left:'0px' }, "fast");
		$("#next").show();
	}
	if( ( col_left + scrollSpeed )  >  ( $(ID).innerWidth() - $(IDC).innerWidth() - scrollSpeed ) ){ 
		$("#next").hide();
	}
	
	//col_left = parseInt( col_left.replace('-','') );
	if(  col_left == ( 0 - scrollSpeed ) ){ 
		$("#first").hide();
		$("#prev").hide();
	}
};
