

// MENU
function initiateMenu(){
    $('#menu-main td').mouseover(function(){
	if(!$(this).hasClass('active')){
	    $('.over',this).stop().animate({'bottom':0},200,function(){
		//$(this).parent().parent().addClass('temp_active');
	    });
	    $('a',this).stop().animate({'color':'#fff'},200);
	}else{
	}
    }).mouseout(function(){
	if(!$(this).hasClass('active')){
	    $('.over',this).stop().animate({'bottom':'26px'},200,function(){
		//$(this).parent().parent().removeClass('temp_active');
	    });
	    $('a',this).stop().animate({'color':'#000'},200);
	}else{
	}
    });
    
    $('#menu-footer td').mouseover(function(){
	if(!$(this).hasClass('active')){
	    $('.over',this).stop().animate({'top':0},200,function(){
		//$(this).parent().parent().addClass('temp_active');
	    });
	    $('a',this).stop().animate({'color':'#fff'},200);
	}else{
	}
    }).mouseout(function(){
	if(!$(this).hasClass('active')){
	    $('.over',this).stop().animate({'top':'31px'},200,function(){
		//$(this).parent().parent().removeClass('temp_active');
	    });
	    $('a',this).stop().animate({'color':'#000'},200);
	}else{
	}
    });
    
	/*
    function checkMenu(){
	var subMenuHeight = $('#menu-sub').height();
	if(!subMenuHeight && !$('body').hasClass('home')){
	    var currentWidth = $('#main').width();
	    //$('#main').css({'padding-left':0,'width':currentWidth+200+'px'});
	}
	var browserHeight = $(window).height();
	var contentHeight = $('#main').height();
	//if(subMenuHeight>(browserHeight-220)){
	//    $('#menu-sub').parent().css({'position':'absolute'});
	//}else{
	//    $('#menu-sub').parent().css({'position':'fixed'});
	//}
	if(subMenuHeight>(contentHeight-100)){
	    $('#main').height(subMenuHeight+100);
	}else{
	    $('#main').css({'height':'auto'});
	}
    }
    checkMenu();
    $(window).resize(function(){
	checkMenu();
    });*/
}

// PANELS
function initiatePanels(){
    var panelCount = 0;
    var panelImageArr = new Array();
    $('.paneltext span').each(function(){
	var height = $(this).height()+40;
	$(this).parent().height(height);
	if($.trim($(this).html())==''){
	    $(this).css({padding:0,marginBottom:'0px'});
	}
    });
    $('.panelgroup').each(function(){
	panelImageArr[panelCount] = $(this).attr('panelbg');
	panelGroupWidth = $('.panel',this).size() * $('.panel').width();
	$(this).css({'width':panelGroupWidth+'px'});
	panelCount++;
    })
    $.loadImages(panelImageArr, function(){panels();});
}
function initiatePanelGroups(){
    var panelCount = 0;
    var panelImageArr = new Array();
	$('.paneltext span').each(function(){
	var height = $(this).height()+40;
	$(this).parent().height(height);
	if($.trim($(this).html())==''){
	    $(this).css({padding:0,marginBottom:'0px'});
	}
    });
    $('.panelgroup').each(function(){
	panelImageArr[panelCount] = $(this).attr('panelbg');
	panelGroupWidth = $('.panel',this).size() * $('.panel').width();
	$(this).css({'width':panelGroupWidth+'px'});
	panelCount++;
    })
    $.loadImages(panelImageArr, function(){panelGroups();});
}
function panels(){
    $('#loading').fadeOut(100);
    var items = $('.panel');
    shuffle(items);
    var panel_height = $('#panels').height();
    var panel_width = items.width();
    for (var i=0;i<items.length;i++) {
	var obj = $(items[i]);
	var background = obj.parent().attr('panelbg');
	var index = ($('.panel',obj.parent()).index(obj));
	var bg_x = -1 * panel_width * index;
	obj.css({'background':'url('+background+') no-repeat '+bg_x+'px 0px','margin-top':panel_height+'px'});
        $(items[i]).delay(i*100).animate({marginTop:0}, {duration:1200,easing:'easeOutCubic'});
    }
    $('.paneltext').delay((items.length*100)).animate({'bottom':0},1200,'easeOutCubic',function(){
	initiatePanelLinks();
    });
}

function panelGroups(){
    $('#loading').fadeOut(100);
    var panels = $('.panel');
    var panelgroups = $('.panelgroup');
    shuffle(panelgroups);
    var panel_height = $('#panels').height();
    var panel_width = panels.width();
    for (var i=0;i<panels.length;i++) {
	var obj = $(panels[i]);
	var background = obj.parent().attr('panelbg');
	var index = ($('.panel',obj.parent()).index(obj));
	var bg_x = -1 * panel_width * index;
	obj.css({'background':'url('+background+') no-repeat '+bg_x+'px 0px'});
    }
    for (var i=0;i<panelgroups.length;i++) {
	var obj = $(panelgroups[i]);
	var background = obj.parent().attr('panelbg');
	var index = ($('.panel',obj.parent()).index(obj));
	var bg_x = -1 * panel_width * index;
	obj.css({'margin-top':panel_height+'px'});
        $(panelgroups[i]).delay(i*100).animate({marginTop:0}, {duration:1200,easing:'easeOutCubic'});
    }
    $('.paneltext').delay((panelgroups.length*100)).animate({'bottom':0},1200,'easeOutCubic',function(){
	initiatePanelLinks();
    });
}

function initiatePanelLinks(){
    var thisHeight = $('#panels').height();
    
    $('.panelgroup').mouseover(function(){
	var obj = $('.paneltext',$(this));
	if(!obj.attr('origHeight')){
	    var origHeight = obj.height();
	    obj.attr({'origHeight':origHeight});
	}
	obj.stop().animate({height:thisHeight},900,'easeOutCubic');
    }).mouseout(function(){
	var obj = $('.paneltext',$(this));
	var origHeight = obj.attr('origHeight');
	obj.stop().animate({height:origHeight},900,'easeOutCubic');
    });
}




function shuffle(a) {
    var j,              // Random position
	x,              // Last item
	i = a.length;   // Iterator
    // Loop through the array
    while(i) {
	    // Select a random position
	    j = (Math.random() * i) | 0;
	    // Get the last item in the array
	    x = a[--i];
	    // Swap the last item with the item at the selected position
	    a[i] = a[j];
	    a[j] = x;
    }
    return a;
}

function initiateLooks(){
    $('.hatchedimage_container').hover(
	function(){
	    if(!$(this).hasClass('active')){
		$('.hatchedoverlay',$(this)).animate({height:'100%'},200);
	    }
	},
	function(){
	    if(!$(this).hasClass('active')){
		$('.hatchedoverlay',$(this)).animate({height:'0'},200);
	    }
	}
    );
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}



function initiateH1(){
    $('h1').each(function(){
		if($(this).html()==''){
			    $(this).hide();
		}
    });
}

