$(document).ready(function() {
	/* Highslide */
	hs.registerOverlay({ overlayId:'closebutton', position:'top right', fade:2 });
	
	// #nav
	// sfHover()
	$(".rollover").hover(
		function(){
			if($(this).attr("src").indexOf("-hover") == -1) {
				var newSrc = $(this).attr("src").replace(".gif","-hover.gif#hover");
				$(this).attr("src",newSrc);
			}
		},
		function(){
			if($(this).attr("src").indexOf("-hover.gif#hover") != -1) {
				var oldSrc = $(this).attr("src").replace("-hover.gif#hover",".gif");
				$(this).attr("src",oldSrc);
			}
		}
	);

	$("#newsletter-salutation").focus( function() {
		if ( $(this).val() == "Your name" ) {
			$(this).val('');
		}
		$(this).removeClass("hint");
	});

	$("#newsletter-email").focus( function() {
		if ( $(this).val() == "Your email" ) {
			$(this).val('');
		}
		$(this).removeClass("hint");
	});

	$("#newsletter-form").submit( function() {
		newsletterSubscribe();
		return false;
	});
});

function newsletterSubscribe() {
	$.getJSON(
		'_gateway/newsletter.cfc',
		{ method: 'subscribe', email: $('#newsletter-email').val(), salutation: $('#newsletter-salutation').val() },
		function(data) {
			//Set new value
			alert( data.MSG );
			
			if ( data.SUCCESS == 1 ) {
				$('#newsletter-email').val('Your email').addClass('hint');
				$('#newsletter-salutation').val('Your name').addClass('hint');
			}
		}
	);
}


/* ----------------------
   Scripts
---------------------- */

function mailingList() {
	alert( 'mailing list' );
	return false;
}

function sfHover() {
	if (document.all&&document.getElementById) {
		var sfEls = document.getElementById("nav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" over";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" over\\b"), "");
			}
		}
	}
}


/* Popup:
popup(URL, Width, Height, Left, Top, AutoCenter[0=False, 1=True], FullScreen[0=False, 1=True])
<a href="javascript:popUp('domain', 640, 480, 50, 50, 1, 0)">Popup!</a>
*/
function popup(URL, popWidth, popHeight, popLeft, popTop, autoCenter, fullScreen) {
	day = new Date();
	id = day.getTime();
	if ( autoCenter == 1 ) {
		var popLeft = (screen.width - popWidth) / 2;
		var popTop = (screen.height - popHeight) / 2;
	}
	if ( fullScreen == 1 ) {
		// Open in Full Screen window!
		eval("page"+id+" = window.open(URL, '"+id+"', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+(screen.width-10)+",height="+(screen.height-26)+",left=0,top=0');");
	} else {
		// Open in normal window!
		eval("page"+id+" = window.open(URL, '"+id+"', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+popWidth+",height="+popHeight+",left="+popLeft+",top="+popTop+"');");
	}
}