
		$(function() {

			initializeDebug();

			$("#footer").hide();
			$("#background2").hide();
			$("#logo").hide();

			$("#content").addClass("defaultLayer");
			
			$("#panel1").addClass("defaultLayer");
			$("#panel2").addClass("defaultLayer");
			$("#menu").addClass("defaultLayer");
			$("#logo").addClass("defaultLayer");
			$("#langnav").addClass("defaultLayer");
			$("#menutitle").addClass("defaultLayer");

			
			$("#content").draggable(globaldragevent);
			
			$("#panel1").draggable(globaldragevent);
			$("#panel2").draggable(globaldragevent);
			$("#menu").draggable(globaldragevent);
			$("#logo").draggable(globaldragevent);
			$("#langnav").draggable(globaldragevent);


			$("#debug").draggable(globaldragevent);
			

			$('#content').resizable(globalResizeEvent);

			$("#panel2").resizable(globalResizeEvent);
			$("#menu").resizable(globalResizeEvent);
			$("#logo").resizable(globalResizeEvent);
			$("#langnav").resizable(globalResizeEvent);

		
			$('#panel1').animate({ left: '40', top: '182'}, 1); 
			$('#panel2').animate({ left: '1001', top: '60'}, 1); 

            $("#worldmap").animate({ left: '+=20', top: '+=8' }, 800);

			$('#logo').animate({left:212, top:'-16'}).show("scale", {percent: 100}, 1200);
			$('#menu').animate({ left: '10', top: '122'}, 0);

			$('#content').animate({ left: '263', top: '182'}, 0);

			$('#langnav').css({'left': '826px', 'top':'54px'});

			$('img.menuHover').each(function(i)
			{
				$(this).hover(
				function()
				{
					$(this).attr("src", $(this).attr("src").replace('_green','_blue'));
				},		
				function()
				{
					$(this).attr("src", $(this).attr("src").replace('_blue','_green'));
				});
			});

			$(window).scroll(function(){
				    
					if (($('#footer').css('display') == "none"))
					{
						var ActualContentHeight = $(document).height() - $(window).height();
						var S1 = ActualContentHeight - 400;
						if  ($(window).scrollTop() >= S1 && $(window).scrollTop() < ActualContentHeight ){
                           setBackground2Position();
						   window.setTimeout(function() 
							                { 
							                    $("#footer").animate({ top: '+=150px'}, 800); 
												$("#sliderdiv").css('top', -90);
						                    }, 500);
						}
					}
			});



			$('#js-news').ticker( {
				titleText: ''
			});
		
			  $('#slider').simpleslider({
					auto: true,
					interval: 2000,
					speed: 500,
					direction: 'horizontal',
					buttons: false
				});

			var test = $('#menutitle11_a').attr('appear');
			if (test == 'yes')
			{					
				$('#bg_pp').animate({ left: '-=420' },0);
				$('#menutitle11_a').delay(1900).attr('appear', 'no');
			}

			$('#menutitle11_a').mouseenter(function() {
				
				test = $('#menutitle11_a').attr("appear");

				if (test == 'no')
				{
					$('#menutitle11_a').attr('appear', 'yes');
					$('#bg_pp').animate({ left: '800' }, 0).animate({ left: '-=800' }, 800);
				}
			});

			$('#sliding-navigation3').mouseleave(function() {
				    test = $('#menutitle11_a').attr('appear');
					if (test == 'yes')
					{
						$('#bg_pp').delay(2000).animate({ left: '-=420' }, 400);
						$('#menutitle11_a').delay(2900).attr('appear', 'no');
					}
			}); 

			$('#bg_pp_crossX').click(function() {
						$('#bg_pp').animate({ left: '-=420' }, 400);
						$('#menutitle11_a').delay(2000).attr('appear', 'no');
			});

			$('#sliding-navigation1').mouseenter(function() {
				$('#tabmenu11').animate({ width: '570' }, 500);
				$('#sliding-navigation1a').show();
				$('#sliding-navigation1b').show();

			});
			
			$('#tabmenu11').mouseleave(function() {
				$('#sliding-navigation1a').hide();
				$('#sliding-navigation1b').hide();
				$('#tabmenu11').animate({ width: '188' }, 500);
			});

			$('#sliding-navigation2').animate({ height: '375' }, 400);
			$('#tabmenu2').mouseenter(function() {
				$('#tabmenu2').animate({ height: '830' }, 500);
				$('#sliding-navigation2').animate({ height: '830' }, 500);
			}).mouseleave(function() {
				$('#tabmenu2').delay(2400).animate({ height: '375' }, 400);
				$('#sliding-navigation2').delay(2400).animate({ height: '375' }, 400);
			});

		   window.setTimeout(function() 
				{ 
				    test = $('#menutitle11_a').attr('appear');
					if (test == 'yes')
					{					
						$('#bg_pp').animate({ left: '-=420' }, 400);
						$('#menutitle11_a').delay(1900).attr('appear', 'no');
					}
				}, 2900);


		   window.setTimeout(function() 
				{ 
					if (($('#footer').css('display') == "none"))
					{
						setBackground2Position();
						window.setTimeout(function() 
						       { 
									$("#footer").animate({ top: '+=150px'}, 800); 
									$("#sliderdiv").css('top', -90);
						       }, 500);
					}
					
				}, 5000);


		$("#content").draggable("destroy");

		});



