
/*
 * newWindow 1.1 - jQuery plugin for adding new window functionality to links.
 * http://www.alexanderdickson.com/projects/jquery-plugins/newwindow/
 *
 * Copyright (c) 2009 Alex Dickson
 * Licensed under the MIT licenses.
 * See website for more info.
 *
 * Date: 2009-08-22 09:03:00 +1000 (Sunday, 23 Aug 2009)
 */

 (function($){  
  $.fn.newWindow = function(options) {   
    var defaults = {
		titleText: 'Link opens in a new window'
	};	
	var options = $.extend(defaults, options);   
     return this.each(function() {  
	   var obj = $(this);
       if ( ! obj.is('a')) {
           return;
       };
	   if (options.titleText != '') {   
		   if (obj.attr('title')) {
				var newTitle = obj.attr('title') + ' (' + options.titleText + ')';
		   } else {
				var newTitle = options.titleText;   
		   };		   
		   obj.attr('title', newTitle);   
	   };
	   obj.click(function(event) {
	   	  event.preventDefault();  
		  var newBlankWindow = window.open(obj.attr('href'), '_blank');
		  newBlankWindow.focus();
		}); 
	   });
  };  
 })(jQuery); 


$(function() {

	if ($('#content_more a').text() !== 'CONTACT US') return;
	

	var contentBox = $('#content_box');
	var contentText = $('#content_text');
	
	contentBox.css({ backgroundImage: 'none' });

	contentText.css({ top: 0, height: '420px', paddingTop: '50px' });
	
	$('#content_header').remove();

});



// stopping spam

$(function() {

    var $inputRow = $('#matangi-spam')

    $inputRow.find('input').val('Matangi');
    
    $inputRow.hide();
    
    $('a[rel=external]').newWindow();

});

//ELEMENT POSITIONS

function getElementTop(Elem) {

		if(document.getElementById) {	
			var elem = document.getElementById(Elem);
		} else if (document.all) {
			var elem = document.all[Elem];
		}
		yPos = elem.offsetTop;
		tempEl = elem.offsetParent;
		while (tempEl != null) {
  			yPos += tempEl.offsetTop;
	  		tempEl = tempEl.offsetParent;
  		}
		return yPos;
	}



function getElementLeft(Elem) {
	
		var elem;
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		xPos = elem.offsetLeft;
		tempEl = elem.offsetParent;
  		while (tempEl != null) {
  			xPos += tempEl.offsetLeft;
	  		tempEl = tempEl.offsetParent;
  		}
		return xPos;
	
}




//POP UP SCRIPT

/*
Usage Description:
"this.href" refers to the URL given in the "a" tag; "'popup'" is the name of the popup window;
600 is the width of the popup window; 500 is the height of the popup window; the numbers that
follow designate whether a property is turned on ("1") or off ("0"), in this order:
scrollbars, resizable, menubar, toolbar, addressbar, statusbar, fullscreen
*/

function newWindow(a_str_windowURL, a_str_windowName, a_int_windowWidth, a_int_windowHeight, a_bool_scrollbars, a_bool_resizable, a_bool_menubar, a_bool_toolbar, a_bool_addressbar, a_bool_statusbar, a_bool_fullscreen) {
  var int_windowLeft = (screen.width - a_int_windowWidth) / 2;
  var int_windowTop = (screen.height - a_int_windowHeight) / 2;
  var str_windowProperties = 'height=' + a_int_windowHeight + ',width=' + a_int_windowWidth + ',top=' + int_windowTop + ',left=' + int_windowLeft + ',scrollbars=' + a_bool_scrollbars + ',resizable=' + a_bool_resizable + ',menubar=' + a_bool_menubar + ',toolbar=' + a_bool_toolbar + ',location=' + a_bool_addressbar + ',statusbar=' + a_bool_statusbar + ',fullscreen=' + a_bool_fullscreen + '';
  var obj_window = window.open(a_str_windowURL, a_str_windowName, str_windowProperties)
    if (parseInt(navigator.appVersion) >= 4) {
      obj_window.window.focus();
    }
}




