function in_array(needle, haystack) {
	var n = haystack.length;
	for (var i=0; i<n; i++) {
		if (haystack[i][1]==needle) {
			return (haystack[i][2]);
		}
	}
	return false;
}

$(document).ready(function(){
		
	// menu initialization
	$("#navigation").treeview({	
		animated: "fast",
		collapsed: true,
		persist: "location",
		unique: true	});
	
	// validate forms
	var signupValidate = $('form#oemProSubscription').validate({
		errorLabelContainer: $("div.oemProSubscriptionError"),
		rules: {
			FormValue_Email: {	required: true,	email: true	}
		},
		messages: {
			FormValue_Email: {	required: "Please enter an email",	email: "Must be an email address"	}
		}
	});
	
	// IE PNG fix
	$('img[@src$=.png], #tooltip-top, #tooltip-bottom').IEPNGHack();
	
	// set the h6 footer element to be the same as the title
	if ( $("h1").html() ) {
		var h6replace = $("h6.currentPage").html($("h1").html() + " page.");
	}
	
	// change the first word of H1 and H3 to a different color
	var h1Element=document.getElementsByTagName("h1");
	for (var i = 0; i < h1Element.length; i++) { 
		if ( $("h1:eq("+i+")").length > 0 )
		{	var broken_h1_string = $("h1:eq("+i+")").html().split(" ");
			for (j=0 ; j < broken_h1_string.length ; j++)
			{	if (j==0)
				{	newH1 = "<span style='color:#2C3940'>";	}
				newH1 = newH1 + broken_h1_string[j];
				if (j==0)
				{	newH1 = newH1 + "</span>";	}
				newH1 = newH1 + " ";
			}
			var h1FirstWord = $("h1:eq("+i+")").html(newH1);
		}
	}
	var h3Element=document.getElementsByTagName("h3");
	for (var i = 0; i < h3Element.length; i++) { 
		if ( $("h3:eq("+i+")").length > 0 )
		{	var broken_h3_string = $("h3:eq("+i+")").html().split(" ");
			for (j=0 ; j < broken_h3_string.length ; j++)
			{	if (j==0)
				{	newH3 = "<span style='color:#7f7f7f'>";	}
				newH3 = newH3 + broken_h3_string[j];
				if (j==0)
				{	newH3 = newH3 + "</span>";	}
				newH3 = newH3 + " ";
			}
			var h3FirstWord = $("h3:eq("+i+")").html(newH3);
		}
	}
	
	// center all images that are part of a showcase example
	var showcaseImg = $(".showcase img").wrap("<div align='center'></div>");
	
	// display the tooltip for the hovered tooltip word.
	$(".tooltip").hover(function () {
		title = $(this).attr("title");
		$(this).attr("title", "");
    	$(".tooltip").mousemove(function(e){
			var XPageCoords = e.pageX + 15;
			var YPageCoords = e.pageY + 15;
			$("#hidden-tooltip").css({ position:"absolute", top:YPageCoords, left:XPageCoords, display:"block" });
			$("#tooltip-center").html(title);
    	});    
	}, function () {
        $("#hidden-tooltip").css({ display:"none" });
		$(this).attr("title", title);
    });

	
});



function launchPopup(mediaURL, mediaWidth, mediaHeight) {
	if (mediaURL && window.open) {
		
		var periodPos = mediaURL.lastIndexOf('.');
		var mediaExt = mediaURL.substring(periodPos + 1);
		
		var popupURL = "http://www.chicagoproducers.com/" + mediaURL;
		var cpPopup = window.open("about:blank", "cpPopup", "width=50, height=50, scrollbars=no, resizable=no");
		cpPopup.close();
		cpPopup = window.open(popupURL, "cpPopup", "width=" + mediaWidth + ", height=" + mediaHeight + ", scrollbars=no, resizable=no");
		cpPopup.focus();
	}
}