var loadInIframe = function(hash){
	var $trigger = $(hash.t);
	var $modal = $(hash.w);
	var myUrl = $trigger.attr('href');
	// Create iframe here to keep popup content out of browser history
	$(document.createElement('iframe'))
		.attr('allowtransparency','yes')
		.attr('height','100%')
		.attr('width','100%')
		.attr('scrolling','no')
		.attr('frameborder','0')
		.attr('marginwidth','0')
		.attr('marginheight','0')
		.attr('id','popup-content')
		.appendTo($modal); 
	var $modalContent = $("iframe", $modal);
	$modalContent.html('').attr('src', myUrl);
	//$modal.jqmShow();
	hash.w.show();
}

var loadInIframeFeat = function(myUrl){
	$(document.createElement('iframe'))
		.attr('allowtransparency','yes')
		.attr('height','100%')
		.attr('width','100%')
		.attr('scrolling','no')
		.attr('frameborder','0')
		.attr('marginwidth','0')
		.attr('marginheight','0')
		.attr('id','popup-content')
		.attr('src', myUrl)
		.appendTo('#modalWindow');
}

var iframeReset = function(hash){
	var $modal = $(hash.w);
	$('#popup-content').remove();
	$modal.css('display','none');
//	$('#modalWindow').find('iframe').attr('src', 'blank.html');
}

$(document).ready(function(){

	$("#featured-slides").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 4500, true);
	$("#featured-slides").hover(
		function() {
			$("#featured-slides").tabs("rotate",0,true);
		},
		function() {
			$("#featured-slides").tabs("rotate",4500,true);
		}
	);
	
	$('#modalWindow').jqm({
		modal: true,
		trigger: 'a.workpopup',
		target: '#jqmContent',
		onShow:  loadInIframe,
		onHide: iframeReset
	});
	
		
	$('.external').attr('target','_blank');
	
	$('form#contactform').validate();
	
	// Because IE7 was being a bitch.
	$('ul#topnav li a').html(null);

});