// JavaScript Document


	function MM_preloadImages() { //v3.0
		var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}
			
	
	var $cy=jQuery.noConflict();
	$cy(document).ready(function() {
	$cy('#travelling_tips_p').cycle({  
		    fx:     'scrollHorz',  
		    prev:   '#travelling_tips_prev',  
		    next:   '#travelling_tips_next',  
		    timeout: 0  
		});
	});
	
	
	var $scroll=jQuery.noConflict();
	$scroll(document).ready(function(){
		$scroll("#featured").tabs({
			fx:{opacity: "toggle"}
		}).tabs("rotate", 7000, true);
		$scroll('.ui-tabs-nav').jScrollPane();
	});

	
	var $sshow=jQuery.noConflict();	
	$sshow(document).ready(function() {
		$sshow('.slideShow').slideShow({
			interval: 5
		});
	});


	/*
	$gal = jQuery.noConflict();
	$gal(document).ready(function(){
		bannerRotator('#bannerRotator', 500, 5000, true);
	});
	*/

	
	$gal = jQuery.noConflict();
	$gal(document).ready(function(){
		$gal('#photos').galleryView({
			panel_width: 587,
			panel_height: 375,
			frame_width: 50,
			show_filmstrip_nav: false,
			show_panel_nav: true,
			has_filmstrip: true,
			has_panels: true,
			frame_height: 50
		});
	});
	
	

function showtab(id,path){
	document.getElementById(id).style.display="block";
	document.getElementById('tab1').src = path+'room1_button_slct.png';
	document.getElementById('tab2').src = path+'room2_button_slct.png';
	
	document.getElementById(id).style.display="";
	if(id=="firstblk"){
		document.getElementById('tab1').src = path+'room1_button_slct.png';
		document.getElementById('secondblk').style.display="none";
	
		var $j=jQuery.noConflict();
		$j("#adults_2_combo").attr("selectedIndex", 0);
		$j("#children_2_combo").attr("selectedIndex", 0);
		$j("#room2_child1_age_combo").attr("selectedIndex", 0);
		$j("#room2_child2_age_combo").attr("selectedIndex", 0);
		$j("#room2_child3_age_combo").attr("selectedIndex", 0);
        document.getElementById("room2_of_2_child1").style.display = "none";
        document.getElementById("room2_of_2_child2").style.display = "none";
        document.getElementById("room2_of_2_child3").style.display = "none";
	
	}
	if(id=="secondblk"){
		document.getElementById('tab2').src = path+'room2_button_slct.png';
	}

} // func ends 


function makeDynamicMenu(div_id) {
	var div1 = 'byresort';
	var div2 = 'bydestination';
	if (div_id == div1){
		document.getElementById(div2).style.display = 'none'
		document.getElementById(div1).style.display = 'block'
	}else{
		document.getElementById(div1).style.display = 'none'
		document.getElementById(div2).style.display = 'block'
	}
}  // func ends


function switchDiv(div_id)
{
	var style_sheet = getStyleObject(div_id);
	if (style_sheet)
	{
		hideAll();
		changeObjectVisibility(div_id,"visible");
	}
	else
	{
		alert("Sorry, this only works in browsers that do Dynamic HTML");
	}
} // func ends


function hideAll()
{
	changeObjectVisibility("byresort","hidden");
	changeObjectVisibility("bydestination","hidden");
} // func ends 


function getStyleObject(objectId){
	if(document.getElementById && document.getElementById(objectId)) {
		return document.getElementById(objectId).style;
	}
	else if (document.all && document.all(objectId)) {
		return document.all(objectId).style;
	}
	else if (document.layers && document.layers[objectId]) {
		return document.layers[objectId];
	}else{
		return false;
	}
} // func ends 


function changeObjectVisibility(objectId, newVisibility) {
	var styleObject = getStyleObject(objectId);
	if(styleObject){
		styleObject.visibility = newVisibility;
		return true;
	} else {
		return false;
	}
} // func ends 



function ShiftTo(DivID){
	Base=document.getElementById(DivID).parentNode;
	Sub=Base.getElementsByTagName('div');
	for (x=0;x<Sub.length;x++){
		if (Sub[x].parentNode==Base){
			if (Sub[x].id==DivID){
				Sub[x].style.display="block";
			}else{
				Sub[x].style.display="none";
			}  // else if ends 
		} // if ends 
	}  // for ends 
}  // func ends 



function changeBackground(strURL)
{
	document.getElementById('thediv').style.backgroundImage="url("+strURL+")";
}  // func ends 

var $pop=jQuery.noConflict();	

$pop(function () {
	$pop("#email_popup").dialog({
		autoOpen: false,
		show: "blind",
		hide: "explode",
		modal: true,
		width:"680px"
	});
	
	$pop("#sharemail_popup").dialog({
		autoOpen: false,
		show: "blind",
		hide: "explode",
		modal: true,
		width:"680px"
	});
	
	$pop("#callback_popup").dialog({
		autoOpen: false,
		show: "blind",
		hide: "explode",
		modal: true,
		width:"680px"
	});
	
	
	$pop("#facebook_popup").dialog({
		autoOpen: false,
		show: "blind",
		hide: "explode",
		modal: true,
		width:"680px"
	});
	
	
	$pop("#twitter_popup").dialog({
		autoOpen: false,
		show: "blind",
		hide: "explode",
		modal: true,
		width:"680px"
	});
});

FB.init({
appId  : '231239080234425',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml  : true  // parse XFBML
});

