
var iaz_preserved_elements = [];
var iaz_preserved_zindexes = [];

/*ie_apply_zindex('#galleryContainer', 1);
ie_apply_zindex('#imagesContainer', 1);
ie_apply_zindex('#offsetContainer', 1);*/

function ie_apply_zindex(element_id, zindex, context_id) {
   // default values
   if (undefined == zindex) { zindex = 1; }
   var context = (undefined == context_id ? $(context_id) : $(document.body));
   var element = $(element_id);

   // undo past ie_apply_zindex()
   for (i = iaz_preserved_elements.length-1; i >= 0; i--) {
      iaz_preserved_elements[i].setStyle({'z-index': iaz_preserved_zindexes[i]});
   }
   iaz_preserved_elements = [];
   iaz_preserved_zindexes = [];

   // find relative-positioned ancestors of element within context
   element.parents().each(
      function(parent) {
         if ('relative' == parent().getStyle('position')) {
            // preserve ancestor's current z-index
            iaz_preserved_elements.push(parent());
            iaz_preserved_zindexes.push( parent().getStyle('z-index') );

            // apply z-index to ancestor
            parent().setStyle({'z-index': zindex});
         }
         if (parent() == context) { throw $break; }
      }
   );
}

/** expand menu **/
function makeTall() {
    //alert("hover make tall");
	//ie_apply_zindex('li.bg-img img', 1);
//	alert($("#galleryContainer").css('z-index'));
//	alert($("#panel-area").css('z-index'));
//	alert($("#imagesContainer").css('z-index'));
//	alert($("#offsetContainer").css('z-index'));
//	alert("bg-img" + $("bg-img").css('z-index'));
    $(".navi").show();
    $(".navi").animate({"height":112, "margin-bottom":0},200);
}

/** collapse menu **/
function makeShort(){
//	alert($("#galleryContainer").css('z-index'));
//	alert($("#panel-area").css('z-index'));
//	alert($("#imagesContainer").css('z-index'));
//	alert($("#offsetContainer").css('z-index'));
//	alert($(".bg-img").css('z-index'));
    //alert("hover make short")
    $(".navi").animate({"height":0},200, function(){
        $(".navi").hide();
    });
}

/** init menu **/
$(function(){

//	ie_apply_zindex('bg-img', 6);

    makeTall(); // expand menu
    //$('#panel-area').hover(makeTall,makeShort);

    $("#panel-area").mouseenter(function(){
        //alert("mouse enter");
        makeTall();
    });

    $("#panel-area").mouseleave(function(){
        if ( $("#tekstContainer").height() > 0 || contentstate == 'open' ) {
            // dont make it short
            //alert("hier?"); Hij blijft hier hangen....
        } else {
            //alert("naar make short functie");
            makeShort();
        }
    });

    var current_url = parseURL (document.location);
    if ( in_array ( 'portfolio', current_url.segments ) ) { // we're viewing the portfolio hide the menu
        makeShort();
    }
    

});
