//////////////////////////////////////////////////////////////////////////
//                                                     					//
//      Lundin Mining 2010 website scripting                     		//
//      Copyright 2010, James Clarke -- Adnet Communications Inc.      	//
//      Requires Mootols 1.1 Library                           			//
//                                                      				//
//////////////////////////////////////////////////////////////////////////

window.addEvent('domready',function(){      
         
////////////////////////////
// SUB MENU
//////////////////////////////

         var subMenuAnim = new Fx.Style('subNav','width').set(70);
         var subMenuBGAnim = new Fx.Style('subNav','background-position').set([-18,0]);
         
         var sm_fadeInt;
         var sm_width = 70;
         var sm_bgPos = [-18,0];
         var targetWidth = 190;
		 
		function setSubHeight(){
		 	 var mySubHeight = $('main_container').getTop();
			 var targetSubHeight = $('footer_container').getTop();
			 var newSubHeight = targetSubHeight - mySubHeight - getOffset();
			 $('subNav').setStyle('height',newSubHeight);	
		}
		function getOffset(){
			if(document.all){
				return 22;
			}else{
				return 10;
			}
		}
		setSubHeight();
		setTimeout(setSubHeight, 2000);
         
         function myTrans(){
            var rate = .5;
            var out = 5;
            var incline = (sm_width > 120)?true:false;
            
            if(incline){
               rate += (sm_width - 120)*.01
            }else{
               rate -= (sm_width - 190)*.01
            }
            
            return Math.floor(out);//*rate);
         }
   
         function sm_FadeIn(){
            clearInterval(sm_fadeInt);
            if(sm_width < targetWidth) sm_fadeInt = setInterval(sm_Anim,10);

         }
         function sm_FadeOut(){
            clearInterval(sm_fadeInt);
            sm_fadeInt = setInterval(sm_AnimNeg,10);
         }
         
         function sm_Anim(){
            var adj = myTrans();
            sm_width += adj;
            sm_bgPos[0] = sm_bgPos[0] + adj; 
            subMenuAnim.set(sm_width);
            subMenuBGAnim.set(sm_bgPos);
            
            if(sm_width >= targetWidth) clearInterval(sm_fadeInt);
         }
         function sm_AnimNeg(){
            var adj = myTrans();
            sm_width -= adj;
            sm_bgPos[0] = sm_bgPos[0] - adj; 
            subMenuAnim.set(sm_width);
            subMenuBGAnim.set(sm_bgPos);
            
            if(sm_width < 70) clearInterval(sm_fadeInt);
         }
         
         $("subNav").addEvent('mouseenter',function(e){
               e = new Event(e).stop();
               sm_FadeIn();
			   setSubHeight();
            });
         
         $("subNav").addEvent('mouseleave',function(e){
               e = new Event(e).stop();
               sm_FadeOut();
            });   
                     
      });
