function isDefined(property) {
	return (typeof property != 'undefined');
}

function externalLinks() {
	if (!document.getElementsByTagName) {
		return;
	}
	var anchors = document.getElementsByTagName("a");
	for (var i=0;i<anchors.length;i++) { 
		var anchor = anchors[i];
		if ((anchor.getAttribute("href")) && (anchor.getAttribute("rel") == "external")) {
			anchor.target = "_blank";
		}
	}
}

function blurLinks() {
	lnks = document.getElementsByTagName("a");
	inpts = document.getElementsByName("input");
	for(i=0;i<lnks.length;i++) {	
		if ((lnks[i].getAttribute("rel") == null) || (lnks[i].getAttribute("rel") == "")) {
			lnks[i].onfocus = new Function("this.blur()");
		}
	}
	for(i=0;i<inpts.length;i++) {
		inpts[i].onfocus= new Function("this.blur()");
	}
}

function slideSwitch(id,speed) {
	if (!speed) {
		speed = 1000;
	}
	var $holder = $(id);
	var $active = $holder.find(".active");
	if ($active.length == 0) {
		$active = $holder.find("DIV:last");
	}
	var $next = $active.next().length ? $active.next() : $holder.find("DIV:first");
	$active.addClass("last-active");
	$next.css({opacity: 0.0})
	$next.addClass("active")
	$next.animate({opacity: 1.0}, speed, function() { $active.removeClass("active last-active"); });
}

function jQueryFunctions() {
	$(document).ready(function() {
		if ($("#ImagesInner")) {
			setInterval("slideSwitch('#ImagesInner')", 5000);
		}
		if (document.getElementById("tabContent")) {
			var tabs = $("#tabContent").tabs();
		}
	});
}

function gallerySlider() {
	if (document.getElementById("Gallery")) {
		stepcarousel.setup({
			galleryid: 'Gallery', //id of carousel DIV
			beltclass: 'belt', //class of inner "belt" DIV containing all the panel DIVs
			panelclass: 'panel', //class of panel DIVs each holding content
			autostep: {enable:false, moveby:1, pause:3000},
			panelbehavior: {speed:500, wraparound:false, wrapbehavior:'slide'},
			defaultbuttons: {enable: true, moveby: 1, leftnav: ['/images/buttons/left.gif', 390, 396], rightnav: ['/images/buttons/right.gif', -430, 396]},
			statusvars: ['statusA', 'statusB', 'statusC'], //register 3 variables that contain current panel (start), current panel (last), and total panels
			contenttype: ['inline'] //content setting ['inline'] or ['ajax', 'path_to_external_file']
		});
	}
}

function loadFlash() {
	if (document.getElementById("Promo")) {
		var so = new SWFObject("/flash/sportwagen_animation.swf", "Flash Map", "930", "380", "6", "#000000");
		so.addParam("wmode", "transparent");
		so.write("Promo");	
	}
}

function logOut() {
	question = "Are you sure you wish to logout?";
	if (confirm(question)) {
		URL = "/admin/logout.php";
		window.location.href= URL;
	}
}

if (isDefined(window.addEventListener)) {
	window.addEventListener("load", RunFunctions, false);
}

else if (isDefined(window.attachEvent)) {
	window.attachEvent("onload", RunFunctions);
}

function RunFunctions() {
	externalLinks();
	blurLinks();
	loadFlash();
	jQueryFunctions();
	gallerySlider();
	if (eval(window.adminLoadFunctions) != undefined) {
		adminLoadFunctions();
	}
}


