$(document).ready(function() {
	if(String(window.location).split('#').length == 1 || window.location.hash=='#/' || window.location.hash==''){
		loadHome()
	}
});

function loadHome(){
	resetBackSwitching()
	//replaceItems	=	".HomeAnnouncement, .HomeTitle, .HomeDescription, .HomeUrlTekst";
	//Cufon.replace(replaceItems,{ fontFamily:'DIN'})//, onAfterReplace:onHomeLoaded});
	
	var $active = $('#active');
	if($active.length != 0){
		$('.HomeTitle .cufon-canvas').css({'height':'50px','marginTop':'-20px','marginBottom':'20px'})
		if(slideInterval == null){
			slideInterval	=	setInterval( "slideSwitch()", 5000 );
			var newbackground	=	'/_images/backimages_home/'+$('.HomeBlok#active').find('img').attr('id')+'.jpg'
			$('.img_Back').attr('src',newbackground)
		}else{
			clearInterval(slideInterval);
			slideSwitch()
			slideInterval	=	setInterval( "slideSwitch()", 5000 );
		}
	}
}

var replaced		=	0;
var replaceItems;

function onHomeLoaded(element,options){
	replaced++
	if(replaced==$(replaceItems).length){
		$('.HomeBlok:first').css({'display':'block'})
	}
}

var slideInterval;
function slideSwitch() {
	var $active = $currentBlok.find('#active');
	if($active.length == 0){
		clearInterval(slideInterval);
		slideInterval	= null;
		$active = $currentBlok.find('.HomeBlok:last');
	}

    var $next =  $active.next('.HomeBlok').length ? $active.next()
        : $currentBlok.find('.HomeBlok:first');
	
	$active.attr("id","last-active")
	
	if($next.length == 1){
		showSomeBackGround('/_images/backimages_home/'+$next.find('img').attr('id')+'.jpg')
	}
	
    $next.css({opacity: 0.0, 'display': 'block'})
    	.attr("id","active")
    	.animate({opacity: 1.0}, 1500, function() {
    		$active.removeClass('active last-active');
    		$active.attr("id","")
    	});
}