function doPanel() {
	
	if (returnObjById('action')) {
	
	
		if (returnObjById('action').innerHTML=='open') {
			
			closePanel();
			returnObjById('action').innerHTML='closed';
		} else {
			
			openPanel();
			returnObjById('action').innerHTML='open';
		}
		
		
		
		
	} else {
	
			if (returnObjById('open_close').innerHTML!='') {
				
				
				

					openPanel();
					
			
			
			
			returnObjById('open_close').innerHTML='';
			returnObjById('open_close2').innerHTML='';
			
			} else {
				
				
			closePanel();	
				
			
			
			returnObjById('open_close').innerHTML='<a href="javascript:doPanel();">';
			returnObjById('open_close2').innerHTML='</a>';
			}
	
	}
	
	
}





//old browsers getelementbyid

function returnObjById( id )
{
    if (document.getElementById)
        var returnVar = document.getElementById(id);
    else if (document.all)
        var returnVar = document.all[id];
    else if (document.layers)
        var returnVar = document.layers[id];
    return returnVar;
}







function closePanel() {
	
	returnObjById('action').innerHTML='closed';
	
			  $("#content_text").animate({ 
					top: "+=360px",
					height: "35px",
					opacity: 0.75
					
				  }, 1500 );
				  
			
				if (returnObjById('drag_bar0')) {
				   returnObjById('drag_bar0').style.display='none';
				}
			
			returnObjById('go').style.display='block';
				  returnObjById('close_box').style.display='none';
    
	
	
	
	
}







	function openPanel() {
		
		if (returnObjById('more_info_box')) {
							document.getElementById('more_info_box').style.display='none';
		}
	 //open text box
				
				returnObjById('action').innerHTML='open';
				
				  $("#content_text").animate({ 
					top: "-=360px",
					//height: "388px",
					height: "400px",
					opacity: 0.9 }, 1500 );
				  
				
					
				  returnObjById('go').style.display='none';
				  returnObjById('close_box').style.display='block';
				  
				  
				  
				  if (returnObjById('errorbox')) {
				  returnObjById('errorbox').style.display='none'
				  }
				
				
				//				alert(returnObjById('res_box').style.top);
				
				
				if (returnObjById('res_box').style.top == "152px") {
				
			 $("#res_box").animate({ 
										height: "0px", top: "-=20px"
					
					
					
				  }, 500 );
			 
			 
				}
			 // returnObjById('res_box').style.display='none';
			
			
				
			
			
			
			$("#content_text").queue(function () {
											   
				   	if (returnObjById('drag_bar0')) {
					returnObjById('drag_bar0').style.display='block';
					}
					$(this).dequeue();
					
				  });


	
		
	}


//sliding panel jQuery code edited by Alex

 $(document).ready(function(){
  
    
    // Using multiple unit types within one animation.
    $("#go").click(function(){
      
			  openPanel();




    });
	
	
	
	

	
	
	
	
	
	
	
	
	
	
	
	








    // Using multiple unit types within one animation.
    $("#close_box").click(function(){
   
			   
			   //close text box
		closePanel();
				
	
	});

























  
    // Using multiple unit types within one animation.
    $("#reservation_link_button").click(function(){
   
   
   
   
   
  
//  alert(returnObjById('res_box').style.display);
  if (returnObjById('res_box').style.display=='' || returnObjById('res_box').style.display=='table-cell' || returnObjById('res_box').style.height < "100px" ) {
  
  
   if (returnObjById('res_form')) {
   
   				  
				
  	
				
			//	closePanel();
				
			}
				  
				 
				 returnObjById('res_box').style.display='block';
			  
			  $("#res_box").animate({ 
								height: "107px", 
								
				top: "+=20px"
				
			  }, 500 );
			  
			  
			  if (returnObjById('errorbox')) {
						  returnObjById('errorbox').style.display='none'
						  }
			  
			  
			 
			  if (returnObjById('close_box')) {
				  
				   //alert(section);
						 if ((returnObjById('close_box').style.display=='block') ||  section=="dropit") {
						//	 alert(returnObjById('close_box').style.display);
						// if ((returnObjById('close_box').style.display=='block')) {
									closePanel();
									
						  
						  } 
								}
				  
   
			  
	  
  }
	  
	  
							
	  
	  
    });




  




  });
 
 
 
 
 
 
 
    
   function changeVar() {
	   
	   section='liftit';
	  // alert(section);
	   
   }
		
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 //remove scroll bar if exists
 
 
 
 function removeScroll() {
	 
	
		if (returnObjById('drag_bar0')) {
			 returnObjById('drag_bar0').style.display='none';
			
		}
	 
 }
 
 
 
 
 
 // check date form, make sure it validates
 
 function checkFields() {

if (document.check.startdate.value!='' && document.check.enddate.value!='' && document.check.startdate.value!='dd/mm/yyyy' && document.check.enddate.value!='dd/mm/yyyy') {


returnObjById("form_stuff").style.display = 'none';
returnObjById("checking_stuff").style.display = 'block';
returnObjById("checking_stuff").style.height = '20px';
returnObjById("loading_box").style.display = 'block';



if (video==true) {
	
	
document.check.submit();
} else {

InitializeTimer('res','3');

}


}
else {

alert('Please enter both an arrival and departure date.');
}

}
 
 
 

 
 

 
 
 
 
 
 
 
 
 //timer thanks to mcfedries, modified by alex
 
 var secs
