// scripts.js

// CONSTANTS
var clinicalStudiesDir = 'tiles/clinicalstudies/';
var clinicalStudy1URL = clinicalStudiesDir + 'clinicalstudy1.htm';
var clinicalStudy2URL = clinicalStudiesDir + 'clinicalstudy2.htm';
var clinicalStudy3URL = clinicalStudiesDir + 'clinicalstudy3.htm';
var clinicalStudy4URL = clinicalStudiesDir + 'clinicalstudy4.htm';
var clinicalStudy5URL = clinicalStudiesDir + 'clinicalstudy5.htm';

// JQuery loading function
jQuery().ready(function(){
		// Initialise the menu
		jQuery('#navigation').Accordion({
			active: false,
			header: '.head',
			navigation: true,
			event: 'mouseover',
			autoheight: true
		});
});


// Initialisation function
function init() {
	// Fix up any PNG images that are present on the page
	correctPNG();
}

// newFunction
function setHighlight(id) {
	var elem = document.getElementById(id);
	elem.className = 'menuItem_highlight';
}

function removeHighlight(id) {
	var elem = document.getElementById(id);
	elem.className = 'menuItem';
}

function submitContactForm(privacyID, form) {
	if (!document.getElementById(privacyID).checked) {
		alert("You must have read and agreed with our Privacy Statement");
	} else {
		form.submit();
	}
}

function linkHighlight(element, show) {
	if (show == true) {
		element.style.color = '#d9000d';
	} else {
		element.style.color = 'navy';
	}
}

// Opens a new window at a given url. Adds the current timestamp to the name of the new window, 
// to ensure it is unique and always open up a new window.
//  Author: Liam Tong
function openNewWindow(name, url) {
	var windowName = name + (new Date()).valueOf();
	window.open(url, windowName, 'scrollbars=yes,menubar=no');
}

function correctPNG() {
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);
	
	if ((version >= 5.5) && (document.body.filters)) {
	
		for (var i=0; i<document.images.length; i++) {
			var img = document.images[i];
			var imgName = img.src.toUpperCase();
			// Filtering for PNGs and ignoring the horizontal separator
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG"
					&& imgName.substring(imgName.length-9, imgName.length) != "H_SEP.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;
				if (img.align == "left") imgStyle = "float:left;" + imgStyle;
				if (img.align == "right") imgStyle = "float:right;" + imgStyle;
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
					+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
					+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
					+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
				img.outerHTML = strNewHTML;
				i = i - 1;
			}
		}
	}    
}

// bind to change event of select to control first and seconds accordion
// similar to tab's plugin triggerTab(), without an extra method
jQuery('#switch select').change(function() {
	jQuery('#navigation').activate( this.selectedIndex-1 );
});
jQuery('#close').click(function() {
	jQuery('#navigation').activate(-1);
});
jQuery('#switch2').change(function() {
	jQuery('#navigation').activate(this.value);
});

