var arrowimages={down:['downarrowclass', '/p/down.gif', 23], right:['rightarrowclass', '/p/right.gif']}
var tempora='';
var zzz=mmm=lvl=ttt='';
function hideitnow(){
mmm.slideUp(jqueryslidemenu.animateduration.out);
}
function hideandshow() {
$('.'+lvl).slideUp(jqueryslidemenu.animateduration.out);
sss.slideDown(jqueryslidemenu.animateduration.over)
}
var hidetimers=Array();

var jqueryslidemenu={
    animateduration: {over: 0, out: 0},
    buildmenu:function(menuid, arrowsvar, type){
    	jQuery(document).ready(function($){
    		var $mainmenu=$("#"+menuid+">ul")
    		var $headers=$mainmenu.find("ul").parent()
    		$headers.each(function(i){
    			var $curobj=$(this)
    			var $subul=$(this).find('ul:eq(0)');
    			this._dimensions={w:this.offsetWidth, h:this.offsetHeight, subulw:$subul.outerWidth(), subulh:$subul.outerHeight()}
    			this.istopheader=$curobj.parents("ul").length==1? true : false
    			$subul.css({left:this.istopheader? this._dimensions.w+"px" : 0})
    			if (type==2){    			     
    				$curobj.children("a:eq(0)").css({background:'url(/p/right.gif) no-repeat right center'});
                    if($curobj.children("a:eq(0)").attr('rel')=='selected') $curobj.children("a:eq(0)").css({backgroundColor:'#999999'});
    			}else{
    				$curobj.children("a:eq(0)").css(this.istopheader? {paddingRight: arrowsvar.down[2]} : {}).append(
    				'<img src="'+ (this.istopheader? arrowsvar.down[1] : arrowsvar.right[1])
    				+'" class="' + (this.istopheader? arrowsvar.down[0] : arrowsvar.right[0])
    				+ '" style="border:0;" />'
    			)}            
    			$curobj.hover(
    				function(e){
    					var $lala=$(this);
    					var $targetul=$(this).children("ul:eq(0)");
						lvl=$targetul.attr('class');
						tempora = $lala;
						sss=$targetul;
						clearTimeout(zzz);
						clearTimeout(ttt);
    					this._offsets={left:$(this).offset().left, top:$(this).offset().top}
    					if (type==2){		              
    					   var menuleft=this._dimensions.w;
    					   $targetul.css({top:"0"});                       
                           if($(this).parent().attr('className')=='lvl0') $(this).children('a').css({backgroundColor:'#999999', color:'#fff'});
                           if($(this).parent().attr('className')=='lvl1') {
                                $(this).children('a').css({backgroundColor:'#666666', color:'#fff'});
                                if ($.browser.msie && $.browser.version == 6){
                                    menuleft = menuleft - 7;
                                } else menuleft = menuleft + 2;
                           } 
    					} else {                       
    					   var menuleft=this.istopheader? 0 : this._dimensions.w                                               
                           if($(this).parent().attr('className')=='lvl0') {
                                $targetul.css({top:"23"});
                                $(this).children('a').css({backgroundColor:'#2068ac', color:'#fff'});
                                menuleft = menuleft - 2;
                           }
                           if($(this).parent().attr('className')=='lvl1') {
                                $(this).children('a').css({backgroundColor:'#09416e', color:'#fff'});
                                menuleft = menuleft + 2;
    
                           }                         
    					}
    					menuleft=(this._offsets.left+menuleft+this._dimensions.subulw>$(window).width())? (this.istopheader? -this._dimensions.subulw+this._dimensions.w : -this._dimensions.w) : menuleft
    					if($targetul!=$(this).parent)ttt=setTimeout(hideandshow,1100);
						
						$targetul.css({left:menuleft+"px",width:this._dimensions.subulw+'px'});//.slideDown(jqueryslidemenu.animateduration.over)
    				},
    				function(e){ 
    				    if ($(this).children('a').attr('rel')!='selected'){  
        				    if (type==2){
        				        if($(this).parent().attr('className')=='lvl0') $(this).children('a').css({backgroundColor:'', color: '#2e3133'});
                                if($(this).parent().attr('className')=='lvl1') $(this).children('a').css({backgroundColor:'', color: ''});
                            } else {
                                if($(this).parent().attr('className')=='lvl0') $(this).children('a').css({backgroundColor:'', color: ''});
                                if($(this).parent().attr('className')=='lvl1') $(this).children('a').css({backgroundColor:'', color: ''});
                            }
                        }
						
						var $targetul=$(this).children("ul:eq(0)");
						lvl=$targetul.attr('class');
						clearTimeout(zzz);
						clearTimeout(ttt);
						mmm=$targetul;
						zzz = setTimeout(hideitnow,1100);
    				},function(){});
    		});
    		$mainmenu.find("ul").css({display:'none', visibility:'visible'})
    	});
    }
}
jqueryslidemenu.buildmenu("top_menu", arrowimages, 1);
jqueryslidemenu.buildmenu("left_menu", arrowimages, 2);