var timerID = null
var timerRunning = false
var delay = 1000
var whattodo;

whattodo=''

function InitializeTimer(dowhat,seconds)
{
    // Set the length of the timer, in seconds
    secs = seconds
    StopTheClock()
	
	
    StartTheTimer(dowhat)
}

function StopTheClock()
{
    if(timerRunning)
        clearTimeout(timerID)
    timerRunning = false
}

function StartTheTimer(dothis)
{

	if (whattodo=='') {
whattodo=dothis;	
	}


//alert(whattodo);

    if (secs==0)
    {
        StopTheClock()
       
	   //in this case submit the form!
	  //  alert(whattodo);
		
		
	   if (whattodo=='res') {
	   
	   document.check.submit();
	   
	   }
	   
	   else if (whattodo=='video') {
		    	//alert(whattodo);
	   returnObjById("video_cont").style.background = 'url("images/outro_movie.jpg")';
	   }
	   
	     else if (whattodo=='img') {
		    	//alert(whattodo);
	   returnObjById("loading_box").style.display = 'none")';
	   }
	   
	   
    }
    else
    {
        self.status = secs
        secs = secs - 1
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay)
    }
}

 
 
 
 
 
 
 
 
 
 
 
 
//function to show different images

function showImage(imagename, folder, imgno) {
	
	//InitializeTimer('img','1');
	
	returnObjById("loading_box").style.display = 'block';
	

returnObjById("content_box").style.background = 'url(\'images/articles/' + folder + '/' + imagename + '\')';
	
	
	
	for (x=0;x<totalimgs-1;x++) {
		
	//alert(x);
	returnObjById("image_display" + x).src='images/white_square.gif';
	
	}
	returnObjById("image_display" + imgno).src='images/white_square_on.gif';
	
	
	setInterval('hideLoader()', 1500);
	
}
 
 
  
  
  
  
  //postcard preview stuff
  
  
  function previewBack() {
	  
	   returnObjById("preview_back").style.display = 'block';
	  returnObjById("preview_front").style.display = 'none';
	  
	returnObjById("messagetext").innerHTML=returnObjById("texta").value;  
	  
	  fromstring = returnObjById("from").value + '<BR>' + returnObjById("send_email").value ; 
	  
	returnObjById("fromstuff").innerHTML=  fromstring;
	
	
		returnObjById("recievestuff").innerHTML=  'Receiver<BR>' + returnObjById("recieve").value + '<BR>' + returnObjById("recieve_email").value;
	 
	 returnObjById("phototitle").innerHTML= 'Title: ' + returnObjById("selectimage").value;	 
  }
  

   
   
   function previewFront() {
	   
	   returnObjById("loading_box").style.display = 'block';
	   
	    returnObjById("preview_front").style.display = 'block';
	    returnObjById("preview_back").style.display = 'none';
		
		
		
		//numberimg = document.postcard.p_image.selectedIndex + 1;
		
		numberimg = returnObjById("selectimage").selectedIndex + 1;
		
	   // returnObjById("preview_front").style.background = 'url("images/postcards/card" +  numberimg + ".jpg")';
		returnObjById("preview_image").src="images/postcards/card" +  numberimg + ".jpg";
		
		 hideLoader();
		 
   }
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   //hide loading
   
   
   function hideLoader() {
	   
	   
	   if (returnObjById('loading_box')) {
	returnObjById('loading_box').style.display='none'   
	   }
   }
   
   
   
   
	
  
  
  
  //validate email
  
