//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, filter:''}, 'fast');
}).livequery('mouseleave', function() {
	if(!$(this).hasClass('item_active'))
		$(this).animate( {opacity:0.5, filter:''}, 'slow');
}).livequery('click', function() {
	$('#menu_items img').removeClass("item_active");
	$(this).addClass("item_active");
	$('#menu_items img').not($(this)).animate( {opacity:0.5, filter:''}, 'slow');
	$(this).animate( {opacity:1.0, filter:''}, 'slow');
});

$('.main_content_fade').livequery('mouseenter', function() {
	$(this).animate( {opacity:1.0}, 'slow');
}).livequery('mouseleave', function() {
	$(this).animate( {opacity:0.5}, 'slow');
});

$('#content_map').livequery('mouseenter', function() {
	$(this).animate( {height:'460px'}, 'slow');
}).livequery('mouseleave', function() {
	$(this).animate( {height:'360px'}, 'slow');
}).livequery(function() {
	$(this).mosne_map({mode:'address', elements:'<div class="maplocation"><div class="infobox"><h2 class="name">SevenBit</h2><p class="address">Gibelstrasse 58b, CH-2540 Grenchen</p></div></div>'});
});

$('.content_thumbs').livequery(function() {
	$(this).thumbnailScroller({scrollerType:"hoverPrecise", scrollerOrientation:"horizontal", scrollSpeed:800, scrollEasing:"easeOutCirc", scrollEasingAmount:3600, acceleration:4, noScrollCenterSpace:10, autoScrolling:0, autoScrollingSpeed:2000, autoScrollingEasing:"easeInOutQuad", autoScrollingDelay:500});
});

$('.content_thumbs2').livequery(function() {
	$(this).thumbnailScroller({scrollerType:"hoverPrecise", scrollerOrientation:"horizontal", scrollSpeed:800, scrollEasing:"easeOutCirc", scrollEasingAmount:3600, acceleration:4, noScrollCenterSpace:10, autoScrolling:1, autoScrollingSpeed:4800, autoScrollingEasing:"linear", autoScrollingDelay:500});
});

$('*[title]').livequery(function(){
	$(this).qtip({position:{my: 'top center', at: 'bottom center'}, style:{tip: true, classes: 'ui-tooltip-shadow ui-tooltip-tipsy'}, show: {effect: function() { $(this).slideDown(300); }}, hide: {effect: function() { $(this).slideUp(150); }}});
});

//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() {
		$('#main_content').animate( { opacity:0.5, backgroundPosition:'(0px -100px)' }, 'slow');
		startLoading('#main_content_ajax', '3', 'blind', 'slow');
		startLoading('#main_content_submenu_ajax', '4', 'blind', 'slow');
	});

	if(getLoadState() == false) {
		$('#main_logo_ajax').hide('fade', function() {
			startLoading('#main_logo_ajax', '6', 'fade', 'slow');
		});
		$('#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');
		});
		$('#main_content_right_ajax').hide('fade', function() {
			startLoading('#main_content_right_ajax', '5', 'blind', 'slow');
		});
	}
	else {
		if(setType == 'load') {
			$('#main_content').css({backgroundPosition: "(0px 0px)"});
		}
		else if(setType == 'refresh') {
			$('#main_content_right_ajax').hide('blind', function() {
				startLoading('#main_content_right_ajax', '5', 'blind', 'slow');
				//startLoading('#main_content_right_submenu_ajax', '6', 'blind', 'slow');
			});
		}
		else if(setType == 'refresh2') {
		}
		refreshBoxContent('#main_header_ajax', '1');
	}
	$('#main_loadingbar_ajax').fadeIn('normal');
	function startLoading(getObject, site_content_id, setEffect, setDuration) {
		$(getObject).empty();
		if(getObject == '#main_content_ajax')
			$('#main_content').animate( { opacity:1.0, backgroundPosition:'(0px 100px)', filter:'' }, 'fast');
		$(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);
		if(getObject == '#main_content_ajax') {
			$('#main_content').animate( { opacity:1.0, backgroundPosition:'(0px 0px)', filter:'' }, 'slow');
			setTimeout(function() {$('#main_content_submenu').animate( { opacity:1.0, backgroundPosition:'(0px 0px)', filter:'' }, 'slow');}, 1500);
		}
	}
	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');
		}
	})
}