var globaldragevent = {
		// Find original position of dragged image.
		start: function(event, ui) {

			// Show start dragged position of image.
			var Startpos = $(this).position();
			$("div#start").text("START: \nLeft: "+ Startpos.left + "\nTop: " + Startpos.top + "\nz-index: " + $(this).css('z-index') + "\nwidth: " + $(this).css('width') + "\nheight: " + $(this).css('height'));
		},

		drag: function(event, ui) {

			// Show drag position.
			var Stoppos = $(this).position();
			$("div#stop").text("STOP: \nLeft: "+ Stoppos.left + "\nTop: " + Stoppos.top + "\nz-index: " + $(this).css('z-index') + "\nwidth: " + $(this).css('width') + "\nheight: " + $(this).css('height'));
		},

		// Find position where image is dropped.
		stop: function(event, ui) {

			// Show dropped position.
			var Stoppos = $(this).position();
			$("div#stop").text("STOP: \nLeft: "+ Stoppos.left + "\nTop: " + Stoppos.top + "\nz-index: " + $(this).css('z-index') + "\nwidth: " + $(this).css('width') + "\nheight: " + $(this).css('height'));
			/* $(this).draggable( "destroy" ); */
			$(this).addClass("defaultLayer2");
		}	
};


var globalResizeEvent = {

		stop: function(event, ui) {

			/*$(this).resizable( "destroy" ); */
			var Stoppos = $(this).position();
			$("div#stop").text("STOP: \nLeft: "+ Stoppos.left + "\nTop: " + Stoppos.top + "\nz-index: " + $(this).css('z-index') + "\nwidth: " + $(this).css('width') + "\nheight: " + $(this).css('height'));
			/* $(this).addClass("defaultLayer2"); */
		}
}

function setBackground2Position()
{
	$("#footer").show();
	$("#background2").show();
    var max_height_content = $('#content').height() + $('#content').position().top;
	/* var max_height_panel1 = $('#pane11').height() + $('#pane11').position().top; */
	var max_height_panel2 = $('#panel2').height() + $('#panel2').position().top;

    var GreatestHeight = -10;
	var GreastestTop = 0;

	switch (true) {
		case  (max_height_content > max_height_panel2):
			GreatestHeight += max_height_content + 50;
			GreastestTop = $('#content').position().top;
			break
		default:
			GreatestHeight += max_height_panel2 + 100;
			GreastestTop = $('#panel2').position().top;
	}

	$("#background2").css( { 'top': GreatestHeight  } );

}


function getCurrentState_Panel2()
{
	$(".sliding-navigation").hide();
	var theNavNum = $.cookies.get('CurrentState_Panel2');
	
	(theNavNum == null) ? $('#sliding-navigation1').show() : $('#sliding-navigation' + theNavNum).show();

}

function setCurrentState_Panel2(navigation_id)
{
	//$(".sliding-navigation").hide();
	$.cookies.set("CurrentState_Panel2", navigation_id, { hoursToLive: 0.5 }); // expired
}


function initializeDebug()
{
	$('#debugToggle').toggle(
      function () {
        $('#debug').show();
      },
      function () {
        $('#debug').hide();
      }
    );

}



