// *******************************************
// TOGGLES THE DIV PASSED IN
function toggle(divname)
{
	var elem = document.getElementById(divname);
	var state = elem.style.display;
	var togImg = document.getElementById( divname + "_img" );
	
	if(state == "none"){
		elem.style.display = "block";
		if( togImg != null) togImg.src="images/minus.jpg";
	}
	else {
		elem.style.display = "none";
		if( togImg != null) togImg.src="images/plus.jpg";
	}
}
// *******************************************



// *******************************************
function checkemail( inEmail ){
	var str = inEmail;
	var testresults;

    if( inEmail == "" )
    {
        testresults = false;
    }
    else
    {
	    var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i

	    if (filter.test(str)) {
		    testresults = true;
	    }
	    else{
		    //alert("Please input a valid email address!");
		    testresults = false;
	    }
    }

	//alert("testresults = " + testresults);
	return (testresults)
}
// *******************************************


/********************************************************************************************************************/
/***************************************** * NAVIGATION * ***********************************************************/
/********************************************************************************************************************/
 
$(document).ready(function()
{ 
   
   	var timer;
    var timer2;
	var current;
    $("#mainNav > li").mouseover(function()
    {
       
		current = $(this).attr('class');
        $("#mainNav li:not(." + current + ") ul").stop(true, true).fadeOut(250);
        $("ul", this).stop(true, true).fadeIn(100);

        clearTimeout(timer);

    }).mouseout(function()
    {
       current = "";
	   timer = setTimeout(hideSubnav, 250);
    });
	 $("#mainNav > li ul").mouseover(function(){
							 clearTimeout(timer2);	   
	});
	function hideSubnav()
    {
        $("#mainNav li ul").stop(true, true).fadeOut(250);
    }
});


/********************************************************************************************************************/
/********************************************** * CONTENT TABS * ***************************************************/
/********************************************************************************************************************/

$(document).ready(function(){
			
	var maxDivs = 5;
	for (var x = 1; x <= maxDivs; x++)					   
	{
		var tab = "#tab_" + x;
		var div = "#content_" + x;
		if(x != 1)
		{
			$("#content_" + x).hide();
			
		}
		else
		{
			$("#tab_" + x).addClass("current");
		}
		clickTab(tab, div);
	}
	function clickTab(tab, div)
	{
		
		$(tab).click(function(){	
			for (var x = 1; x <= maxDivs; x++)					   
			{
				$("#content_" + x).hide();
				$("#tab_" + x).removeClass("current");
			}
			$(this).addClass("current");
			$(div).fadeIn(300);	
		});
	}
	clickTab("tab_1", "content_1");
	
});


/********************************************************************************************************************/
/***************************************** * entire div hightlightse * ***********************************************************/
/********************************************************************************************************************/

//$(document).ready(function(){
						   
	//$(".emphasis p, .emphasis li").click(function(){
    	//window.location=$(this).find("a").attr("href");return false;
	//});

//}); //close doc ready

$(document).ready(function(){
						   
	$(".emphasis p, .emphasis li").click(function() {
        	var thisLink = $(this).find("a");
        	if ( thisLink.attr('target') == '_blank') // If target=_blank then open in a new window
        	window.open(thisLink.attr("href"));
      else
          window.location=thisLink.attr("href");
      return false;
	});

}); //close doc ready



/********************************************************************************************************************/
/***************************************** * preload images * ***********************************************************/
/********************************************************************************************************************/

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)
$(document).ready(function(){
jQuery.preLoadImages("images/bg_headerWrapper.jpg", "images/subnav_top.png", "images/subnav_repeater.png", "images/subnav_bottom.png" );
});

//, "images/paperTop.gif", "images/paperRepeater.gif", "images/paperBottom.gif", "images/paperTopTwoCol.gif", "images/paperBottomTwoCol.gif", "images/paperRepeaterTwoCol.gif, "images/btn-davinci-products.png", "images/btn-technical-specs.png", "btn-architectural.png", "btn-sustainability.png", "images/btn-masterpiece.png"



