﻿/**
 * This function allows the programmer to retrieve objects biased on the class name you 
 * want to retrieve. Similar to the GetElementByID and GetElementByTagName.
 * @member UtilNS
 * @param {object} oElm The object you want to search, could be a whole document or something more specific.
 * @param {string} strTagName The string containing the name of the tag name i.e. "a", "div", "span" what ever the class name is attached to.
 * If no tag is given it will search all elements.
 * @param {string} strClassName The string containing the class name you're searching for
 * @returns An array filled with the class names found in the search
 * @type Array
 * {@link  http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/#more-256 getElementsByClassName} Utility Function
 */


function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];		
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}	
	}
	return arrReturnElements;
}

$(document).ready(function(event){

// original from navigation
  $("#navmenu-h li,#navmenu-v li").hover(
    function() { $(this).addClass("iehover"); },
    function() { $(this).removeClass("iehover"); }
  );

  // ADD border on sub navigation
  $("ul#navmenu-v li li:first-child a").css("border-top","1px solid #2c2c2c");

/* START HOME 4 images, services */
    $("#a1").hover(
      function () {
		$("#img1").css("background-position","bottom");
      }, 
      function () {
        $("#img1").css("background-position","top");
      }
    );

	$("#a2").hover(
      function () {
		$("#img2").css("background-position","bottom");
      }, 
      function () {
        $("#img2").css("background-position","top");
      }
    );

    $("#a3").hover(
      function () {
		$("#img3").css("background-position","bottom");
      }, 
      function () {
        $("#img3").css("background-position","top");
      }
    );

    $("#a4").hover(
      function () {
		$("#img4").css("background-position","bottom");
      }, 
      function () {
        $("#img4").css("background-position","top");
      }
    );
/* END HOME 4 images, services */

/* START set height */

    var navheight = $("#structure").height();
    // navheight = navheight - 34;
    if (navheight <= 380)
    {
        navheight = 380;
    }
    else
    {
        navheight = navheight - 34;
    }

    $("#nav").height(navheight);
    
/* END set height */

	$(".SubmitImageButton").mouseover(function(){
	        $(this).attr("src","/images/btn-submit-off.jpg");
		}).mouseout(function(){
		    $(this).attr("src","/images/btn-submit-on.jpg");
		});



/*


	// Add first-child and last-child class
	$("#nav-main li:last-child").addClass("last-child");
	$("#nav-main li:first-child").addClass("first-child");
	
	$(".SubmitImageButton").mouseover(function(){
	        $(this).attr("src","images/btn-submit-over.jpg");
		}).mouseout(function(){
		    $(this).attr("src","images/btn-submit.jpg");
		});

*/
/*	// change color of nav link while hovering
	var temp = false;
	$("#nav li").mouseover(function(){
		   if ( $(this).hasClass("selected") )
		   {
			   temp=true;
			   return;
		   }
		   else
		   {
			   $(this).addClass("selected");
			   temp=false;
		   }
		}).mouseout(function(){
			if (!temp)
			{
		  		$(this).removeClass("selected");
			}
		});

	// change color of nav tab by adding the selected class - active page
	if ( $("#content").hasClass("homepage") )
	{
		$(".home").addClass("selected");
	}
	else if ( $("#content").hasClass("storepage") )
	{
		$(".store").addClass("selected");
	}
	else if ( $("#content").hasClass("faqpage") )
	{
		$(".faq").addClass("selected");
    }
*/

/*	$("#site-info li:last-child, #nav-top li:last-child, #nav-search li:last-child, .tbl-row > div:last-child, .graySolidBox div:last-child," +
	  "#nav-sub li:last-child, #banner li:last-child, li:last-child").addClass("last-child");
	$("#nav-top li:first-child, .graySolidBox div:first-child, .tbl-row > div:first-child, #banner li:first-child, li:first-child").addClass("first-child");
	
	
	$("#content-main .blueBoundBox").equalizeCols();
	$(".grayShade .tbl-col > div, .tbl-3col + .teachingBox .tbl-col").equalizeCols();
	$(".teachingBox + .teachingBox .tbl-col").equalizeCols();
	$(".tbl-3col .teachingBox").equalizeCols();
	
	$(".teachingBox .imgHolderSmall").each ( function () { 
		var height = $(this).parent().height();
		$(this).css("height", height);
	});
	
	$(".blueBoundBox .more-link, .grayShade .more-link").css({"position": "absolute", "width": "270px", "bottom": "10px"});
	$(".grayShade .more-link").css("bottom", 0);
	
	$(".tabbedPane ul").each( function() { 
		var totalWidth = $(this).width();
		var $aTags = $("a", $(this));
		var aTagsWidth = Math.floor((totalWidth - (20*$aTags.length + 2*$aTags.length-1))/$aTags.length);

		$aTags.each( function (a) {
			$(this).width( (a == $aTags.length-1) ? aTagsWidth+1 :aTagsWidth);
		});
	});
	

	$("#more").hover( function (){ $(".tbl-4col", $(this)).slideToggle("fast"); }, function (){ $(".tbl-4col", $(this)).slideToggle("fast"); });
*/	
	/*
	$("#home-form .submit").toggle (
		function () {
			$(this).css({"margin-top": "1px", "margin-right": "-1px"});	
		},
		function () {
			$(this).css({"margin-top": "0", "margin-right": "0"});	
		}
	);
	*/
/*
$("#search label").each( function () {
		var text = $(this).text();
		$(this)
			.next()
			.val(text)
			.focus( function () { $(this).val( ($(this).val() == text)? "" : $(this).val() );  })
			.blur( function () { $(this).val( ($(this).val() == "") ? text :  $(this).val());  })
			.end()
			.remove();	
	});
	
	if ( $.browser.mozilla) {
 	  //console.debug(" %s", $("#nav-top > ul").css("overflow"));
	  $("#nav-top > ul").css("overflow", "visible");
	  $(".teachingBox .tbl-row > .last-child").css("width", "46%");
	}
*/
});








/* =jQuery Plugins*/
(function($) {
		  
$.fn.equalizeCols = function() {
        var height = 0,
			reset = $.browser.msie ? "1%" : "auto";

        return this
			.css("height", reset)
			.each(function() {
			    height = Math.max(height, $(this).outerHeight(true));
			})
			.css("height", height)
			.each(function() {
			    var h = $(this).outerHeight(true);
			    if (h > height) {
			        $(this).css("height", height - (h - height));
			    };
			});

    };
	
	/*fill height to container**/
    $.fn.fill_height = function() {
        return this.each(function() {
			//console.debug("%s", $(this).attr("class"));
            var maxHeight = $(this).height();
            var sumChildrenHeights = 0;
            var children = $(this).children().not('.corner');
			//console.debug("%o %d", children, children.length);
            for(var i = 0, len = children.length; i < len; i++) {
                sumChildrenHeights = sumChildrenHeights + $(children[i]).outerHeight(true);
            }
			 
            var $lastchild = $(children[children.length - 1]);
			if($lastchild) {
            //console.debug("%o childHeight %d",$lastchild, sumChildrenHeights);
			$lastchild.height( ($lastchild.height() + (maxHeight - sumChildrenHeights)));
			}
        });
    };
	
})(jQuery);
