/* new Jquery section */
jQuery(function($){
	
	$('#megabannerfade')
	  .innerfade({ speed: 2000, timeout: 6000, type: 'sequence', containerheight: '366px'});	
	 
	/* temp - make header banners click through to deal page 
	$('#headoverlay.bannerautolink').css('cursor', 'pointer').click(function(){
	  if(!$(this).is('a'))
		document.location.href = 'http://www.ayersrockresort.com.au/sunrise/';
	});*/
	
	/* --- Start Video Handling --- */
	// test for html5 video support
	var temp_video = document.createElement('video') || false;
	var html5_video_supported = temp_video && typeof temp_video.canPlayType !== "undefined";
	
	$('#head_overlay_video').click(function(){
		$('#videooverlay, #videobox').show();
		clearTimeout(_innerfade);
		VideoJS.setupAllWhenReady();
		$('#videobox video').height(272);
		setTimeout(function(){
			$('#videobox video').each(function(){
				if(html5_video_supported) this.play();
			});
		},250);
		
		return false;
	});
	
	$('#videobox_close').click(function(){
	  $('#videobox video').each(function(){
		  if(html5_video_supported) this.pause(); 
		  else {
		    $('#videobox object').remove();
		    $('#head_overlay_video').remove();
		  }
		  $('#megabannerfade')
		  .innerfade({ speed: 2000, timeout: 6000, type: 'sequence', containerheight: '366px'});
	  });	 		
	  $('#videooverlay, #videobox').hide(); 
	});
	/* --- End Video Handling --- */
	
	$('#frmSearch #q').focus(function(){
	  if($(this).val() == 'SEARCH')
	  {
	    $(this).val('');
	  }
	}).blur(function(){
	  if($(this).val() == '')
	  {
        $(this).val('SEARCH');
      }		
	});
	
	// Home Valley Redirection
	var overlay_styles = {
			zIndex: 10,
			position: 'absolute',
			top: 0,
			left: 0,
			width: '100%',
			height: $("body").height(),
			background: 'transparent url(/images/overlay.png)',
			opacity: 0.8
		};
	
	var overlay_box_styles = {
			zIndex: 11,
			position: 'absolute',
			top: 0,
			left: ($("body").width() - 500) / 2 + 'px',
			width: '500px',
			margin: 'auto',
			height: '300px',
			background: '#ffffff url(/images/homevalley-red-logo.jpg) bottom right no-repeat',
			padding: '20px',
			border: '4px solid #ffd6c8'
		};	
	$('a.hv_external, #sub_resorts a[href*="hvstation.com.au"]').live('click', function(){
		overlay_box_styles.top = ($(window).height() - 300) / 2 + $(window).scrollTop() + 'px';
		var redirect_url = $(this).attr('href');
		var overlay_html = $('<div></div>').css(overlay_styles);
		var box_html = $('<div><strong>Redirecting...</strong><p>Please wait a few seconds ' +  
				'while we take you directly to:<br /><br /><strong>' + 
				'<a href="' + redirect_url + '">Home Valley Station</a></strong></p></div>')
				.css(overlay_box_styles);		
		$("body")
			.append(overlay_html)
			.append(box_html)
			.find('object, embed, #sub_resorts')
			.remove();
		setTimeout(function(){
			document.location.href = redirect_url;
		}, 2500);
		return false;
	});
	
});

var browser=navigator.userAgent.toLowerCase();
var isFF=((browser.indexOf('mozilla')!=-1) && (browser.indexOf('spoofer')==-1) && (browser.indexOf('compatible')==-1) && (browser.indexOf('opera')==-1) && (browser.indexOf('webtv')==-1) && (browser.indexOf('hotjava')==-1));
var isIE=((browser.indexOf("msie")!=-1) && (browser.indexOf("opera")==-1));
var isOP=(browser.indexOf("opera")!=-1);

function openwindow(url) {
    var options = 'scrollbars=yes,resizable=yes,status=no,toolbar=no,menubar=no,location=no';
    options += ',width=' + screen.availWidth + ',height=' + screen.availHeight;
    options += ',screenX=0,screenY=0,top=0,left=0';
    var win = window.open(url, '', options);
    win.focus();
    win.moveTo(0, 0);
    win.resizeTo(screen.availWidth, screen.availHeight);
}


// ************* NEW WINDOW *************
// This is used for opening a link in a new window (since we cant use target="_blank" in xhtml)
function jump(sLocation)
{
window.open(sLocation, '_blank');
}