function isValidEmail(str) {


var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
return (filter.test(str));


   return (str.indexOf(".") > 1) && (str.indexOf("@") > 0);
 


}









//LIVE FIJI CLOCK







// function to calculate local time
// in a different city
// given the city's UTC offset
function calcTime(city, offset) {


city="Fiji";
offset="+12";

    // create Date object for current location
    d = new Date();
   
    // convert to msec
    // add local time zone offset
    // get UTC time in msec
    utc = d.getTime() + (d.getTimezoneOffset() * 60000);
	
	
	//document.getElementById('clock_box').innerHTML=('offset: '+d.getTimezoneOffset());
	
	debug_date = new Date(utc);

//alert(debug_date);

    // create new Date object for different city
    // using supplied offset
    nd = new Date(utc + (3600000*offset));
   
   //document.getElementById('clock_box').innerHTML=('gmt:'+debug_date + '\n\nfiji-time:' + nd);

   

   
    // return time as a string
   // alert("The local time in " + city + " is " + nd.toLocaleString());
	
	today = nd;
	
	 var second = today.getSeconds();
 var minute = today.getMinutes();
 
 
 
 
 var hour   = ((today.getHours()));
 var hour24 = ((today.getHours()));
 
  
 var local_hour   = ((today.getHours()));
 var local_hour24 = ((today.getHours()));
	
	

 
 
 //alert(hour);
 var ampm   = "";
 
 var day    = today.getDay();
 var date   = today.getDate();
 var month  = today.getMonth();
 var year   = today.getFullYear();
 
 var days   = new Array();
  days[0]   = "Sunday";
  days[1]   = "Monday";
  days[2]   = "Tuesday";
  days[3]   = "Wednesday";
  days[4]   = "Thursday";
  days[5]   = "Friday";
  days[6]   = "Saturday";
  
 var mns   = new Array();
  mns[0]   = "January";
  mns[1]   = "February";
  mns[2]   = "March";
  mns[3]   = "April";
  mns[4]   = "May";
  mns[5]   = "June";
  mns[6]   = "July";
  mns[7]   = "August";
  mns[8]   = "September";
  mns[9]   = "October";
  mns[10]  = "November";
  mns[11]  = "December";
   
 if(second<10)
  {
   second = "0"+second;
  }
 if(minute<10)
  {
   minute = "0"+minute;
  }
 if((hour24)<12)
  {
   ampm = "AM";
  }
 else
  {
   ampm = "PM"
  }
 if(hour24>=12)
  {
  hour= hour-12;
  }
 if(hour24==0)
  {
  hour=12;
  }
  
  
  if (hour==0) { hour=12 };
	
if (returnObjById("live_clock")) {
document.getElementById('live_clock').innerHTML=("FIJI-TIME: "+(hour)+":"+minute+":"+second+" "+ampm);

}


document.getElementById('clock_box').innerHTML=("<span id=\"phone_number\">TOLL FREE: 1-888-628-2644</span> &gt; <span id=\"matangi_time\"> MATANGI ISLAND TIME: "  +(hour)+":"+minute + " "+ ampm+"</span>");



 
 var today  = new Date();
 var second = today.getSeconds();
 var minute = today.getMinutes();
 
 
 
 
 var hour   = ((today.getHours()));
 var hour24 = ((today.getHours()));
 
  
 var local_hour   = ((today.getHours()));
 var local_hour24 = ((today.getHours()));
 

 
 //alert(hour);
 var ampm   = "";
 
 var day    = today.getDay();
 var date   = today.getDate();
 var month  = today.getMonth();
 var year   = today.getFullYear();
 
 var days   = new Array();
  days[0]   = "Sunday";
  days[1]   = "Monday";
  days[2]   = "Tuesday";
  days[3]   = "Wednesday";
  days[4]   = "Thursday";
  days[5]   = "Friday";
  days[6]   = "Saturday";
  
 var mns   = new Array();
  mns[0]   = "January";
  mns[1]   = "February";
  mns[2]   = "March";
  mns[3]   = "April";
  mns[4]   = "May";
  mns[5]   = "June";
  mns[6]   = "July";
  mns[7]   = "August";
  mns[8]   = "September";
  mns[9]   = "October";
  mns[10]  = "November";
  mns[11]  = "December";
   
 if(second<10)
  {
   second = "0"+second;
  }
 if(minute<10)
  {
   minute = "0"+minute;
  }
 if((hour24)<=12)
  {
   ampm = "AM";
  }
 else
  {
   ampm = "PM"
  }
 if(hour24>=12)
  {
  hour= hour-12;
  }
 if(hour24==0)
  {
  hour=12;
  }


document.getElementById('print_clock').innerHTML=(days[day] + ' ' + date + " " + mns[month] + ' ' + year + ' ' + (hour)+":"+minute+":"+second+" "+ampm);
} 
 

							



	

	
	






