var stepStore = 0;
var navStore = 'home';
var conStore = new Array();
$(document).ready(function(){    
	$(".navLink").click(function () {
	  $(this).toggleClass("linkHi");
	  $('#'+navStore).toggleClass("linkHi");
	  navStore = this.id;
	});
	$('img.contentImg').load(function(){
	
	  if (this.id!='img_'+stepStore) {
	  	$(this).animate( { opacity: 0.1}, 500 );
	  }
	});			    
	$('#contentBackground').animate( { opacity: 0.9}, 1 );
	//whatever hover simple on ie6
	/*
	$('.navLink').mouseover(function(){
	  $(this).css('backgroundColor','#008b47');
	}).mouseout(function(){
	  if ($(this).hasClass('linkHi')) {
	  	//donothing
	  } else {
	  	$(this).css('backgroundColor','#bfbfbf');
	  }		
	});*/
	//blendContent('noClose');			
});


function imgScroll(steps,lnkObj,specialContent) {
	if (steps!=stepStore) {
		if (typeof specialContent == 'undefined') hideContent();
		$('#subNavContainer').fadeOut('slow');
		if (!isNaN(steps)) {
			var unit = 780;
			var scrollTarget = unit*steps;
			$('#innerImageContainer').animate( { marginLeft: -scrollTarget+"px"}, 2000, "easeOutCirc" , function () {showSubNavi(steps,lnkObj)} );
			$('#img_'+stepStore).animate( { opacity: 0.1}, 500 );
			$('#img_'+steps).animate( { opacity: 1}, 2500 ); 
		}     			
		stepStore = steps;
		if (typeof specialContent != 'undefined') {
			showContent(lnkObj,'','noClose');
		}
	}
}

function showSubNavi (contentID,lnkObj) {      			
	//declare subnavi
	var hasSubNav	= [ 2, 3 ];
	var subNavLogo	= new Array();
	subNavLogo[0] 	= new Object();
	subNavLogo[0][2]= 'junior_flag.gif';
	subNavLogo[0][3]= 'super_flag.gif';
	//show if exists      			
	if (jQuery.inArray(contentID,hasSubNav)>-1) {
		if (typeof subNavLogo[0][contentID] != 'undefined') $('#subFlagLogo').attr('src','img/'+subNavLogo[0][contentID]);
		
		$('#subNavContainer').slideDown('slow');
		$('#atWork').attr('rel',contentID);
		$('#Gallery').attr('rel',contentID);
		$('#Options').attr('rel',contentID);
		$('#Technic').attr('rel',contentID);
	}
}

function showContent (contentObj,toDo,optVar) {
	$.post("lib/contentLoader.php", { cFile: contentObj.id, cID: contentObj.rel },
  function(data){
    $('#innerContent').html(data);
    $('#innerContent').css('marginTop','0px');
    cMargin = 0;
    //$("a[rel^='prettyPhoto']").prettyPhoto();
    $("a[rel^='prettyPhoto']").prettyPhoto({
    	allowresize: true,
    	theme: 'light_rounded' /* light_rounded / dark_rounded / light_square / dark_square */
    });
    blendContent(optVar);
  });
}

function blendContent(optVar) {
	$('#contentContainer').fadeIn('slow');
	if (optVar!='noClose') {
		$('#closeContent').fadeIn('slow');
	} else {
		$('#closeContent').fadeOut('slow');
	}
	checkContentHeight();
}
function hideContent() {
		//$('#contentBackground').animate( { opacity: 0.1}, 1 );
		$('#contentContainer').fadeOut('slow');
		$('#closeContent').fadeOut('slow');
	}
	var cMargin = 0;
	
function scrollNow (dir) {
	cEnd = $('#innerContent').height();
	cDif = cEnd-(cMargin*(-1));
	if (dir=='up') {
		if (cDif>$('#contentContainer').height()-20) {
			cMargin=cMargin-2;
		}					    		
	} else {
		if (cMargin<=0) {
			cMargin=cMargin+2;	
		}					    		
	}					    	
	$('#innerContent').css('marginTop',cMargin+"px");					    						    	
}  


var initScrollStore = false;
function checkContentHeight () {
	$('#contentContainer').height(460);
	var cFrame = $('#contentContainer').height();
	var cInner = $('#innerContent').height();
	if (cInner>cFrame) {
		$('#contentScrollUp').show();
		$('#contentScrollDown').show();
		if (initScrollStore==false) {
			initScrollStore=true;
			$('#contentScrollUp').mouseover(function(){
		    startScrollUp = window.setInterval("scrollNow('down')", 10);					    
	    }).mouseout(function(){
  			window.clearInterval(startScrollUp);
	    });
		$('#contentScrollDown').mouseover(function(){
		    startScrollUp = window.setInterval("scrollNow('up')", 10);					    
	    }).mouseout(function(){
  			window.clearInterval(startScrollUp);
	    });
			
		} 
	}
	else {
		$('#contentScrollUp').hide();
		$('#contentScrollDown').hide();
		if (cInner<445) {
			var minimize = cInner+15;
			$('#contentContainer').animate({
				"height": minimize+"px"
			},500);
			
		}
		
	}
}

function chkForm() {
	var MailError = false;
		if ($('#name').val()=='') {
			MailError = true;
			$('#labelName').html('Name *:');
			$('#labelName').append('<span class="mailError"> Bitte ausfüllen.</span>');
		} else {
			$('#labelName').html('Name *:');
		}
		if ($('#em').val()=='') {
			MailError = true;
			$('#labelMail').html('eMail *:');
			$('#labelMail').append('<span class="mailError"> Bitte ausfüllen.</span>');
		} else {
			$('#labelMail').html('eMail *:');
			//alert (valideMail($('#em').val()));
			if (valideMail($('#em').val())==false) {
				MailError = true;
				$('#labelMail').append('<span class="mailError"> Diese eMail Adresse hat ein ungültiges Format.</span>');
			}
		}
		if (MailError==true) {
			return false;
		} else {
			$.post("lib/mOut.php", { 
				name: $('#name').val(),
				addr: $('#addr').val(),
				tel: $('#tel').val(),
				em: $('#em').val(),
				msg: $('#msg').val(),
				prosJ: $('#prosJ:checked').val(),
				prosS: $('#prosS:checked').val()
			},
			function(data){
			    $('#innerContent').html(data);
			    $('#closeContent').fadeIn('slow');
			});

		}
	
}
function valideMail (mString) {
	if (!mString.match(/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$/i)){
	    return false;
	} else {
	    return true;	    
	}
}




















