$(document).ready (function () {
		pz.init();
		
		$('#menu')
			.children('a')
			.hover (mm.onOver,mm.onOut);		
		/* bind SWF Adress Events */
		SWFAddress.addEventListener(SWFAddressEvent.CHANGE, mm.onChange);
		$('a[rel="fancybox"]').fancybox({
			overlayColor:'#000000',
			autoDimensions:false,
			width:600,
			height:'auto'
			});
		//list.init();
		
	});














/*::::::::::::::::::::::::::::::
		HANDEL PAGE SIZE
::::::::::::::::::::::::::::::::*/
var pz = {

	minWidth:null,
	minHeight:null,
	

	init:function () {
		
		$sizer = $('#page-size');
		
		pz.minWidth = parseInt($sizer.css('min-width'));
		pz.minHeight = parseInt($sizer.css('min-height'));
		
		$(window).resize(pz.onResize);
		pz.onResize();
	},





	onResize:function () {
		
		$win = $(window);
		$sizer = $('#page-size');
		 
		var nWidth = 0;
		 
		//width
		if ($win.width() < pz.minWidth){
			$sizer.css('width',pz.minWidth);
			nWidth = pz.minWidth;
		}else{
			$sizer.css('width','100%');
			nWidth = $win.width();
		}
		
		//height
		var nHeight = 0;
		var bottomHeight = $('#bottom').height();
		
		if ($win.height() < pz.minHeight){
			nHeight = pz.minHeight - bottomHeight;
			$sizer.css('height',pz.minHeight);
		}else{
			nHeight = $win.height() - bottomHeight;
			$sizer.css('height','100%');
		}
		
		$('#content-wrapper').css('height',nHeight);
		
		$('#content-slider').css('width',$('.content').size() * nWidth);
		
		$('.content')
			.css('width',nWidth)
			.each (function (i) {
				$(this).css('left',nWidth*i);
			});
			
		pz.scaleImages();
	},
	
	
	scaleImages:function () {
	
		$win = $(window);
		
		$('.image-bg').each (function () {
			
			$img = $(this).children('img');
			
			var ration = $img.width() / $img.height();
			var winRation = $win.width()/$win.height();
			
			var nWidth = 0;
			var nHeight = 0;
			
			if (winRation < 1.6) {
				$img.css({'height':'78%','top':'10%'});
			}else{
				$img.css({'height':'100%','top':'0'});
			}
		});
			
	}

}






/*::::::::::::::::::::::::::::::
		HANDEL HISTORY
::::::::::::::::::::::::::::::::*/

var mm = {

	current:null,
	
	onChange:function () {
		
		var np = mm.normAdress();
		
		var $page = $('.content[rel="'+np+'"]');
		
		if ($page.size() > 0) {
			
			mm.current = np;
			mm.changeMenu(np);
			
			
			$('.content')
				.stop()
				.fadeTo(1000,0,function () {
					$(this)
						.children('.image-bg')
						.children('img')
						.css('display','none');	
				})
				.children('.image-bg')
				.children('img')
				.removeClass('quality')
				.addClass('speed');




			$page
				.stop()
				.fadeTo(0,1, function () {
					$(this)
						.children('.image-bg')
						.children('img')
						.removeClass('speed')
						.addClass('quality');					
					
					})
				.children('.image-bg')
				.children('img')
				.css('display','block');
			
			
			
			$('#content-slider')
				.animate({left:-$page.position().left},1000,'easeInOutCirc');

				
		}else{
			
			/**********************************
				ERROR HANDEL !!!!!!!!
			***************************************/
			
		}
		
		
	},
	
	
	
	
	changeMenu:function (index) {
		$('#menu')
			.children('a')
			.removeClass('active');
			
		$('#menu')
			.children('a[href="#'+index+'"]')
			.addClass('active');		
	},
	
	normAdress:function () {
		
		var p = SWFAddress.getPathNames().toString();
		if (p != "") {
			p = p.split('#')[0];
			return p;
		}else{
			return "home";	
		}
			
		
	},
	
	onOver:function () {
		$(this)
			.stop()
			.animate({'color':'#FFCC00'},300);	
	},
	
	
	onOut:function () {
		$(this)
			.stop()
			.animate({'color':'#B3B3B3'},300);
	}

}





/********************
	LISTS / MAP 
*********************/

var list = {

	map:null,
	
	
	
	init:function () {
		//list.map = new GMap2(document.getElementById("map"));
        //list.map.setCenter(new GLatLng(51.165691, 10.451526), 10);
		
		//$('#map').fadeTo(0,.5);
		
		$.getJSON ('infoboxx-out.php', list.onDataLoaded);
	},
	
	
	
	onDataLoaded:function (json) {

		$.each (json.gebiete, function (i, item) {
			
			$('#gebiete > ul').append ('<li>'+item.name+'</li>');
			
			$.each (item.outlets, function (i, outlet) {

					
				//var point = new GLatLng(outlet.latitude, outlet.longitude);
				//list.map.addOverlay(new GMarker(point));
					
					
			});
			
			
			
		});	
		
		
		list.updateListAfterEvent('gebiete');
		list.addMouseScolling('gebiete');
	},
	
	
	
	updateListAfterEvent:function (list) {
	
		$('#'+list)
			.children('ul')
			.children('li')
			.hover (function () {
					$(this).animate({backgroundColor:'#252525',color:'#FFCC00'},400);
				}, function () {
					$(this).animate({backgroundColor:'#000000',color:'#B3B3B3'},400);
					});
		
		
	},
	
	
	
	addMouseScolling:function (list) {
		
		$t = $('#'+list);
			
		$t.bind ({
			
			mousemove:function (e) {
				
				var p = ((e.pageY - $t.offset().top)*100)/$t.height();
				var np = ($t.children('ul').innerHeight() * p)/100;
				
				$t.children('ul')
				  .css('top',-np-$t.offset().top);
				}
			
			});	
		
		
	}
	
	
}






