var options = 'menubar=0,scrollbars=1,resizable=1,';

function popup(url) {
	window.open(url, 'mypopup', options + 'height=600,width=600');
}

function popup2(url) {
	window.open(url, 'mypopup', options + 'height=500,width=900');
}

function main() {
	$("a[rel='external']").attr("target", "_blank");

	$("a.newWindow").click(function(e) {
		var self = $(this);
		var href = self.attr("href");

		popup(href);
		e.preventDefault();
	});

	$("a.newWindow2").click(function(e) {
		var self = $(this);
		var href = self.attr("href");

		popup2(href);
		e.preventDefault();
	});

	$(".infoBox").click(function() {
		// Get the address of the first link in the infobox
			var href = $("a", this).eq(0).attr("href");

			window.location = href;
		});

	$("#tabs").tabs( {
		select : function(event, ui) {
			// Open the trial page when the user clicks the trial tab
			if (ui.tab.hash == "#trial-tab") {
				popup('trial.php');
				return false;
			}

			// Open the contact page when the user clicks the contact tab
			if (ui.tab.hash == "#contact-tab") {
				popup('contact.php');
				return false;
			}
		}
	});

	var counter = 1;
	function rotateImage() {
		var img = $("#rotatingImage");
		var length = 4;
		img.attr("src", "images/eview_main" + counter + ".jpg");

		counter++;

		if (counter > length) {
			counter = 1;
		}

		setTimeout(rotateImage, 5000);
	}

	rotateImage();
}

$(document).ready(main);