function submitShare(site)
{
	//var facebookLink = 'http://www.facebook.com/sharer.php?u=http://www.jamaicavacation.com&t=Vacation deal';
	var facebookLink = 'http://www.facebook.com/sharer.php?u=http%3A%2F%2Fwww.jamaicavacation.com%2F&t=Vacation%20deal';
	var twitterLink = 'http://twitter.com/home?status=Vacation deal';
	var share_url = '';
	if(site == 'facebook')
	{
		var share_text = jQuery("#yoursFBMessage").val();
		var publish = {
		  method: 'stream.publish',
		  message: share_text,
		  attachment: {
			name: 'View The Rate',
			caption: 'Jamaica Vacation',
			description: (
			  'The Best Place For Holiday! '
			),
			href: facebookLink
		  },
		  user_prompt_message: 'Share your Rate from Jamaica Vacation'
		};

		FB.ui(publish);
	}
	else
	{
		var share_text = jQuery("#yoursTWMessage").val();
		share_url = twitterLink.replace("Vacation Deal", encodeURIComponent(share_text));
		
		var oWin = window.open(share_url, '_blank');

		if (oWin.focus) 
		{ 
			oWin.focus();
		}
		
	}
}


function open_callback_dialog(resortName, resortDesc, rooms, adults, children){
	$pop("#callback_popup").dialog("open");
		document.getElementById('popup_resortName').value = resortName;
		document.getElementById('popup_resortDesc').value = resortDesc;
		document.getElementById('popup_rooms').value = rooms;
		document.getElementById('popup_adults').value = adults;
		//document.getElementById('popup_children').value = children;
	return false;
} // func ends


function open_sharemail_dialog(){
	$pop("#sharemail_popup").dialog("open");
	$pop("#emailFrdSubmit").attr("onClick","submitFriendsEmailForm();return false;");
	return false;
} // func ends


function open_facebook_dialog(resortName){
	$pop("#facebook_popup").dialog("open");
	str ="Found this great deal on a vacation to "+resortName;
	document.getElementById('yoursFBMessage').innerHTML = str;
	return false;
} // func ends 


function open_twitter_dialog(resortName){
	$pop("#twitter_popup").dialog("open");
	str ="Found this great deal on a vacation to "+resortName;
	document.getElementById('yoursTWMessage').value = str;
	return false;
} // func ends 


function submitFriendsEmailForm(){
	var estr = '';
	var eValues = document.getElementsByName('yourFriendEmail');
	for(var i=0; i<eValues.length;i++){
		if(i<(eValues.length-1)){
			estr += eValues[i].value+", ";
		} else {
			estr += eValues[i].value;
		}
	}
	document.getElementById('emailAddressValues').value = estr;
	document.getElementById('emailSubjectPop').value = document.getElementById('emailSubject').value;
	document.getElementById('emailMessagePop').value = document.getElementById('emailMessage').value;
	document.getElementById('getYourName').value = document.getElementById('yourName').value;
	document.getElementById('getYourEmail').value = document.getElementById('yourEmail').value;
	document.forms['purchasing.php'].submit();
	//alert(eValues);
	return false;
}


function open_email_dialog(vals){
	$pop("#email_popup").dialog("open");
	$pop("#emailSubmit").attr("onClick","submitEmailForm();return false;");
	return false;
}

function submitEmailForm(){
	var estr = '';
	// var eValues = document.getElementById('emailAdd').value;
	var eValues = document.getElementsByName('emailAdd');
	for(var i=0; i<eValues.length;i++){
		if(i<(eValues.length-1)){
			estr += eValues[i].value+", ";
		} else {
			estr += eValues[i].value;
		}
	}
	document.getElementById('emailAddressValues').value = estr;
	document.forms['purchasing.php'].submit();
	//alert(eValues);
	return false;
}

function removeInput(id){
	$pop("#"+id).slideUp("slow");	
}

function addInput(id,cnt,hideId)
{
	var tot = document.getElementsByName(cnt).length;
	var totnow = tot + 1; 
	var x = document.getElementById(id);
	
	x.innerHTML += '<table cellpadding="1" cellspacing="4" border="0" width="94%" align="center" id="rowId_'+totnow+'"><tr ><td width="30%" valign="top" align="left">Friend\'s Email Address:</td><td width="70%" valign="top" align="left"><input type="text" name="'+cnt+'" id="'+cnt+'_'+totnow+'" class="pop_tbox" />&nbsp;<span class="star">*</span>&nbsp;&nbsp;<a href="javascript:void(0);" onclick="removeInput(\'rowId_'+totnow+'\');">Remove</a></td></tr></table>';
	if(totnow == 5){
		document.getElementById(hideId).style.display = 'none';	
	}
}


function SameBillingAddress(Obj)
{
	if(Obj.checked==true)
	{
		document.getElementById('billing_address1').value = document.getElementById('shipping_address1').value;
		document.getElementById('billing_address2').value = document.getElementById('shipping_address2').value;
		document.getElementById('billing_city').value = document.getElementById('shipping_city').value;
		document.getElementById('billing_state').value = document.getElementById('shipping_state').value;
		document.getElementById('billing_zip').value = document.getElementById('shipping_zip').value;
		
	}
}



function trim(str)
{
	if(str.length>0){
		var i=0;
		while(str.charAt(i)==" ")
		{
		i++;
		}
		str=str.substring(i,str.length);
		len=str.length-1;
		while(str.charAt(len)==" ")
		{
		len--;
		}
		str=str.substring(0,len+1);
	} // if str is not empty
	return str;
}

