$(document).ready(function(){
	var window_focus = true;
	$(window).focus(function() { window_focus = true; }).blur(function() { window_focus = false; });
	
	// GENERAL --------------------------------------------------------------------------
				
	$('.thuisbasis_rollover').mouseover(function(){$('.onze_thuisbasis').stop(true,false).fadeTo(300,0.2);});
	$('.thuisbasis_rollover').mouseout(function(){$('.onze_thuisbasis').stop(true,false).fadeTo(400,0);});
	$('.onze_thuisbasis').mouseover(function(){$(this).stop(true,false).delay(400).fadeTo(300,1);});
	$('.onze_thuisbasis').mouseout(function(){$(this).stop(true,false).fadeTo(400,0);});
	
	$('.social_link').mouseover(function(){$(this).stop(true,false).animate({marginTop: '-15px'}, 200);});
	$('.social_link').mouseout(function(){$(this).stop(true,false).animate({marginTop: '0px'}, 200);});
	
	var over_outline_open = 0;
	$('.logos').mouseover(function(){
		$('.logo_black').stop(true,false).fadeTo(200,1);
	});
	$('.logos').mouseout(function(){
		$('.logo_black').stop(true,false).fadeTo(200,0);
	});
	$('.logos').click(function(){
		showhide_overoutline();
	})
	
	function showhide_overoutline(){
		if (over_outline_open == 0){
			$('.overoutline').css('display','block');
			var oo_height = $('.overoutline').height();
			oo_height -= 10;
			$('.main').stop(true,false).animate({marginTop: oo_height+'px'},300);
			oo_height += 100;
			$('.social_link').stop(true,false).animate({marginTop: oo_height+'px'},300);
			over_outline_open = 1;
		}else{
			$('.main').stop(true,false).animate({marginTop: '0px'},300);
			$('.social_link').stop(true,false).animate({marginTop: '0px'},300);
			over_outline_open = 0;
		}
	}
	
	$('.footerlink').fadeTo(1,0.7);
	$('.footerlink').mouseover(function(){ $(this).stop(true,false).fadeTo(200,1); });
	$('.footerlink').mouseout(function(){ $(this).stop(true,false).fadeTo(200,0.7); });
	
	$('.fadelink').fadeTo(1,0.85);
	$('.fadelink').mouseover(function(){ $(this).stop(true,false).fadeTo(200,1); });
	$('.fadelink').mouseout(function(){ $(this).stop(true,false).fadeTo(200,0.85); });
	
	$('.bigbutton_red, .bigbutton_green').fadeTo(1,0.85);
	$('.bigbutton_red, .bigbutton_green').mouseover(function(){ $(this).stop(true,false).fadeTo(200,1); });
	$('.bigbutton_red, .bigbutton_green').mouseout(function(){ $(this).stop(true,false).fadeTo(200,0.85); });
			
	$('.rightmenu').fadeTo(1,0.85);
	$('.rightmenu').mouseover(function(){ $(this).stop(true,false).fadeTo(200,1); });
	$('.rightmenu').mouseout(function(){ $(this).stop(true,false).fadeTo(200,0.85); });
	
	$('.slides_img').fadeTo(1,0.6);
	$('.slides_img').mouseover(function(){ $(this).stop(true,false).fadeTo(200,1); });
	$('.slides_img').mouseout(function(){ $(this).stop(true,false).fadeTo(200,0.6); });
	
	// HOME --------------------------------------------------------------------------
				
	$('.home_acco_img').fadeTo(1,0.5);
	$('.home_acco_link').mouseover(function(){ $(this).children('.home_acco_img').stop(true,false).fadeTo(200,1); });
	$('.home_acco_link').mouseout(function(){ $(this).children('.home_acco_img').stop(true,false).fadeTo(200,0.5); });
	
	$('.slideshow_item').fadeTo(1,0.7);
	$('.slideshow_item').mouseover(function(){ $(this).stop(true,false).fadeTo(200,1); });
	$('.slideshow_item').mouseout(function(){ $(this).stop(true,false).fadeTo(200,0.7); });
	
	// HOME SLIDESHOW --------------------------------------------------------------------------
	
	var currpos = 0;
	var totalitems = $('.slideshow_item').size();
	var slideshow_over = 0;
	
	$('.slideshow_holder').everyTime(4500,function() { slideshow_next(); });
	$('.slideshow_holder').mouseover(function(){ slideshow_over = 1; });
	$('.slideshow_holder').mouseout(function(){ slideshow_over = 0; });
	
	function slideshow_next(){
		if ((!window_focus && $.browser.webkit) || slideshow_over == 1){
		}else{
			var nextpos = currpos+1;
			if (nextpos > (totalitems-1)){ nextpos = 0; }
			var newright = nextpos*410*(-1);
			$('.slideshow_holder').animate({left:newright}, {duration: 1000, easing: "easeOutQuint"});
			currpos = nextpos;
		}
	}
			
	// JIRICNA --------------------------------------------------------------------------
	
	$('.j_img').fadeTo(1,0);
	$('.j_img').mouseover(function(){
		$('.j_img').stop(true,false).fadeTo(500,0);
		$('.j_plan').stop(true,false).fadeTo(500,0.3);
		$(this).stop(true,false).fadeTo(500,1);
		
		var id = $(this).attr('id');
		var position = $(this).position();
		var wd = $(this).width();
		var newx = (position.left+(wd/2)-155);
		var newy = (position.top-240);
		$('.j_popup:eq('+id+')').stop(true,false).css('left',newx+'px').css('top',newy+'px').css('display','block').fadeTo(1,0).stop(true,true).css('z-index',(zindex+100)).delay(100).animate({opacity: 1, top:'-=10'}, 500);			
	});
	$('.j_img').mouseout(function(){
		$('.j_plan').stop(true,false).fadeTo(500,1);
		$('.j_img').stop(true,false).fadeTo(500,0);
		
		var id = $(this).attr('id');
		var position = $(this).position();
		$('.j_popup:eq('+id+')').stop(true,false).animate({opacity: 0, top:'-=10'}, 500, function() { $(this).css('display','none'); });	
	});
});

// JIRICNA SLIDESHOW --------------------------------------------------------------------------

var currentimage = 0;
var zindex = 101;
setInterval ("nextimage()", 5500);

function nextimage(){
	var totalitems = $('.img_slide').size();
	
	var newimage = currentimage+1;
	if (newimage >= totalitems){
		newimage = 0;
	}
	$('.img_slide:eq('+newimage+')').fadeTo(1,0).stop(true,true).css('z-index',zindex).fadeTo(1000,1);
	zindex++;
	$('.jiricna_slideshow_info').css('z-index',zindex);
	zindex++;
	currentimage = newimage;
}
