// JavaScript Document
var is_IE = false;
function init(do_intro, is_IE_param){
	is_IE = is_IE_param;
	var h = $(".wrapper").outerHeight(false);
	if(do_intro) {
		$("body").append('<div id="tall" style="height:' + h + 'px;"></div>');
		
		$("body").append('<img id="loading" style="color:#FFF; position:absolute; top:200px; left:50%;" src="images/graphics/loader.gif" width="16" height="16" />');
		
		
		$(".wrapper").toggle();
		$(".center").toggle();
		$(".footer_wrapper").toggle();
		
		$.preload(['loft-space-1500x900-2'],
					{
					base: 'images/graphics/',
					ext: '.jpg',
					onComplete:	function(data) {initCenter();}
					});
	}

	//$(".footer").css("top", h - $(".footer").outerHeight(true));
	$(document).pngFix();
	
	initDropDowns();
}


function initCenter() {
   $("#loading").toggle();
	$(".wrapper").fadeIn(
				   750,
				   function callBack(){pause(".center");}
				   );
	$(".wrapper").click(function(){
					$(".wrapper").unbind("click");
					
					$(".wrapper").stop(true, false);
					$(".center").stop(true, false);
					$(".footer_wrapper").stop(true, false);
					
					$(".wrapper").fadeIn("fast");
					$(".center").fadeIn("fast");
					$(".footer_wrapper").fadeIn("fast");
	});
}
   
function pause(obj){
	$(obj).animate({
				   dummy:0
				   },
				   2000,
				   function callBack(){
						$(".center").fadeIn(1000);
						$(".footer_wrapper").fadeIn(1000);
						$("#tall").toggle();
					   }
				   );
}

var over = false;
//var curr_menu;
var menu_items = Array();

var curr_color = "#DEDEDE";
var over_color = "#ADADAD";
var over_image = "url(images/graphics/drop_bg.png) repeat-x";
//var border_normal = "solid 1px #DEDEDE";

function initDropDowns(){
	over = false;
	
	menu_items = $(".drop_down");
	
	$(".drop_down").bind("mouseover", dropOver);
	$(".drop_down").bind("mouseout", dropOut);
	
	$(".drop_down").children().next().bind("mouseover", dropChildOver);
	$(".drop_down").children().next().bind("mouseout", dropChildOut);
}

function dropOver (e){
 	var curr_id = $(this).attr("id");
	over = true;
	
	jQuery.each(menu_items, function(){
									 if($(this).attr("id") != curr_id) {
										 $(this).children().next().hide();
										 $(this).css("background", "none");
										 //$(this).children().css("border-left", border_normal);
										 if($(this).children().attr("class") == "current") {
											 $(this).children().css("background", curr_color);
										 }
									 } else {
										 if(is_IE) {
											 $(this).children().css("display", "block");
										 } else {
											$(this).children().next().fadeIn(250);
										 }
										 //$(this).children().css("border-left", "none");
										 if($(this).children().attr("class") == "current") {
											 $(this).children().css("background", over_color);
											 $(this).children().next().css("background", over_image);
										 }
									 }
									 });
	
 }
 
function dropOut(){
	over = false;
	stopTimer($(this));
	startTimer($(this));
	$(this).css("background", over_color);
}

function dropChildOver(){
	over = true;						  
	stopTimer($(this).parent());
	$(this).parent().css("background", over_color);
}

function dropChildOut(){
	over = false;
	startTimer($(this).parent());
}


function startTimer(obj) {
	$(obj).animate({
				   dummy:0
				   },
				   250,
				   function callBack(){
					   resetMenuItem(obj);
				   }
				   );
}

function stopTimer(obj) {
	$(obj).stop(true, false);
}

function resetMenuItem(obj) {
	if(!over) {
		$(".drop_down").css("background", "none");
		$(".current").css("background", curr_color);
/*		if($(this).children().attr("class") == "current") {
			 $(this).children().css("background", "#ADADAD");
		}*/
		$(obj).children().next().hide();
		//$(obj).children().css("padding-bottom", "1px");
		over = false;
	}
}