$(function() {
	//top menu
    $('#tbNav tr td').mouseover(function() {
        var sel = $(this).attr('id');
       if( sel != null && sel != ''){
           //onhover - change BG
    	   //alert(sel);
		  changeBG(sel);
       }
       
    }).mouseout(function() {
        //onhover OUT - default
            var sel = $('body').attr('id');
           if( sel != null && sel != ''){
               //onhover - change BG
        	   loadBG(sel);
           }
    }).click(function() {
        //onhover click
    	 var sel = $(this).attr('id');
           if( sel != null && sel != ''){
        	   if( lang == 'fr' ){
        		   if(sel == 'tfr_home'){
						redirect('http://www.mwcfin.com/index.php');
					}else if(sel == 'tfr_about'){
						redirect('http://www.mwcfin.com/fr/about_us.php');
					}else if(sel == 'tfr_services'){
						redirect('http://www.mwcfin.com/fr/service.php');
					}else if(sel == 'tfr_calculator'){
						redirect('http://www.mwcfin.com/fr/calculator.php');
					}else if(sel == 'tfr_contact'){
						redirect('http://www.mwcfin.com/fr/contactez_nous.php');
					}else if(sel == 'tfr_credit'){
						redirect('http://www.mwcfin.com/fr/application.php');
					}
    		   }else{
					if(sel == 't_home'){
						redirect('http://www.mwcfin.com/index.php');
					}else if(sel == 't_about'){
						redirect('http://www.mwcfin.com/about_us.php');
					}else if(sel == 't_services'){
						redirect('http://www.mwcfin.com/service.php');
					}else if(sel == 't_calculator'){
						redirect('http://www.mwcfin.com/calculator.php');
					}else if(sel == 't_contact'){
						redirect('http://www.mwcfin.com/contact_us.php');
					}else if(sel == 't_credit'){
						redirect('http://www.mwcfin.com/application.php');
					}
        	   }
           }
        });
    	
    //side menu
    $('#tbSideNav tr td').mouseover(function() {
        var sel = $(this).attr('id');
       if( sel != null && sel != ''){
           //onhover - change BG
		   changeSideNav(sel,sel+'_on');
       }
       
    }).mouseout(function() {
    	  var sel = $(this).attr('id');
          if( sel != null && sel != ''){
        	//onhover OUT - default
   		    changeSideNav(sel,sel+'_off');
   		   	//default
   		    var i = $('#tbSideNav').attr('class');
   		    changeSideNav(i,i+'_on');
          }
          
    }).click(function() {
        //onhover click
    	 var sel = $(this).attr('id');
           if( sel != null && sel != ''){
        	   if( lang == 'fr' ){
					if(sel == 'ServicesFR'){
						redirect('http://www.mwcfin.com/fr/service.php');
					}else if(sel == 'FinancingFR'){
						redirect('http://www.mwcfin.com/fr/financement.php');
					}else if(sel == 'ProgramsFR'){
						redirect('http://www.mwcfin.com/fr/programmes.php');
					}else if(sel == 'ContactFR'){
						redirect('http://www.mwcfin.com/fr/contactez_nous.php');
					}else if(sel == 'LocationFR'){
						redirect('http://www.mwcfin.com/fr/location.php');
					}
	           }else{
	        	   if(sel == 'Services'){
						redirect('http://www.mwcfin.com/service.php');
					}else if(sel == 'Financing'){
						redirect('http://www.mwcfin.com/financing.php');
					}else if(sel == 'Programs'){
						redirect('http://www.mwcfin.com/programs.php');
					}else if(sel == 'Contact'){
						redirect('http://www.mwcfin.com/contact_us.php');
					}else if(sel == 'Location'){
						redirect('http://www.mwcfin.com/location.php');
					}
	           }
           }
        });
     });

  function changeBG(x){
	  if( x != null && x != ''){
		  //alert('changeBG to => '+x);
		  $('#topNav').css("background-image", "url(http://www.mwcfin.com/etc/img/"+x+".gif)");
	  }
  }
  
  function changeSideNav(td_id,x){
	  if( x != null && x != ''){
		  $('#'+td_id+' > img').attr("src", "http://www.mwcfin.com/etc/img/side"+x+".gif");
	  }
  }
  
  function loadBG(x){
	  //alert('loadBG=> '+x);
	  if( lang == 'fr' ){
		  	//alert('fr');
		  changeBG('tfr_'+x);
	  }else{
		  //alert('t_'+x);
		  changeBG('t_'+x);
	  }
  }

  function redirect(x){
	  if( x != null && x != ''){
		  window.location.href = x;
	  }
  }
