/* 
  2009 Copyright Project Play
  MassCommute
  Master Javascript file
  Created 10.7.09 by Mike Kivikoski  
  Last edited 10.20.09 by Rachel Donovan
  
  Table of Contents
  
  Navigation Functions
  
  Calculator Functions
  
  Start jQuery
    1.Drop Shadow
    2.Accordian
    3.Table Rows
    
    
    IE6 Fixes.
        
        Png Fixes
        
        
*/

/*Navigation functions: */
function show_f(sub_class, sub_nav_color, position, current_class){  
	  hide_all_sub();
    $(sub_class).css("display","inline");
	  $("#sub_nav_bar").css("background-color", sub_nav_color);
	  $(current_class).css("background-position", position);
	  $("#sub_nav_bar").css("display","inline");
   };
	
function hide_all_sub(){
	  $(".default_sub").css("display", "none");
	  $(".fc_sub").css("display", "none");
	  $(".fe_sub").css("display", "none");
	  $(".fs_sub").css("display", "none");
	  $(".ff_sub").css("display", "none");
	  reset_tabs();
};

function reset_tabs(){
	 $("a.fc").css("background-position", "0 0");
	 $("a.fe").css("background-position", "-160px 0");
	 $("a.ff").css("background-position", "-324px 0");
   $("a.fs").css("background-position", "-486px 0");
   $("#sub_nav_bar").css("display","inline");
}

/* Calculator functions: */
function CalcCosts() {
	try {
		document.getElementById("cm").value = "error";

		document.getElementById("cy").value = "error";

		var a, b, c, d, e, f, g;
		a = Number(document.getElementById("qa").value);
		b = Number(document.getElementById("qb").value);
		c = Number(document.getElementById("qc").value);
		d = Number(document.getElementById("qd").value);
		e = Number(document.getElementById("qe").value);
		f = Number(document.getElementById("qf").value);
		g = Number(document.getElementById("qg").value);

		document.getElementById("cm").value = Math.round(((a*b/c*d) + (a*b*e) + (b*f) + g)*100)/100;

		document.getElementById("cy").value = Math.round(document.getElementById("cm").value * 12 * 100)/100; 

		if (document.getElementById("cm").value == "NaN") document.getElementById("cm").value = "";
		if (document.getElementById("cy").value == "NaN") document.getElementById("cy").value = "";

	} catch(e) {
	
		document.getElementById("cm").value = "";

		document.getElementById("cy").value = "";
	}
	
	
}


/*When Page loads*/

    $(document).ready(function(){
        
        // 1.
       $(".promotion").dropShadow({left: 2, right: 2, top: 4, blur: 3});
       
       // 2.
       $('#planner').accordion({
            header: 'div.title',
			autoheight: true
            
	});
       
      // 3.
      $("tr:even").css("background-color", "#fff");
      $("tr:odd").css("background-color", "#e8e8e8");
      
      
      // 4.
          $("#top_logo").hover(
		function() {show_f(".default_sub", "#0033FF", "0 0", "#main_nav_img_cont");});

               $(".fc").hover(
                       function() {show_f(".fc_sub", "#4b873d", "0 39px", "a.fc");});	
                   
               $(".fe").hover(
                       function() {show_f(".fe_sub", "#990066", "-160px -44px", "a.fe");});
       
               $(".ff").hover(
                       function() {show_f(".ff_sub", "#ff9933", "-324px -45px", "a.ff");});
               
               $(".fs").hover(
                       function() {show_f(".fs_sub", "#cc0000", "-486px -44px", "a.fs");});
       
       
       
      // 5.
         
         //This determines the 'default' styling of the navigation. Since we don't know what lang
         //we are using yet, this is determined with jQuery. On the sub pages place their common class
         //on their body tag.
            //commuter pages have the class of 'commuter'
            //employers pages have the class of 'employers'
            //families pages have the class of 'families'
            //schools pages have the class of 'schools'
            
         //Commuter
         //if($('body').hasClass('commuter')){
        //    show_f(".fc_sub", "#4b873d", "0 39px", "a.fc");
        //  };
         
         //Employers 
         //if($('body').hasClass('employers')){
         //   show_f(".fe_sub", "#990066", "-160px -44px", "a.fe");
         // };
         // 
         ////Families
         //if($('body').hasClass('families')){
         //   show_f(".ff_sub", "#ff9933", "-324px -45px", "a.ff");
         // };
         // 
         ////Schools
         //if($('body').hasClass('schools')){
         //   show_f(".fs_sub", "#cc0000", "-486px -44px", "a.fs");
         // };
          
          //homepage
          //there was a bug that on intial load the tabs all were set to the first tab, this just resets the
          //tabs to a default position.
           if($('body').hasClass('home')){
              reset_tabs();
            };
          

       
       //IE6 Fixes
       if ($.browser.msie && $.browser.version <= 6 ) {
        
         //Assign classes to elements that IE6 can't read. This is certain form elements and CSS3 properties
         $('input[type=text]').addClass('input-text');
         $('.dropShadow').css({'display':'none'});//Currently hides the JS dropShadow
         
          
            //PNG Fix - Use the CSS Selector to fix the broken PNG images.
            // DD_belatedPNG.fix('#main_nav_img_cont img, #search, #go, #calculate, .promotion h1, .promotion h1 strong, .promotion h2, #footer img, .calc img, #newsletter_signup input#btn-newsletter, .promotion3 img, td img, #top_logo img');
            $('body').supersleight({shim: '/images/x.gif'});
        
       }
       
       //IE7 Fixes
       if ($.browser.msie && $.browser.version <= 7 ) {
       	 // when the url has a # in it the drop shadow for the promotion div would be displayed overlapping
       	 // the left side of the nav.  Remove it for now.
         $('.dropShadow').css({'display':'none'});//Currently hides the JS dropShadow
       }
       
       
       
    }); //End jQuery