//print

function makePrint() {
	
	if  (returnObjById("textholder")) {

var stripped = returnObjById("textholder").innerHTML.replace(/(<a([^>]+)>)/ig,""); 

returnObjById("printarttext").innerHTML=stripped;




	}
}

function printThis() {
	
	window.print();  

	
	
}
















//validate forms


 
function cFV(checkwhat) {
	 
	 
	
	 
	 if (checkwhat=='res') {
	 
	 	var email = $('#res_form #email').val();
	 
		if (returnObjById("fullname").value=='') {
		
		
			alert('You must enter a valid name.');
			
		} else if ( ! isValidEmail(email) ) {
		
			alert('You need a valid email');
		
		
		
		
		} else if (returnObjById("bure").selectedIndex ==0 ) {
			
			alert('You must select a bure.');	
		
		} else {
		
			returnObjById("reserve").submit();
			returnObjById('loading_box').style.display='block';
		}
		 
	 
	 }
	 
	 
	if (checkwhat=='taf') {
	
	
	if ((returnObjById("from").value=='') || (returnObjById("ur_email").value=='') || (returnObjById("toname").value=='...')|| (returnObjById("toemail").value=='...') || (isValidEmail(returnObjById("ur_email").value)==false)|| (isValidEmail(returnObjById("toemail").value)==false) ) {
	
	alert('You must enter all information, with valid emails.');	
		} 
		else {
		
		returnObjById("taf_form2").submit();
		
		returnObjById('loading_box').style.display='block';
		
	
	}
	 
	 }



if (checkwhat=='postcard') {
	

	
	if ((returnObjById("from").value=='') || (returnObjById("recieve").value=='') || (returnObjById("texta").value=='...')||(isValidEmail(returnObjById("send_email").value)==false)|| (isValidEmail(returnObjById("recieve_email").value)==false) ) {
	
	alert('You must enter all information, with valid emails.');	
		} 
		else {
		returnObjById("img_index").value = returnObjById("selectimage").selectedIndex + 1;
		returnObjById("send_postcard").submit();
		returnObjById('loading_box').style.display='block';
		
	
	}
	 
	 }



if (checkwhat=='enquiry') {
	
	
	if ((returnObjById("fullname").value=='') || (returnObjById("enquiry").value=='') || (isValidEmail(returnObjById("em").value)==false)) {
	
	alert('You must enter all information, with a valid email.');	
		} 
		else {
		
		returnObjById("contact_matangi").submit();
		returnObjById('loading_box').style.display='block';
		
	
	}
	 
	 }





if (checkwhat=='subscribe') {
	
	
	if ( (isValidEmail(returnObjById("your_email").value)==false)) {
	
	alert('You must enter a valid email.');	
		} 
		else {
		
		returnObjById("subscribe").submit();
		returnObjById('loading_box').style.display='block';
		
	
	}
	 
	 }

	 
 }





// home page animations


function slideMovie() {


returnObjById("video_cont").style.display='block';
  $("#video_cont").animate({ 
								height: "288px", top: "-=288px" 
								
				
				
			  }, 1500 );

  
 
 
			$("#video_cont").queue(function () {
											   
				  
  
  so.write("video_cont");
  InitializeTimer('video','10');
					$(this).dequeue();
					
				  });
 
 
}

function hidePlayer() {

returnObjById("video_cont").style.background = 'url("images/outro_movie.jpg")';
returnObjById("video_cont").innerHTML='<img src="images/outro_movie.jpg">'
  $("#video_cont").animate({ 
								height: "1px", top: "+=288px" 
								
				
				
			  }, 1500 );

  
 
 
			$("#video_cont").queue(function () {
											   
				  
  
  returnObjById("video_cont").style.display='none';
					$(this).dequeue();
					
				  });
	
}





//PRELOAD BURE IMAGES
