
var _active_id = "";

function init_headmenu( menu )
{
	$("#start").mouseover( show_menu );
	$("#start").mouseout( hide_menu );
	$("#start").click( show_start );

	$("#credits").mouseover( show_menu2 );
	$("#credits").mouseout( hide_menu2 );
	$("#credits").click( show_credits );

	$("#references").mouseover( show_menu3 );
	$("#references").mouseout( hide_menu3 );
	$("#references").click( show_references );

	$("#contact").mouseover( show_menu4 );
	$("#contact").mouseout( hide_menu4 );
	$("#contact").click( show_contact );

	if( menu == "referenzen" ){
		show_references();
	}else if( menu == "kontakt" ){
		show_contact();
	}else if( menu == "impressum" ){
		show_credits();
	}else if( menu == "sitemap" ){
		show_sitemap();
	}else if( menu == "ra-zabel" ){
		show_references();
		show_references_razabel();
	}else if( menu == "port" ){
		show_references();
		show_references_port();
	}else if( menu == "fotowettbewerb" ){
		show_references();
		show_references_fotowb();
	}else if( menu == "ms-blog" ){
		show_references();
		show_references_myblog();
	}else{
		show_start();
	}
}

function hin()
{
	$("#ref-id").animate({ left: "-772px" }, { duration: 500, queue: false, complete: completed2 });
}

function her()
{
	$("#ref-id").animate({ left: "1px" }, { duration: 500, queue: false, complete: completed });
}

function completed2()
{
	window.location.href = "#pre-ref-top";
}

function completed()
{
	$("#her-id").hide();
	window.location.href = "#pre-ref-top";
}

function show_menu( id )
{
	$("#start").animate({
        height: "30px",
        opacity: 0.85
      }, 200 );

}

function hide_menu( id )
{
	$("#start").animate({
        height: "20px",
        opacity: 1.0
      }, 200 );
}

function show_menu2()
{
	$("#credits").animate({
        height: "30px",
        opacity: 0.85
      }, 200 );
}

function hide_menu2()
{
	$("#credits").animate({
        height: "20px",
        opacity: 1.0
      }, 200 );
}

function show_menu3()
{
	$("#references").animate({
        height: "30px",
        opacity: 0.85
      }, 200 );
}

function hide_menu3()
{
	$("#references").animate({
        height: "20px",
        opacity: 1.0
      }, 200 );
}

function show_menu4()
{
	$("#contact").animate({
        height: "30px",
        opacity: 0.85
      }, 200 );
}

function hide_menu4()
{
	$("#contact").animate({
        height: "20px",
        opacity: 1.0
      }, 200 );
}

function show_start()
{
	var ajax = new msAjax();
	ajax.send(
		'load_start',
		function( retval ){
			if( !!retval.status == true ){
				if( _active_id != "" ){
					$('#' + _active_id).attr({ "class" : "headmenu"});
				}
				_active_id = 'start';
				$('#start').attr({ "class" : "headmenu active"});
				$('#subcontent_id').fadeOut("slow", function(){
					$('#subcontent_id').html( retval.widget ).fadeIn("normal");
					$('#head_info_id').html( retval.widget2 ).fadeIn("normal");
				});
			}
		}
	);
}

function show_credits()
{
	var ajax = new msAjax();
	ajax.send(
		'load_credits',
		function( retval ){
			if( !!retval.status == true ){
				if( _active_id != "" ){
					$('#' + _active_id).attr({ "class" : "headmenu"});
				}
				_active_id = 'credits';
				$('#credits').attr({ "class" : "headmenu active"});
				$('#subcontent_id').fadeOut("slow", function(){
					$('#subcontent_id').html( retval.widget ).fadeIn("normal");
					$('#head_info_id').html( retval.widget2 ).fadeIn("normal");
				});
			}
		}
	);
}

function show_references()
{
	var ajax = new msAjax();
	ajax.send(
		'load_references',
		function( retval ){
			if( !!retval.status == true ){
				if( _active_id != "" ){
					$('#' + _active_id).attr({ "class" : "headmenu"});
				}
				_active_id = 'references';
				$('#references').attr({ "class" : "headmenu active"});
				$('#subcontent_id').fadeOut("slow", function(){
					$('#subcontent_id').html( retval.widget ).fadeIn("normal", function(){
						$("#jm-fotowb").click( show_references_fotowb );
						$("#ra-zabel").click( show_references_razabel );
						$("#ms-blog").click( show_references_myblog );
						$("#fa-port").click( show_references_port );
					});
				});
			}
		}
	);
}

function show_contact()
{
	var ajax = new msAjax();
	ajax.send(
		'load_contact',
		function( retval ){
			if( !!retval.status == true ){
				if( _active_id != "" ){
					$('#' + _active_id).attr({ "class" : "headmenu"});
				}
				_active_id = 'contact';
				$('#contact').attr({ "class" : "headmenu active"});
				$('#subcontent_id').fadeOut("slow", function(){
					$('#subcontent_id').html( retval.widget ).fadeIn("normal");
				});
			}
		}
	);
}

function show_sitemap()
{
	var ajax = new msAjax();
	ajax.send(
		'load_sitemap',
		function( retval ){
			if( !!retval.status == true ){
				if( _active_id != "" ){
					$('#' + _active_id).attr({ "class" : "headmenu"});
				}
				_active_id = '';
				$('#subcontent_id').fadeOut("slow", function(){
					$('#subcontent_id').html( retval.widget ).fadeIn("normal");
				});
			}
		}
	);
}

function show_references_fotowb()
{
	var ajax = new msAjax();
	ajax.send(
		'load_references_fotowb',
		function( retval ){
			if( !!retval.status == true ){
				$('#her-id').html( retval.widget ).show();
				hin();
			}
		}
	);
}

function show_references_razabel()
{
	var ajax = new msAjax();
	ajax.send(
		'load_references_razabel',
		function( retval ){
			if( !!retval.status == true ){
				$('#her-id').html( retval.widget ).show();
				hin();
			}
		}
	);
}

function show_references_myblog()
{
	var ajax = new msAjax();
	ajax.send(
		'load_references_myblog',
		function( retval ){
			if( !!retval.status == true ){
				$('#her-id').html( retval.widget ).show();
				hin();
			}
		}
	);
}

function show_references_port()
{
	var ajax = new msAjax();
	ajax.send(
		'load_references_port',
		function( retval ){
			if( !!retval.status == true ){
				$('#her-id').html( retval.widget ).show();
				hin();
			}
		}
	);
}

function send_message()
{
	var name = $('#contact-name').val();
	var phone = $('#contact-phone').val();
	var email = $('#contact-email').val();
	var subject = $('#contact-subject').val();
	var msg = $('#contact-msg').val();

//	if( !!name == false || !!email == false || !!msg == false ){
//		$('#contact-err').fadeIn();
//		return;
//	}

	var ajax = new msAjax();
	ajax.send(
		'send_message',
		function( retval ){
			if( !!retval == true ){
				$('#contact-err').hide();
				$('#contact-okay').fadeIn();
				$('#contact-name,#contact-phone,#contact-email,#contact-subject,#contact-msg').val('');
			}else{
				$('#contact-err').fadeIn();
			}
		},
		{
			'name'	: name,
			'phone'	: phone,
			'email'	: email,
			'subj'	: subject,
			'msg'	: msg
		}
	);
}

