
var host = "http://" + document.location.host;
var path = "/web/";
var baseURL = host + path; 


var _anchor = "";
var _tab	= "";


$(document).ready(function(){
	
	Galleria.loadTheme('js/galleria/themes/classic/galleria.classic.js');
	$("#galleria").galleria({
		image_crop: false,
		transition: 'flash',
		data_config: function(img) {
			return {
				description: $(img).next('p').html()
			};
		}
	});
	
	
	globalBehaviour();
	newsSlider();
	
	// *****************************************
	// GLOBAL BEHAVOIR FOR ALL PAGES ON LOAD
	// *****************************************
		
	function globalBehaviour(){
	$("a[rel^='prettyPhoto']").prettyPhoto();
					

	// *****************************************
	// ONLOAD BEHAVIOUR
	// *****************************************
	$('.sf-menu').superfish({
		animation: { opacity:'show',height:'show' },
		delay: 0,
		speed: 'fast'
		
	});

		newsSlider();
		

		
		// HEADLINES
		$('.headline h1').css('top','0px');

		// TOGGLE PANELS
		$('.closePanel').toggle(
			function(){
				$(this).html('Info zeigen');
				$(this).parent().find('.panel').slideUp('fast');
			},
			function(){
				$(this).html('Schliessen');
				$(this).parent().find('.panel').slideDown('fast');
			}			
		);
		
		// BUTTONS
		$('.readmore').hover(
			function(){
				$(this).find('.arrow_right').stop().animate({'left':'20px'}, {duration:200});
				$(this).find('a').stop().animate({'paddingLeft':'10px'}, {duration:200});
			},
			function(){
				$(this).find('.arrow_right').stop().animate({'left':'8px'}, {duration:200});
				$(this).find('a').stop().animate({'paddingLeft':'3px'}, {duration:200});
			}
		);
		
		Cufon.replace('.sf-menu a', {fontFamily:'Asphaltum WF'});
		Cufon.replace('h1', { fontFamily: 'BigDots'});
		Cufon.replace('h2', { fontFamily: 'BigDots'});
		Cufon.replace('.nl_text h3', { fontFamily: 'BigDots'});	
		Cufon.replace('.win_question', {fontFamily:'Asphaltum WF'});

	}
	
	function dialogBehaviour(){
		$('#dialog_link').click(function(){
			$("#dialog[rel^='"+$(this).attr('rel')+"']").dialog('open');
			return false;
		});		
		
		$('#dialog').each(function(){
			$(this).dialog({
				autoOpen: false,
				width: 600,
				buttons: {
					"Schliessen": function() { 
						$(this).dialog("close"); 
					}
				},
				modal: true
			});
		});/*	*/
	}
	
	function accordionBehaviour(){
		$("#accordion").accordion({
			header: ".accordion-header",
			autoHeight: false
		});
	}
	
	function gotoTab(tab){
		//$('.'+tab).slideDown('fast');
		
	}

	/* ************************************************************************************************************************************ */
	/* AJAX PAGE LOADING 				 				 				 				 				 				 					*/
	/* ************************************************************************************************************************************ */

	function getScrollXY() {
		var scrOfX = 0, scrOfY = 0;
		if( typeof( window.pageYOffset ) == 'number' ) {
			//Netscape compliant
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
		} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			//DOM compliant
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			//IE6 standards compliant mode
			scrOfY = document.documentElement.scrollTop;
			scrOfX = document.documentElement.scrollLeft;
		}
		return [ scrOfX, scrOfY ];
	}


	function loadContent(targetPage){

		$.ajax({
			url: targetPage + '.php' + "?ajax=true",
			type:"POST",
			data:"test=1&test2=2",
			context: $('.container100x100'), 
			success: 
				function($content){
					// PAGE REFRESH
					if(currentPage == targetPage || currentPage == ''){
						$('.container100x100').css('opacity',0);
						$('.container100x100').html($content);
						$('.container100x100').animate({'opacity':1},{duration:200, 'complete':function(){}});
						currentPage = targetPage;
						gotoAnchor();
						globalBehaviour();
					}
					else{
						$('.container100x100').append($content);
						currentPage = targetPage;
						switchContent(targetPage);
					}
				}
			});
	}
});