// ************* POPUP WINDOW *************
// This is used for generating a pop-up window
function winPop(sLocation,sWidth,sHeight,sScrollbars)
{
window.open(sLocation, '', 'toolbar=0,resizable=1,scrollbars=' + sScrollbars + ',left=2,top=2,width=' + sWidth + ',height=' + sHeight);
}

// ************* POPUP WINDOW WITH STATUS BAR *************
// This is used for generating a pop-up window
function winPopWithStatus(sLocation,sWidth,sHeight,sScrollbars)
{
window.open(sLocation, '', 'toolbar=0,resizable=1,status=1,scrollbars=' + sScrollbars + ',left=2,top=2,width=' + sWidth + ',height=' + sHeight);
}

// ************* POPUP IMAGE WINDOW *************
// This is used for poping up a window with a large image
// when the user clicks a thumbnail.
function imagePop(imgFile,imgWidth,imgHeight)
{
window.open('/includes/viewimage.asp?page=' + escape(location.href) + '&img=' + imgFile, '', 'toolbar=0,resizable=0,scrollbars=0,left=2,top=2,width=' + imgWidth + ',height=' + imgHeight);
}

// ************* POPUP VR WINDOW *************
// This is used for poping up a window of virtual tours
// when the user clicks a thumbnail.
function vrPop(imgId)
{
window.open('/includes/virtual_tour_view.asp?id=' + imgId, '', 'toolbar=0,resizable=0,scrollbars=0,left=2,top=2,width=490,height=330');
}

// ************* SUBSCRIBER FUNCTIONS *************
// These are used with the email subscriber box.
function submitEmail(){
window.open('','PopUp','resizable=1,scrollbars=1,width=600,height=470'); 
document.getElementById('subscribe').target = 'PopUp';
document.getElementById('subscribe').submit();
}

function clearField(){
if (document.getElementById('subscribe').EAddy.value =='Your email here!')
	 { 
		(document.getElementById('subscribe').EAddy.value ='');
	 }
}
function galleryEmailSubmit(){
window.open('/email_add.asp','PopUp','resizable=0,scrollbars=1,width=500,height=300');
}
SwapMap = 0;

function swapMap(sDirectory){
	if (SwapMap == 0){
	document.images.LocationMap.src = '/images/' + sDirectory + '/map_on.gif';
	SwapMap = 1;
	}else{
	document.images.LocationMap.src = '/images/' + sDirectory + '/map.gif';
	SwapMap = 0;
	}
}

function launchSelfDrive(){
	window.open('/includes/self_drive_virtual_tour.asp','PopUp','resizable=0,scrollbars=0,left=2,top=2,width=750,height=550');
}

function SendWithUrl(sNewLocation)
{window.location.href = sNewLocation + '?page=' + escape(document.location);}  

function CreatePDF(){
	alert('PDF will now be created - this may take a few moments.\nWhen the download box appears, please select "Save" to save the file to your computer.');
}

function CaratTrack(sTrackingId){
	var dd = new Date();
	var ord = Math.round(Math.abs(Math.sin(dd.getTime()))*1000000000)%10000000;
	var adsfac_image = new Image(1,1);
	adsfac_image.src = 'http://adsfac.net/pct_mx.asp?L='+sTrackingId+'&amp;ref='+escape(top.document.referrer)+'&amp;url='+escape(top.document.URL)+'&amp;ord='+ord;
}


function openflashpopup(el,filepath){
	var flashelementtext = "\<div style\=\"text\-align\:right\; padding\-right\:10px\;\"\>\<a href\=\#\ onclick\=\"closeflashpopup\(this\)\; return false\;\"><img src=\"\/images\/icons\/close.gif\" border\=\"0\" \/\>\<\/a\><\/div\><object classid\=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase\=\"http\:\/\/download\.macromedia\.com\/pub\/shockwave\/cabs\/flash\/swflash\.cab\#version=7\,0\,0\,0\" height\=\"330\" width\=\"409\"\>\<param name\=\"movie\" value\=\"" + filepath + "\" \/\>\<param name\=\"quality\" value\=\"high\" \/\>\<embed height\=\"330\" pluginspage\=\"http:\/\/www\.macromedia\.com\/go\/getflashplayer\" quality\=\"high\" src\=\"" + filepath + "\" type\=\"application\/x-shockwave-flash\" width\=\"409\" \/\>\<\/object\>";
	   		
	el.parentNode.parentNode.getElementsByTagName('div')[0].innerHTML=flashelementtext;
	el.parentNode.parentNode.getElementsByTagName('div')[0].style.display='block';	
}

function closeflashpopup(el) {		
	el.parentNode.parentNode.style.display='';	
	el.parentNode.parentNode.innerHTML='';		
}
