//handler functions
$('.nav').livequery('click', function() {
	loadContent($(this).attr('href').substring($(this).attr('href').indexOf('?')+1), 'refresh');
	return false;
});

$('.nav2').livequery('click', function() {
	loadContent($(this).attr('href').substring($(this).attr('href').indexOf('?')+1), 'refresh');
	return false;
});

$('.nav3').livequery('click', function() {
	loadContent($(this).attr('href').substring($(this).attr('href').indexOf('?')+1), 'refresh2');
	return false;
});

$('#menu_items img').livequery('mouseenter', function() {
	$(this).animate( {opacity:1.0}, 'fast');
}).livequery('mouseleave', function() {
	if(!$(this).hasClass('item_active'))
		$(this).animate( {opacity:0.5}, 'slow');
}).livequery('click', function() {
	$('#menu_items img').removeClass("item_active");
	$(this).addClass("item_active");
	$('#menu_items img').not($(this)).animate( {opacity:0.5}, 'slow');
	$(this).animate( {opacity:1.0}, 'slow');
});

$('.kwicks').livequery(function() {
    $(this).kwicks({  
        max : 175,  
        spacing : 0  
    });  
});

$('#main_searchfield input').livequery('keyup', function() {
	if($(this).length == 0)
		$('#main_searchfield .searchfield_box').hide();
	else
		$.post("include/ajaxGetData.inc.php?site_content_id=7", {searchfield: ""+$(this).val()+""}, function(data){ if(data.length >0) $('#main_searchfield .searchfield_box').show(); $('#main_searchfield .searchfield_box div').html(data); });
});
	
$('#main_searchfield input').livequery('blur', function() {
		$(this).val();
		setTimeout("$('#main_searchfield .searchfield_box').hide();", 200);
});

$('#content_map').livequery('mouseenter', function() {
	$(this).animate( {height:'320px'}, 'slow');
}).livequery('mouseleave', function() {
	$(this).animate( {height:'220px'}, 'slow');
}).livequery(function() { 
	setTimeout(function() {
		$('#content_map').mosne_map({mode:'address', elements:'<div class="maplocation"><div class="infobox"><h2 class="name">Femobau GmbH</h2><p class="address">M&#252;hlestrasse 50, CH-2504 Biel/Bienne</p></div></div>'});
	;}, 300);
});

$('*[title]').livequery(function(){
	$(this).tipTip({edgeOffset:7, delay:150, fadeIn:600});
});

//load functions
function setLoadState(bool) {
	loadState = bool;
}

function getLoadState() {
	return loadState;
}

setLoadState(false);

function changeImage(getObject, setValue, setType) {
	if(setType == undefined)
		setType = 'background';
	if(setType == 'background') {
		if ($(getObject).css('background-image') != "url(\"http://"+document.domain+"/images/"+setValue+"\")"){
			$(getObject).animate({opacity: 0}, 'normal', function() {
				$(this).css({'background-image': 'url(images/'+setValue+')'}).animate({opacity: 1});
			});
		}
	}
}

function loadContent(setValue, setType) {
	if(setType == undefined)
		setType = 'load';
	$('#main_content_ajax').hide('blind', function() {
		startLoading('#main_content_ajax', '3', 'blind', 'slow');
	});
	if(getLoadState() == false) {
		$('#main_header_ajax').hide('fade', function() {
			startLoading('#main_header_ajax', '1', 'fade', 'slow');
		});
		$('#main_menu_ajax').hide('fade', function() {
			startLoading('#main_menu_ajax', '2', 'fade', 'slow');
		});
	}
	else {
		if(setType == 'load') {

		}
		else if(setType == 'refresh') {

		}
		else if(setType == 'refresh2') {
		
		}
		refreshBoxContent('#main_header_ajax', '1');
	}
	$('#main_loadingbar_ajax').fadeIn('normal');
	function startLoading(getObject, site_content_id, setEffect, setDuration) {
		$(getObject).empty();
		$(getObject).load('include/ajaxGetData.inc.php?site_content_id='+site_content_id+'&'+setValue, '', loadBoxContent(getObject, setEffect, setDuration));  
	}  
	function loadBoxContent(getObject, setEffect, setDuration) {  
		setTimeout(function() {$(getObject).show(setEffect, setDuration, finishLoading());}, 400);
	}  
	function finishLoading() {  
		$('#main_loadingbar_ajax').fadeOut('normal');
	}
	function refreshBoxContent(getObject, site_content_id) {
		$(getObject).load('include/ajaxGetData.inc.php?site_content_id='+site_content_id+'&'+setValue, '');	
	} 	
}

//toggle functions
function toggleElement(getObject, setValue) {
	if(setValue == 'show')
		$(getObject).show();
	if(setValue == 'hide')
		$(getObject).hide();
	if(setValue == 'toggle')
		$(getObject).slideToggle('normal');
}

function toggleGroup(getObject, setValue, getObject2) {
	$("div[id^='hidden']").each(function(index) {
		if(getObject+''+index != getObject2) {
			if(setValue == 'show')
				$(this).show('normal');
			if(setValue == 'hide')
				$(this).hide('normal');
			if(setValue == 'toggle')
				$(this).slideToggle('normal');
		}
	})
}
