// Global JavaScripts
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 and 6.
{
	if ((jQuery.browser.msie) && (jQuery.browser.version < 7)) 
    {
       for(var i=0; i<document.images.length; i++)
       {
	      var img = document.images[i]
	      var imgName = img.src.toUpperCase()
	      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	      {
		     var imgID = (img.id) ? "id='" + img.id + "' " : ""
		     var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		     var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		     var imgStyle = "display:inline-block;" + img.style.cssText 
		     var imgAttribs = img.attributes;
		     for (var j=0; j<imgAttribs.length; j++)
			 {
			    var imgAttrib = imgAttribs[j];
			    if (imgAttrib.nodeName == "align")
			    {		  
			       if (imgAttrib.nodeValue == "left") imgStyle = "float:left;" + imgStyle
			       if (imgAttrib.nodeValue == "right") imgStyle = "float:right;" + imgStyle
			       break
			    }
             }
		     var strNewHTML = "<span " + imgID + imgClass + imgTitle
		     strNewHTML += " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	         strNewHTML += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		     strNewHTML += "(src='" + img.src + "', sizingMethod='scale');\""
		     if (imgClass.indexOf("rollover") != 0) { strNewHTML += " onmouseover=\"PNGswap('" + img.id + "');\" onmouseout=\"PNGswap('" + img.id +"');\"" }
		     strNewHTML += "></span>" 
		     img.outerHTML = strNewHTML
		     i = i-1
	      }
       }
   }
}

function PNGswap(myID)
{
   var strOver  = "-over"
   var strOff = "-off"
   var oSpan = document.getElementById(myID)
   var currentAlphaImg = oSpan.filters(0).src
   if (currentAlphaImg.indexOf(strOver) != -1)
      oSpan.filters(0).src = currentAlphaImg.replace(strOver,strOff)
   else
      oSpan.filters(0).src = currentAlphaImg.replace(strOff,strOver)
}




/* Just add class="rollover" to the img tag and make sure your images are named whatever-off.gif and whatever-over.gif */
/* You can use any kind of images and name them what you like.  The "off" and "-over" are the only parts that matter */
function initrollovers() {
	var aPreLoad = new Array();
	var sTempsrc;
	var aImages = $("img.rollover, input.rollover");
	for (var i = 0; i < aImages.length; i++) {
		var src = aImages[i].getAttribute('src');
		var ftype = src.substring(src.lastIndexOf('.'), src.length);
		var hsrc = src.replace('-off'+ftype, '-over'+ftype);
		aImages[i].setAttribute('hsrc', hsrc);
		aPreLoad[i] = new Image();
		aPreLoad[i].src = hsrc;
		aImages[i].onmouseover = function() {
			sTempsrc = this.getAttribute('src');
			this.setAttribute('src', this.getAttribute('hsrc'));
		}
		aImages[i].onmouseout = function() {
			if (!sTempsrc) sTempsrc = this.getAttribute('src').replace('-over'+ftype, '-off'+ftype);
			this.setAttribute('src', sTempsrc);
		}
	}
} 

/* On page load */
$(function() {
	// Fix PNG Transparency and initialize rollover graphics
	correctPNG();
	initrollovers();
	
	// Dropdown Nav
	$('#mainNav ul').superfish({
		autoArrows:  false,
		dropShadows: false,
		delay: 0,
		disableHI: true
	}); 
	
	// Function for Register box
	$("#register").hover(function() {
		$(this).find("div").show();
		$("#ddlIndustry").mouseleave(function(event) { event.stopPropagation(); });
	}, function() {
		$(this).find("div").hide();
		$("#ddlIndustry").mouseleave(function(event) { event.stopPropagation(); });
	});
	
	// Function for Interested In? box
	$("#interestedBtn").hover(function() {
		$(this).find("ul").fadeIn();
	}, function() {
		$(this).find("ul").fadeOut();
	});
	
	// Accordion Functions
	if ($(".accordion").length > 0) {
		$(".accordion").accordion({animated: false, autoHeight: false, collapsible: true, active: false, header: 'h3'});
		
		$("h3.ui-state-active").live("mouseover", function() {
			$(this).next().addClass("ui-accordion-content-active-hover");
		}).live("mouseout", function() {
			$(this).next().removeClass("ui-accordion-content-active-hover");
		});
	}
	
	// Timeline Promo
	if ($("#timelinePromo").length > 0) {
		$(".timeline").hover(function() {
			var tablink = $(this).find("a").attr("href");
			$(tablink).show();
			
			var offsetposition = (tablink.substr(tablink.length-1, 1) * 56);
			
			$("#timelinePromo ul").css("background-position", "0 -"+offsetposition+"px");
		}, function() {
			$($(this).find("a").attr("href")).hide();
			$("#timelinePromo ul").css("background-position", "0 0");
		});
		$(".timeline a").click(function() {
			return false;
		});
	}
	
	// Callout box rollovers
	if ($(".callout").length > 0) {
		$(".callout").mouseover(function() {
			$(this).addClass("calloutOver");
		}).mouseout(function() {
			$(this).removeClass("calloutOver");
		}).click(function() {
			var promolink = $(this).find("a").attr("href");
			var promotarget = $(this).find("a").attr("target");
			if (promotarget=="_blank") {
				window.open(promolink);
			} else {
				location.href = promolink;
			}
			return false;
		});
	}
	
	// Contact Form
	if ($("#formContactUs").length > 0) {
		$("#formContactUs").validate({
			messages: {
				direccion: {
					email: 'Esta dirección de correo no es válida'
				}
			}		
		});	
	}
	
	/* FIXES TITLE BAR TO HAVE TOP LEVEL PARENT DISPLAYED */
	var linkHref = $('#mainNav ul li.active a').attr("href");
	var linkName = $('#mainNav ul li.active a').html();
	$('a.topParentTitle:not(a.topParentTitle.locked)').html(linkName);
	$('#titleBG #title a').attr("href", linkHref);
});



