/**
 * yaralinss.de
 * @author	Michael Bayer
 */

var bg = new Array();
bg[0] = 'hg1.jpg';
bg[1] = 'hg2.jpg';
bg[2] = 'hg3.jpg';
bg[3] = 'hg4.jpg';
for (var i = 0; i < bg.length; i++) {
	$.cacheImage('image/'+bg[i]);
}

var lastReq = '', activeBg = '', footerHeight=0;	

function setContent(reqContent,callingElement,switchLayers,title,newHG) {
/*
	if( $("div:animated:first").length != 0 || reqContent == lastReq  ) {
		return false;
	}
*/
	var reqUrl = 'exchange.php?content='+reqContent;
	lastReq = reqContent;

	$("#layer .pagesContent").load(reqUrl,false,function() {
		$("#layer").hide();
		$("ul.menu a").removeClass('active');
		$(callingElement).addClass('active');
		$("#overlay").fadeIn('normal',function(){
			var goon;
			while(goon != true) {
				random = Math.round((bg.length-1)*(Math.random()));
				if(bg[random] != activeBg) {
					goon = true;
				}
			}
			activeBg = bg[random];
			$('body').css('background-image',"url('image/"+activeBg+"')");
			$("#overlay").fadeOut('normal',function() {
				$("#layer").fadeIn('normal');
			});
		});
	});
};

function switchFooter() {
	if($("#footer").height() != footerHeight) {
		$("#footer").animate({ 
		  height: footerHeight+"px"
		}, 500 );
	} else {
		$("#footer").animate({ 
		  height: "85px"
		}, 500 );
	}
}

$(document).ready(function() {

	footerHeight = $("#footer").height();
	$("#layer").css('opacity','0.85');
	$('#footer').css('opacity','0.6');

	// Homeseite wird beim Start geladen
	setContent('home',false,true,false,1);
	
	$("a[href^='home']").click(function () {
		setContent('home',this,true,false,1);
		return false;
	});

	$("a[href^='press']").click(function () {
		if(!isNaN($(this).attr('href').split('/')[1])) {
			setContent('press&id='+$(this).attr('href').split('/')[1],this,true,'press',2);
		} else {
			setContent('press',this,true,'press',1);
		}
		return false;
	});

	$("a[href^='bio']").click(function () {
		setContent('bio',this,true,false,1);
		return false;
	});
	
	$("a[href^='dates']").click(function () {
		if(!isNaN($(this).attr('href').split('/')[1])) {
			setContent('dates&id='+$(this).attr('href').split('/')[1],this,true,false,2);
		} else {
			setContent('dates',this,true,false,1);
		}
		return false;
	});

	$("a[href^='projects']").click(function () {
		setContent('projects',this,true,false,1);
		return false;
	});

	$("a[href^='media']").click(function () {		
		setContent('media',this,true,false,1);
		return false;
	});
	
	$("a[href^='contact']").click(function () {
		setContent('contact',this,true,false,1);
		return false;
	});	
	
	$("a[href^='legalnotice']").click(function () {
		//switchFooter();
		setContent('contact',$("a[href^='contact']"),true,false,1);
		return false;
	});
	
	
	/**
	 * LIVE!
	 */
	
	$("a.galery").live('click',function () {
		tb_show(null, $(this).attr('href')+'?modal=true', false);
		return false;
	});
	
	
	$("a[href='shop']").live('click',function () {
		tb_show(null, 'exchange.php?content=orderform&width=600&height=320&modal=true', false);
		return false;
	});
	
	$('#orderform').live('submit',function() {
		var postdata = $('div.orderform form').serialize();
		$('#postcallback').html('');
		$.post( 'exchange.php?content=submitorder' , postdata ,
		  function(data){
			if(data == 'status=0'){
				$('.orderform_container:eq(0)').fadeOut('900',
					function() {
						$('.ordersuccess:eq(0)').show();
							$("#TB_window").animate({ 
							  height: "55px"
							}, 900 );
					}			
				)
			} else {
				$('#postcallback').html('Bitte überprüfen Sie Ihre Angaben!');
			}
		  });
		return false;
	});
	
	$("a[href='close']").live('click',function () {
		tb_remove();
		return false;
	});
	
	$("a[href^='readmore']").live('click',function () {
		if($(this).parents('.biotext').find('.hidden:animated').length != 0) {
			return false;
		}
		var hiddenDiv = $(this).parents('.biotext').find('.hidden');
		if(hiddenDiv.css('display') == 'block') {
			$('#layer').scrollTo($(this).parents('.biotext'),0);
			hiddenDiv.hide();
			$(this).text('read more');
		} else {
			hiddenDiv.slideDown(500);
			$(this).text('hide');
		}
		return false;
	});


	
});

	function cleanStueckzahl($this) {
		var value = $.trim( $this.val() );
		if(isNaN(value)) {
			$this.val('0');
		}
	}

/******************
FLASH
*******************/
/*
var flashvars = {
  playlist: "wmplayer/config.xml",
  autostart: false
};
var params = {
  menu: "false",
  wmode: "transparent",
  quality: "best",
  scale: "noscale",
  salign: "lt"
};

swfobject.embedSWF("wmplayer/wmplayer.swf", "player", "180", "16", "8.0.0", null, flashvars, params);
*/

