var _lang = {};
var _popupbox = null;
var _gallery = null;
var _videogallery = null;
_lang['bookmark'] = 'Bookmark ';
$(document).ready(function() {
_popupbox = $(".popup_box").overlay({
top: 20,
expose: {
color: '#ffffff',
loadSpeed: 200,
opacity: 0.5
},
closeOnClick: true,
api: true
});
$.fn.extend(_popupbox, {
setTitle: function(content) {
this.getOverlay().find('.popup_box_title').html(content);
},
setContent: function(content) {
this.stopLoading();
this.getOverlay().find('.popup_box_content').html(content);
},
openContent: function(content) {
this.stopLoading();
this.setContent(content);
this.load();
},
startLoading: function() {
var cnt = this.getOverlay().find('.popup_box_content');
cnt.empty();
cnt.addClass('ajax-loading');
},
stopLoading: function() {
var cnt = this.getOverlay().find('.popup_box_content').removeClass('ajax-loading');
},
setWidth: function(width) {
this.getOverlay().width( width );
}
});
// refresh all rates
var allratesform = $('#allratesform');
if (allratesform) {
allratesform.submit(function(){
var url = 'remote?method=getPackageRates';
$.ajax({
type: "POST",
url: url,
dataType: 'json',
data: '&' + allratesform.serialize() + '&tmp=1',
beforeSend: function() {
$('#allrates').empty();
$('#allrates').addClass('ajax-loading');
},
success: function(jsonObj) {
$('#allrates').html(jsonObj.data);
$('#allrates').removeClass('ajax-loading');
if (jsonObj.minCabins) {
updateMinPrices(jsonObj.minCabins);
}
}
});
return false;
});
var adult = $('select[name=adult]');
var child = $('select[name=child]');
adult.change(function(){
child.empty();
optionChild = '<option value="0">0</option>';
var max = 4-$(this).val()+1;
for (var i=1; i<max; i++) {
optionChild += '<option value="' + i + '">' + i + '</option>'
}
child.append(optionChild);
return false;
});
}
// create a bookmark
var bookmark =$('#bookmark');
if (bookmark) {
bookmark.bind('click', function(event){
var bookLink = window.location.toString().replace('#','');
bookLink = bookLink.split('?a=');
bookLink = bookLink[0];
bookLink += (bookLink.indexOf('?')<0) ? '?bookmark=1' : '&bookmark=1';
window.status=_lang['bookmark']+bookLink;
if (window.sidebar) { // firefox
window.sidebar.addPanel(document.title, bookLink, "");
} else if(window.opera && window.print) { // opera
var elem = document.createElement('a');
elem.setAttribute('href',bookLink);
elem.setAttribute('title',document.title);
elem.setAttribute('rel','sidebar');
elem.click();
} else if(document.all) { // ie
window.external.AddFavorite(bookLink, document.title);
} else {
alert("Please press CTRL + D shortcut or CMD + D (for Mac) in order to bookmark this site.")
}
event.preventDefault();
});
}
// subscribe to a newsletter
var newsletterform = $('#newsletterform');
if (newsletterform) {
newsletterform.submit(function(){
var url = 'remote?method=subscribeNewsletter';
$('#javascriptrespDiv').remove();
$.ajax({
type: "POST",
url: url,
dataType: 'json',
data: '&' + newsletterform.serialize() + '&tmp=1',
beforeSend: function() {
newsletterform.before('<div id="javascriptrespDiv" class="newsletters"></div>');
$('#javascriptrespDiv').addClass('ajax-loading');
},
success: function(jsonObj) {
$('#javascriptrespDiv').remove();
newsletterform.before('<div id="javascriptrespDiv" class="newsletters">' + jsonObj.data + '</div>');
$('#javascriptrespDiv').click(function(){ $(this).remove() });
$('#javascriptrespDiv').removeClass('ajax-loading');
}
});
return false;
});
}
var fields = ['#newsletterform input[name=Email]', '#newsletterform input[name=Name]', '#searchform2 input[name=code]', '.sitesearchform input[name=q]'];
$.each(fields, function(index, lable){
$(lable).bind('focus', function(){
if ($(this).val() == '(enter email address here)' || $(this).val() == '(enter your first name)'
|| $(this).val() == '(enter cruise code/name)' || $(this).val() == 'Search Cruise Sale Finder')
{
$(this).val('').css('color','#000');
}
}).bind('blur',function(){
if (!$(this).val())
{
if ($(this).attr('name') == 'Email')
{
$(this).val('(enter email address here)').css('color','#666');
}
else if ($(this).attr('name') == 'Name')
{
$(this).val('(enter your first name)').css('color','#666');
}
else if ($(this).attr('name') == 'code')
{
$(this).val('(enter cruise code/name)').css('color','#666');
}
else if ($(this).attr('name') == 'q')
{
$(this).val('Search Cruise Sale Finder').css('color','#666');
}
}
});
});
$('#addToShortlist').click(function() {
//Add a package id to the shortlist for this user
$.ajax({
type: 'POST',
url : 'remote?method=addToShortlist',
dataType: 'json',
data: {
packageId: $('#packageId').val()
},
beforeSend: function() {
//Update the interface to show that the package is being saved
$('#addToShortlist').hide();
$('#shortlistMessage').html('Saving...').show();
},
success: function(result) {
console.log(result);
//Hide the loading message
$('#shortlistMessage').hide();
if (result && result.status && result.status === true) {
//Show the link to remove from shortlist
$('#removeFromShortlist').show();
$('#addToShortlist').hide();
} else {
//There was a problem - show the link to add to shortlist
$('#addToShortlist').show();
$('#removeFromShortlist').hide();
alert('Could not save to the shortlist.');
}
},
failure: function(result) {
alert('Could not save to the shortlist.');
//Hide the loading message
$('#shortlistMessage').hide();
//Show the add link again
$('#addToShortlist').show();
$('#removeFromShortlist').hide();
}
});
});
$('#removeFromShortlist').click(function() {
//Remove a package id from the shortlist for this user
$.ajax({
type: 'POST',
url : 'remote?method=removeFromShortlist',
dataType: 'json',
data: {
packageId: $('#packageId').val()
},
beforeSend: function() {
//Update the interface to show that the package is being removed
$('#removeFromShortlist').hide();
$('#shortlistMessage').html('Removing...').show();
},
success: function(result) {
//Hide the loading message
$('#shortlistMessage').hide();
if (result && result.status && result.status === true) {
//Show the link to add to shortlist
$('#addToShortlist').show();
$('#removeFromShortlist').hide();
} else {
//There was a problem - show the link to remove from shortlist
$('#removeFromShortlist').show();
$('#addToShortlist').hide();
alert('Could not remove package from the shortlist.');
}
},
failure: function(result) {
alert('Could not remove package from the shortlist.');
//Hide the loading message
$('#shortlistMessage').hide();
//Show the remove link again
$('#removeFromShortlist').show();
$('#addToShortlist').hide();
}
});
});
createPopups();
createGallery();
});
function createPopups() {
createPopupWins();
createTooltip();
}
function createTooltip() {
var tooltips = $('a.tooltip').get();
$.each(tooltips, function(index, lable){
var title = $(lable).attr('title');
$(lable).bind('mouseover', function (event){
var pLeft = $(lable).offset().left - 25;
var pTop  = $(lable).offset().top + 30;
var cont = title;
if (cont == 'span')
cont = $(lable).find('span') .html();
$('.tooltip_box_btm').html(cont);
$('.tooltip_box').css({ 'left' : pLeft + 'px', 'top' : pTop + 'px' });
if (title) $('.tooltip_box').show();
$(lable).removeAttr('title');
});
$(lable).bind('mouseout', function (event){
$('.tooltip_box').hide();
$(lable).attr('title', title );
});
});
}
function createPopupWins() {
var popups = $('a.popup').get();
$.each(popups, function(index, lable){
$(lable).bind('click', function (event){
loadPopup ($(lable).attr('rel'));
event.preventDefault();
});
});
}
function loadPopup (rel) {
_popupbox.load();
// Load template to popup
var url = 'remote?method=getInfo';
$.ajax({
type: "POST",
url: url,
dataType: 'json',
data: 'data=' + rel + '&tmp=1',
beforeSend: function() {
_popupbox.startLoading();
},
success: function(jsonObj) {
_popupbox.setTitle(jsonObj.title);
_popupbox.setContent(jsonObj.data);
}
});
}
function sendQuote(item) {
var url = 'remote?method=sendOffer';
$.ajax({
type: "POST",
url: url,
dataType: 'json',
data: '&' + $('#quoteform').serialize() + '&tmp=1',
beforeSend: function() {
_popupbox.startLoading();
},
success: function(jsonObj) {
_popupbox.setContent(jsonObj.data);
}
});
}
function sendShortlist() {
//Send the shortlist to an email address
$.ajax({
type: 'POST',
url : 'remote?method=sendShortlist',
data: {
email: $('#sendShortlistEmail').val()
},
beforeSend: function() {
_popupbox.startLoading();
},
success: function(jsonObj) {
_popupbox.setContent(jsonObj.data);
}
});
}
function createGallery() {
if ($(".gallery_box").length == 0) return;
_gallery = $(".gallery_box").overlay({
top: 20,
expose: {
color: '#666666',
loadSpeed: 200,
opacity: 0.5
},
closeOnClick: true,
api: true
});
$(".gallery_box .gallery_box_scroll").scrollable({
items: '.gallery_box .gallery_box_items',
vertical: true,
size: 6
}).mousewheel();
var gal = $(".gallery_box .gallery_box_scroll").scrollable();
$.fn.extend(gal, {
add: function(imgs) {
var self = this;
if ( !self.imgRepo )
self.imgRepo = new Array;
$.each(imgs, function(idx,lbl){
$(lbl).click(function(e) {
_gallery.load();
self.click( $(this).attr('rel') );
self.getItems().filter('.active').click();
e.preventDefault();
});
var position = jQuery.inArray( $(lbl).attr('href'), self.imgRepo );
if ( position < 0 ) {
position = self.getSize();
self.imgRepo[ position ] = $(lbl).attr('href');
var img = new Image();
var thumb = $(lbl).find('img');
if (thumb) {
img.src = thumb.attr('src');
img.rel = $(lbl).attr('href');
img.title = thumb.attr('alt');
}
else {
img.src = $(lbl).attr('href');
img.rel = '';
img.title = $(lbl).attr('title');
}
self.getItemWrap().append( img );
$(img).click(function(e) {
var url = $(this).attr("rel");
if ( !url )
url = $(this).attr("src");
var wrapimg = $(".gallery_box .gallery_box_image");
var wrap = wrapimg.find("img").fadeTo("medium", 0.5);
var img = new Image();
img.onload = function() {
wrap.attr("src", url);
var qtf = ( ( wrapimg.height() / img.height ) < ( wrapimg.width() / img.width ) ) ? ( wrapimg.height() / img.height ) : ( wrapimg.width() / img.width );
wrap.height( img.height * qtf );
wrap.width( img.width * qtf );
if ( wrap.height() < wrapimg.height() ) {
wrap.css( 'padding-top', ( ( wrapimg.height() - wrap.height() ) / 2 ) );
}
else {
wrap.css( 'padding-top', 0 );
}
wrap.fadeTo("fast", 1);
$(".gallery_box span.gallery_box_count").html( (self.getClickIndex()+1) + ' / ' + self.getSize() );
};
img.src = url;
_gallery.getOverlay().find('.gallery_box_title').html( this.title );
});
}
$(lbl).attr('rel', position);
});
self.reload().end();
self.getItems().filter(":first").click();
}
});
gal.add( $('a.imgpopups') );
$(".gallery_box a.gallery_box_prev").bind('click', function(e){
gal.click(gal.getClickIndex()-1);
gal.getItems().filter('.active').click();
$(".gallery_box span.gallery_box_count").html( (gal.getClickIndex()+1) + ' / ' + gal.getSize() );
e.preventDefault();
});
$(".gallery_box a.gallery_box_next").bind('click', function(e){
gal.click(gal.getClickIndex()+1);
gal.getItems().filter('.active').click();
$(".gallery_box span.gallery_box_count").html( (gal.getClickIndex()+1) + ' / ' + gal.getSize() );
e.preventDefault();
});
}
function createVideoGallery() {
if ($(".video_box").length == 0) return;
_videogallery = $(".video_box").overlay({
top: 20,
expose: {
color: '#666666',
loadSpeed: 200,
opacity: 0.5
},
closeOnClick: true,
api: true
});
$(".video_box .gallery_box_scroll").scrollable({
items: '.video_box .gallery_box_items',
vertical: true,
size: 6
}).mousewheel();
var gal = $(".video_box .gallery_box_scroll").scrollable();
$.fn.extend(gal, {
add: function(htmlcode, thumbnail, titl) {
var self = this;
if ( !self.imgRepo )
self.imgRepo = new Array;
var position = jQuery.inArray( thumbnail, self.imgRepo );
if ( position < 0 ) {
position = self.getSize();
self.imgRepo[ position ] = thumbnail;
var img = new Image();
img.src = thumbnail;
img.rel = htmlcode;
img.title = titl;
self.getItemWrap().append( img );
$(img).click(function(e) {
var wrapimg = $(".video_box .gallery_box_image");
wrapimg.html( $(this).attr("rel") );
});
}
self.reload().end();
self.getItems().filter(":first").click();
},
addAction: function(itm){
var self = this;
$(itm).click(function(e) {
_videogallery.load();
self.click( 0 );
self.getItems().filter('.active').click();
e.preventDefault();
});
}
});
$(".video_box a.gallery_box_prev").bind('click', function(e){
gal.click(gal.getClickIndex()-1);
gal.getItems().filter('.active').click();
$(".video_box span.gallery_box_count").html( (gal.getClickIndex()+1) + ' / ' + gal.getSize() );
e.preventDefault();
});
$(".video_box a.gallery_box_next").bind('click', function(e){
gal.click(gal.getClickIndex()+1);
gal.getItems().filter('.active').click();
$(".video_box span.gallery_box_count").html( (gal.getClickIndex()+1) + ' / ' + gal.getSize() );
e.preventDefault();
});
return gal;
}
function updateMinPrices(prices) {
$('div.priceplaceholder').each(function() {
if (this.id in prices) {
$(this).html(prices[this.id]).next("span").show();
} else {
$(this).html("N/A").next("span").hide();
}
});
}

