var movement = false;
var total_pages = 1;
var current_page = 1;
var f_ex = 'false';
var act_f_ex = 'false';
var count_cloop = 0;
var link_param = '';
var index_1 = 0;
var xml_destinations = '';
var onSubnav = false; // true if mouse is over ATN subnav.

jQuery.preloadImages = function()
{
	for(var i = 0; i<arguments.length; i++)
	{
		jQuery("<img>").attr("src", arguments[i]);
	}
}

function is_array( mixed_var ) {
	return ( mixed_var instanceof Array );
}

function str_replace(search, replace, subject) {
    var f = search, r = replace, s = subject;
    var ra = is_array(r), sa = is_array(s), f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
    while (j = 0, i--){
        while (s[i] = s[i].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
    }
    return sa ? s : s[0];
}

function getURLParam(strParamName,link){
	var strReturn = "";
	//var strHref = window.location.href;
	var strHref = link.toString();
	if ( strHref.indexOf("?") > -1 ){
		var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
		var aQueryString = strQueryString.split("&");
		for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
			if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
				var aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
				break;
			}
		}
	}
	return strReturn;
}

function getURLParamShips(strParamName){
	var strReturn = "";
	var strHref = window.location.href;
	if ( strHref.indexOf("?") > -1 ){
		var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
		var aQueryString = strQueryString.split("&");
		for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
			if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
				var aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
				break;
			}
		}
	}
	return strReturn;
}

function browser_is_ie(version){
	var appVer = navigator.appVersion.toLowerCase();
	var iePos = appVer.indexOf('msie'); 
	var is_ie = ((iePos!=-1));
	var ver = appVer.charAt(iePos+5);
	var is_ie6 = (is_ie && ver== 6);
	var is_ie7 = (is_ie && ver== 7);
	
	if ((version=="any") && (is_ie)){return true;}
	else if ((version=="6") && (is_ie6)){ return true;}
	else if ((version=="7") && (is_ie7)){ return true;}
	else {return false;}
}

function detectMAC_FF(){
	if((navigator.userAgent.indexOf("Firefox")!=-1) && (navigator.userAgent.indexOf("Macintosh")!=-1)){
		return true;
	}
	else{
		return false;
	} 
}

function serializeNode (node) {
	if (typeof XMLSerializer != 'undefined') {
		return new XMLSerializer().serializeToString(node);
	}
	else 
		if (typeof node.xml != 'undefined') {
			return node.xml;
		}
		else 
			if (typeof printNode != 'undefined') {
				return printNode(node);
			}
			else
				if (typeof Packages != 'undefined') {
				    try {
				      var stringWriter = new java.io.StringWriter();
				      Packages.org.apache.batik.dom.util.DOMUtilities.writeNode(
				        node, stringWriter);
				      return stringWriter.toString();
				    }
				    catch (e) {
				      // might want to handle problem here
				      return '';
				    }
				}
				else {
				    // might want to handle problem here
					return '';
				}
}

function getContentHtml(xml,new_page){
  	var html_objs = $(xml).find("images image");
  	return buildContentHtml(html_objs,new_page);
}

function buildPager(total,current){
	var html = ''; 
	if(total >= 10){ //need  to build something like this: 1 ... 5 6 7 ...  11
		if(current == 1) {
			html += '<li class="active">1</li>';
		} else {
			html += '<li><a href="javascript:void(0)" rel="1">1</a></li>';
		}
		if(current > 4) {
			html += '<li class="more">...</li>';
		}
		
		//current page should be in the middle of the middle five, if possible.
		//there are 3 cases:  
		//1. it can be a middle of a middle five 
		//2.  too close to the left
		//3. too close to the right
		var from, to;
		if(current > 4 && total - current > 4) {//fits in the middle
			from = current - 2;
			to = current + 3;
			var pages_left = 515;
		} else if(current > 4) {//too close to the right
			from = total - 5;
			to = total;
			var pages_left = 550;
		} else { //too close to the left
			from = 2;
			to = 6;
			var pages_left = 550;
		}
		for (i = from; i < to; i++) {
			if (i == current)
				html += '<li class="active">' + i + '</li>';
			else
				html += '<li><a href="javascript:void(0)" rel="' + i + '">' + i + '</a></li>';
		}		
		
		if(total - current > 4) {
			html += '<li class="more">...</li>';
		}
		if(current == total) {
			html += '<li class="active">' + total + '</li>';
		} else {
			html += '<li><a href="javascript:void(0)" rel="' + total + '">' + total + '</a></li>';
		}		
	} else {
		for (i = 1; i <= total; i++){
			if (i == current) 
				html += '<li class="active">' + i + '</li>';
			else
				html += '<li><a href="javascript:void(0)" rel="' + i + '">' + i + '</a></li>';
		}
		var pages_left = (647 - (total-2)*20);
	}

	$('div.contents ul.pages').html(html);
   	$('div.contents ul.pages').css('position','absolute');
   	$('div.contents ul.pages').css('top','290px');
   	$('div.contents ul.pages').css('left',pages_left+'px');
	if(current==1){
		$('div.left-button div.click').css('display', 'none');
	}
	else{
		$('div.left-button div.click').css('display', 'block');
		$('div.left-button div.click').css('filter','progid:dximagetransform.microsoft.alphaimageloader(src="img/main-button1-1.png")');
	}
	if (current == total) {
		$('div.right-button div.click').css('display', 'none');
	} else {
		if ($('.conts').length > 0) {
			$('div.right-button div.click').css('display', 'block');
			$('div.right-button div.click').css('filter', 'progid:dximagetransform.microsoft.alphaimageloader(src="img/main-button2-1.png")');
		} else {
			$('div.right-button div.click').css('display', 'none');
		}
		//$('div.right-button div.click').css('background', 'url(../img/main-button2-1.png) no-repeat 0 0');
		$('div.right-button div.click').css('filter', 'progid:dximagetransform.microsoft.alphaimageloader(src="img/main-button2-1.png")');
	}
	$('div.contents ul.pages li a').click(function(){		
		var dir = $(this).attr('rel')<current_page?'right':'left';
		var times = (current_page - $(this).attr('rel'))>0?current_page - $(this).attr('rel'):$(this).attr('rel') - current_page; 
		movePictureSet(dir,times);
		return false;
	});
	return html;
}

function buildPopupHtml(xml,xml_prev_img,xml_next_img,title,lmstr){
	var html = '<div class="popups"><a class="close" href="javascript:void(0)" rel="close">close</a>';
	try{
		var xml_str = serializeNode(xml);
	}
	catch(e){
		var xml_str = xml;
	}
	
	if((xml_str.indexOf("nodescr")>=0)||(!xml_str)){
		html+='<div class="text"><span>'+title+'</span>';
		html+='<div class="about">';
		html+='<a class="back" rel="close" href="javascript:void(0)">Back to thumbnails</a>';
		html+='</div></div>';
		
		html+='<div class="image"><div class="left"></div><div class="right"></div>';
		html+='<div class="smenu"><div class="bg">';
		html+='<a class="prw" href="javascript:void(0)"';
		if(xml_prev_img)
			html+='rel="'+xml_prev_img+'" alt="picture" ';
		html+='>Previous photo</a>';
		
		html+='<a class="next" href="javascript:void(0)" ';
		if(xml_next_img)
			rel='rel="'+xml_next_img+'" alt="picture" ';
		html+='>Next photo</a>';
		html+='</div></div></div></div>';
	}
	else{
		html+='<div class="text"><span>'+$('description',xml).attr('ship')+'</span>';
		html+='<h4>'+$('description',xml).attr('title')+'</h4>';
		html+='<div class="desctxt"><p>'+$('description',xml).text()+'</p></div>';
		html+='<div class="about">';
		if($('seemore',xml).attr('href')){
			html+='<span>On '+$('seemore',xml).text()+'</span>';
		}
		if($('learnmore',xml).attr('href')){
			// Before using background image for label
			
			if($('learnmore',xml).text())
				html+='<a class="abouthis" href="'+$('learnmore',xml).attr('href')+'" target="_blank">'+$('learnmore',xml).text()+'</a>';
			else if(lmstr == 'destination')
				html+='<a class="abouthisdest" href="'+$('learnmore',xml).attr('href')+'" target="_blank"> </a>';
			else if(lmstr == 'ship')
				html+='<a class="abouthisship" href="'+$('learnmore',xml).attr('href')+'" target="_blank"> </a>';
			else if(lmstr == 'activity')
				html+='<a class="abouthisact" href="'+$('learnmore',xml).attr('href')+'" target="_blank"> </a>';
			else
				html+='<a class="abouthis" href="'+$('learnmore',xml).attr('href')+'" target="_blank">Learn more about this '+(lmstr)+'</a>';
		}
		html+='<a class="back" rel="close" href="javascript:void(0);">Back to thumbnails</a>';
		html+='</div></div>';
		
		html+='<div class="image"><div class="left"></div><div class="right"></div>';
		
		var dimmension = '';
		var padding = '';
		var width = parseFloat($('description',xml).attr('width'));
		var height = parseFloat($('description',xml).attr('height'));
		var factor = '';
		var padding_val = '';
		//alert($(this).attr('width')+' width - height'+$(this).attr('height')+' - '+$(this).attr('img'));
		if(width > (height*1.415)){
			dimmension = 'width="382"';
			factor = width/382;
			padding_val = (270 - (height/factor))/2;
			padding = 'padding-top:'+padding_val+'px;';
		}
		else{
			dimmension = 'height="270"';
			factor = height/270;
			padding_val = (382 - (width/factor))/2;
			padding = 'padding-left:'+padding_val+'px;';
		}
		
		html+='<img src="'+$('description',xml).attr('img')+'" style="'+padding+'" '+dimmension+' alt="'+$('description',xml).attr('ship')+'" />';
		html+='<div class="smenu"><div class="bg">'
		html+='<a class="prw" href="javascript:void(0)" ';
		if(xml_prev_img)		{
			html+='rel="'+xml_prev_img+'" alt="picture" ';
		}
		html+='>Previous photo</a>';
		
		html+='<a class="next" href="javascript:void(0)" ';
		if(xml_next_img)		{
			html+='rel="'+xml_next_img+'" alt="picture" ';
		}
		html+='>Next photo</a>';
		html+='</div></div></div></div>';
	}
	return html;
}
function buildContentHtml(objs,new_page){
	var i=1;
  	var total=1;
	var total_pict;
  	var html = '';
	var k = 0;
	if(!new_page)
		new_page = 1;
  	objs_length = $(objs).length;
  	//if there's no picture
	if (objs_length==0) {html+= '<span id="nopictmsg" style="margin-left: 206pt; margin-top: 10pt; position: absolute;">Citizens and Stories coming soon</span>'}  	
	$(objs).each(function(key){
		if(k >= 21*(new_page-1) && k <= (21*new_page)-1){
			total_pict = $(this).attr('total');
		 	if(i==1){
		 		html+='<div class="conts"><ul class="foto" >';
		 	}
			var dimmension = '';
			var padding = '';
			var width = parseFloat($(this).attr('width'));
			var height = parseFloat($(this).attr('height'));
			var factor = '';
			var padding_val = '';
			//alert($(this).attr('width')+' width - height'+$(this).attr('height')+' - '+$(this).attr('img'));
			if(width > (height*1.072)){
				dimmension = 'width="74"';
				factor = width/74;
				padding_val = (69 - (height/factor))/2;
				padding = 'margin-top:'+padding_val+'px;';
			}
			else{
				dimmension = 'height="69"';
				factor = height/69;
				padding_val = (74 - (width/factor))/2;
				padding = 'margin-left:'+padding_val+'px;';
			}
			//alert(factor+' factor '+padding_val+' padding_val '+padding+' padding '+width+' width '+height+' height');
		 	html+='<li><div class="bg-img"><a href="javascript:void(0)" alt="picture"';
		 	html+=($(this).attr('xml')=="nodescr" || (!$(this).attr('xml')))?'rel="nodescr-'+key+'">':'rel="'+$(this).attr('xml')+'">';
			html+='<img src="'+$(this).attr('img')+'" alt="'+$(this).attr('tags')+'" style="'+padding+'" '+dimmension+'/></a></div><div class="box-prior"><div class="center"><ul>'

			//Using loop
			var tags = $(this).attr('tags');
			tags = String(tags);
			tags_array = tags.split(',');
			jQuery.each(tags_array, function() {
				if(this == 'couples')
					html+='<li class="prior2">&nbsp;</li>';
			 	if(this == 'families')
			 		html+='<li class="prior1">&nbsp;</li>';
			 	if(this == 'solo-travel')
			 	  	  html+='<li class="prior3">&nbsp;</li>';
			 	if(this == 'groups')
			 	  	  html+='<li class="prior4">&nbsp;</li>';
			 	if(this == 'none')
			 		html+='<li class="none">&nbsp;</li>';
			});

		 	html+='</ul></div></div></li>';
		 	i++;
		 	if(i==22 || ((total-1)*21+(i-1))==objs_length){
		 	  	html+='</ul></div>';
		 	  	i=1;
		 	  	total++;
		 	}
		}
		k++;
  	});
	total = Math.ceil(total_pict/21);
	if(!total_pict) //
		total = 1; //
    return [html,total];
}

function loadContent(link){
	
	$('.left-button').css('display', 'block');
	$('.right-button').css('display', 'block');	
	var rel = $(link).attr('rel');
	if(!rel)
		rel = getURLParam('destination',$(link)[0]);

	//var xml_path = path_to_xml+rel+'/'+rel+'.xml';
	var xml_path = 'dynamic_ajax_php.php?destination='+getURLParam('destination',$(link)[0]);
	if($('ul.menu li.active').attr('tagName'))
		$('ul.menu li.active').removeClass('active');
	else 
		if($('ul.tab-menu li.active').attr('tagName'))
			$('ul.tab-menu li.active').removeClass('active');
		else 
			if($('ul.on-board-sub-menu li.active').attr('tagName'))
				$('ul.on-board-sub-menu li.active').removeClass('active');
		
	$(link).parent().addClass('active');
	$.ajax({
		type: "GET",
		url: xml_path,  
		dataType: "xml",
		success: function(xml){
			xml_destinations = xml;
		   	var parsed = getContentHtml(xml);
		   	var html = parsed[0];
		   	var total = parsed[1];
		   	total_pages = total; 
		   	$('div.cont').empty();
		   	$('div.cont').width(2100); 
		   	$('div.cont').html(html);
		   	$('div.cont').css('position','absolute');
		   	$('div.cont').css('left','0px');
		   	$('div.contents').css('position','absolute');
		   	$('div.contents').css('top','198px');
		   	$('div.contents').css('left','55px');
		   	
		   	$('div.contents ul.prior, div.contents ul.pages').remove(); //remove old element
		   	var contents_html = $('div.contents').html()+ '<ul class="prior"><li class="family">families</li><li class="romantic">couples</li><li class="singles">solo-travel</li><li class="groups">groups</li></ul>';		 
			contents_html += '<ul class="pages"></ul>';
		   	
		   	$('div.contents').html(contents_html);
			var pager_html = buildPager(total,1);

		   	$('div.contents ul.prior').css('position','absolute');
		   	$('div.contents ul.prior').css('top','290px');
		   	$('div.contents ul.prior').css('left','0px');
		   	$('div.cont div.conts a[@alt="picture"]').each(function(){
			   	$(this).click(function(){ 
					loadPopup(this,rel,'destination');
					return false;
			   	});
			});
   		},
   		error: function(xml){
   			$('div.cont').empty();
   			$('div.cont').css('position','absolute');
		   	$('div.cont').css('left','0px');
		   	$('div.contents').css('position','absolute');
		   	$('div.contents').css('top','198px');
		   	$('div.contents').css('left','55px');
   		}
	});
}

function loadPopup(obj,rel,lmstr){
	var xml_descr_path = $(obj).attr('rel');
	var xml_prev_img = $('div.conts a[@rel="'+$(obj).attr('rel')+'"]').parent().parent().prev().children('div.bg-img').children().attr('rel');
	var xml_next_img = $('div.conts a[@rel="'+$(obj).attr('rel')+'"]').parent().parent().next().children('div.bg-img').children().attr('rel');
 	$.ajax({
		type: "GET",
		url: xml_descr_path,  
		dataType: "xml",
		success: function(xml){
			$('div.popup').empty();
			var html = buildPopupHtml(xml,xml_prev_img,xml_next_img,rel,lmstr);
			$('div.popup').html(html);
			$('div.image img').hide();
			$('div.image img').fadeIn(1000);
			$('div.close-menu').show();
			$('div.conts').fadeOut(500);
			$('div.contents').hide();
			$('div.popup').fadeIn(500);
			if( $('div.absolute-flash').length > 0 ) {
				$('div.absolute-flash').fadeIn(500);
			}else{
				$('div.absolute-flash-half').fadeIn(500);
			}
			
			$('a[@rel="close"]').each(function(){
				$(this).click(function(){
					closePopup();
					// Reset animation flag for passport
					$("#swf_animate").val('true'); 
					return false;
				});
			});
	   	     	  
			$('div.click a[@rel="left"],div.click a[@rel="right"]').each(function(){
				var direction = $(this).attr('rel');
				$(this).click(function(){
					closePopup();
					movePictureSet(direction);
					return false;
				});
			});
	   	  
			$('div.popup a[@alt="picture"]').each(function(){
				$(this).click(function(){
					loadPopup(this,rel,lmstr);
					return false;
				})	
			});

			var title_name = "<span class='nickname'>"+$('author',xml).attr('title1')+"</span><span class='join'> of the </span><span class='nickname'>"+$('author',xml).attr('title2')+"</span>";

			var flashvars = {
				first_name:$('author',xml).attr('fname'),
				last_name:$('author',xml).attr('lname'),
				userPhoto:$('author',xml).attr('img'),
				citizen_page_url:$('author',xml).attr('link'),
				official_title_name:title_name,
				intro_animation:$("#swf_animate").val()
			};
			if( $('author',xml).attr('ptype') == 'half'){
				var params = {bgcolor:"#FFFFFF", quality:"high", align:"top", allowScriptAccess:"always", wmode:"transparent"};
				swfobject.embedSWF("passport_half.swf", "flash", "275", "425", "9.0.0","expressInstall.swf", flashvars, params);
				// This will force it to animate once
				if( $("#swf_animate").val() == 'true')
					$("#swf_animate").val('false');
			} else {
				var params = {bgcolor:"#FFFFFF", quality:"high", align:"top", allowScriptAccess:"always", wmode:"transparent"};
				swfobject.embedSWF("passport.swf", "flash", "275", "535", "9.0.0","expressInstall.swf", flashvars, params);
			}
			
  		},
		error: function(xml){
	  	   	var obj_str = $(obj).attr('rel').toString();
	  	   	if(obj_str.indexOf("nodescr")>=0){
				var html = buildPopupHtml(obj_str,xml_prev_img,xml_next_img,rel,lmstr);
				$('div.popup').empty();
				$('div.close-menu').show();
				$('div.popup').html(html);
				$('div.contents').hide();
				$('div.popup').fadeIn(500);
				$('a[@rel="close"]').each(function(){
					$(this).click(function(){
						closePopup();
						return false;
					});
				});
				$('div.popup a[@alt="picture"]').each(function(){
					$(this).click(function(){
						loadPopup(this,rel,lmstr);
						return false;
					})	
				}); 
			}
		}	 	 
	});
}

function movePictureSet(direction,times){
	if(movement==true)
		return false;
	movement=true;
	var next_page = new Array();
	var prev_page = new Array();
	
	var times = (times)?times:1;
	var new_left = (direction=="left")? - 700:+ 0;
	var abs_left = (new_left>0)?new_left:new_left*(-1);  

	if(((direction=="left")&&((new_left<0)&&(abs_left<$('div.cont').width())))||((direction=="right")&&(new_left<700*times)))	{
		var i = 0;
		if(direction == "left"){
			i = 1;
			$('div.conts').each(function(){
				next_page[i] = '<div class="conts">'+$(this).html().toString()+'</div>';
				i++;
			});
		}
		if(direction == "right"){
			i = 1;
			$('div.conts').each(function(){
				prev_page[i] = $(this).html();
				i++;
			});
		}
		
		var new_page = (direction=="left")?current_page+times:current_page-times;
		buildPager(total_pages,new_page);
		current_page = new_page;
		var parsed = getContentHtml(xml_destinations,new_page);
	   	var html = parsed[0];
	   	$('div.cont').empty();
		
	   	if(direction == "left"){
			if($('div.cont').css("left") == '-700px'){
				$('div.cont').html(next_page[2]+html);
				$('div.cont').css("left","0px");
			}
			else{
				$('div.cont').html(next_page[1]+html);
			}
		}
		if(direction == "right"){
			if($('div.cont').css("left") == '0px'){
				$('div.cont').html(html+'<div class="conts">'+prev_page[1]);
				$('div.cont').css("left","-700px");
			}
			else
				$('div.cont').html(html+'<div class="conts">'+prev_page[2]);
		}
		
		$('div.cont div.conts a[@alt="picture"]').each(function(){
			$(this).click(function(){ 
				loadPopup(this,link_param,'destination');
				return false;
			});
		});
		
		new_left = new_left+'px';
		$('div.cont').animate({left:new_left},500,"linear",function(){movement=false;});
	}
	else{
		movement=false;
	}
}

function closePopup(){
	$('div.contents').show();
	$('div.close-menu').hide();
	$('div.popup').fadeOut(500);
	if( $('div.absolute-flash').length > 0 ){
		$('div.absolute-flash').fadeOut(500);
	} 
	else{
		$('div.absolute-flash-half').fadeOut(500);
	}
	$('div.conts').fadeIn(500);
}

var hide = false;
var shown = false;
var movement_f = false;
var movement_b = false;

var li_hide = [false,false];
var li_shown = [false,false];
var li_movement_f = [false,false];
var li_movement_b = [false,false];

var k = 0;

function clickAnywhereCreate(){	
	var _height = jQuery(document).height();
	var _width = ((jQuery.browser.msie)&&(parseInt(jQuery.browser.version)<7))?jQuery(document).width()-20:jQuery(document).width();
	
	if(!jQuery('div#bg-cover').attr('tagName')){
	    jQuery('<div id="bg-cover" style="padding:0;margin:0;position:absolute;top:0;left:0;border:0;width:'+_width+'px;height:'+_height+'px;">&nbsp;</div>')
	    .appendTo('body');
    }
    else{
		jQuery('div#bg-cover').show();
    }
}

function initSignIn(){
	//Initialze signin form to hide
	$('ul.menu-client li.active').toggleClass('active');
	$('#lgn_jsmode').val('1');
	$('#fgt_jsmode').val('1');
	$('#password_form').hide();
	
	$('ul.menu-client li div.sign-popup').prev().click(function() {
		li = $(this).parent();
		li.toggleClass('active');
		if (li.attr('class') == 'active'){
			if(!detectMAC_FF()){
				$('div.sign-popup').fadeIn(500);
				$('#password_sent').hide();
				$('#password_init').fadeIn(500);
			}
			else{
				$('div.sign-popup').show();
				$('#password_sent').hide();
				$('#password_init').show();
			}
			
			
		    clickAnywhereCreate();
		    jQuery('div#bg-cover').click(function(){
		     //$(li).removeClass('active');
		     jQuery('div#bg-cover').hide();
		    });

		}
		else{
			if(!detectMAC_FF()){
				$('div.sign-popup').css("display","none");
				$('#password_sent').hide();
				$('#password_init').css("display","none");
			    clickAnywhereCreate();
			}
		}
		return false;
	});
	
	//stopper for signup form 
	
	$('ul.menu-client li div.sign-bottom .img-bottom1 a').click(function(){
		$(this).parent().parent().hide().next().show().children().children('input[@type="text"]').focus(function(){  //onfocus for email input
			if ($(this).val() == 'Enter email')
				$(this).val('');
		}).blur(function() { //onblur for email input
			if ($(this).val() == '')
				$(this).val('Enter email');
		}).next('input[@type="submit"]').click(function(){
			$(this).parent().parent().hide().next().show();
			return false;
		});
		return false;
	});
}

//Hide drop down menus
function initMenu(){
	$('div.drop').css({"top" : "-133px"});
	$('div.about_drop').css({"top" : "-158px"});
}

/******************************************************/

function initCustomSelects() {
	$('.costum-select a.link-select').click(function(){
		select_box = $(this).parent().children('div')
		select_box.toggle();
		if (select_box.css('display') == 'block') {
			/*
			clickAnywhereCreate();
		    jQuery('div#bg-cover').click(function(){
		    	$(select_box).hide();
		    	jQuery('div#bg-cover').hide();
		    });
			*/
		}
		return false;
	});
	
	$('.costum-select div ul li a').click(function() {
		_value = $(this).attr('rel');
		_txt = $(this).html();
		$(this).parent().parent().parent()
		.parent().children('input[@type="hidden"]').val(_value)
		.parent().children('p').html(_txt)
		.parent().children('div').hide();
		
		// Disable the opt-in checkbox if the choice is Spain / 67
		// If checkbox is checkes, also unchecks to prevent false positive
		if(_value=="67")
		{
			$("#signup_special_offer").attr("checked", "");
			$("#signup_special_offer").attr("disabled", "disabled");
		} else {
			$("#signup_special_offer").removeAttr("disabled");
		}
		return false;
	});	
		
	$('.costum-select2 a.link-select').click(function(){
		select_box = $(this).parent().children('div')
		select_box.toggle();
		if (select_box.css('display') == 'block') {
			/*
			clickAnywhereCreate();
		    jQuery('div#bg-cover').click(function(){
		    	$(select_box).hide();
		    	jQuery('div#bg-cover').hide();
		    });
		*/
		}
		return false;	
	});
	
	$('.costum-select2 div ul li a').click(function() {
		_value = $(this).attr('rel');
		_txt = $(this).html();
		$(this).parent().parent().parent()
		.parent().children('input[@type="hidden"]').val(_value)
		.parent().children('p').html(_txt)
		.parent().children('div').hide();
		return false;
	});
}

/******************************************************/

function updateSifr(){
	if(typeof sIFR == "function"){
		sIFR.replaceElement(named({sSelector:"h3.sifr", sFlashSrc:"swf/Gotham-Book.swf", sWmode:"transparent", sColor:"#201d50", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=justify"}));
		sIFR.replaceElement(named({sSelector:"h4.sifr", sFlashSrc:"swf/Gotham-Book.swf", sWmode:"transparent", sColor:"#201d50", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=center"}));
		sIFR.replaceElement(named({sSelector:"h4.sifr2", sFlashSrc:"swf/Gotham-Book.swf", sWmode:"transparent", sColor:"#201d50", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=center"}));
		sIFR.replaceElement(named({sSelector:"p.sifr3", sFlashSrc:"swf/handwritingDakota.swf", sWmode:"transparent", sColor:"#151e54", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left"}));
		sIFR.replaceElement(named({sSelector:"p.sifr3-1", sFlashSrc:"swf/handwritingDakota.swf", sWmode:"transparent", sColor:"#151e54", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=center"}));
		sIFR.replaceElement(named({sSelector:"p.sifr4", sFlashSrc:"swf/handwritingDakota.swf", sWmode:"transparent", sColor:"#151e54", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left"}));
		sIFR.replaceElement(named({sSelector:"h3.sifr5", sFlashSrc:"swf/gothamUltra.swf", sWmode:"transparent", sColor:"#151b51", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left"}));
		sIFR.replaceElement(named({sSelector:"p.sifr5", sFlashSrc:"swf/gothamUltra-italic.swf", sWmode:"transparent", sColor:"#151b51", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left"}));
		sIFR.replaceElement(named({sSelector:"span.sifr5", sFlashSrc:"swf/gothamUltra-italic.swf", sWmode:"transparent", sColor:"#151b51", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left"}));
		sIFR.replaceElement(named({sSelector:"strong.sifr5", sFlashSrc:"swf/gothamUltra.swf", sWmode:"transparent", sColor:"#151b51", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left"}));
	};
}

/******************************************************/

//page createprofile-stage2

function initCreateProfile(){
	var showStep2 = function (){
		$('.step .step2').show();
		return false; 
	};
	
	var showStep3 = function (){
		$('.step .step3').show();
		return false;
	};
		
	var showStepFLCKR = function (){		
		window.open('uploadfkr.php','_self');
		return false; 
	};		
		
	$('.step a.my-comp').click(showStep2);
	$('.step a.my-flickr').click(showStepFLCKR);
	
	$('.step .step2 .text-area .save a').click(showStep3);
	
//	$('.step .step3 a.del').click(function(){
//		alert("Coming Soon...");
//		return false;
//	});
	
}

/******************************************************/

//citizens-landing-page 
var profiles_num = 0;

function initLeftRightClicks(){
	$('.click a').click(function () {
		//alert("ok");
		dir = $(this).attr('rel');
		if ((dir == 'right' && current_page == 1) || (dir == 'left' && current_page == total_pages)){
		  return false;
		}
		$('div#citizen_popup').hide();
		moveProfilesSet(dir,1);
		showLeftRightButton();
	});
}

//-------      -------      -------       -------
	
function buildPages(current) {
	var html = '';
	if(total_pages >= 10) {
		if(current == 1) {
			html += '<li class="active">1</li>';
		} else {
			html += '<li><a href="javascript:void(0)" rel="1">1</a></li>';
		}
		if(current > 4) {
			html += '<li class="more">...</li>';
		}
		
		var from, to;
		if(current > 4 && total_pages - current > 4) {//fits in the middle
			from = current - 2;
			to = current + 3;
		} else if(current > 4) {//too close to the right
			from = total_pages - 5;
			to = total_pages;
		} else { //too close to the left
			from = 2;
			to = 6;
		}
		for (i = from; i < to; i++) {
			if (i == current)
				html += '<li class="active">' + i + '</li>';
			else
				html += '<li><a href="javascript:void(0)" rel="' + i + '">' + i + '</a></li>';
		}		
		
		if(total_pages - current > 4) {
			html += '<li class="more">...</li>';
		}
		if(current == total_pages) {
			html += '<li class="active">' + total_pages + '</li>';
		} else {
			html += '<li><a href="javascript:void(0)" rel="' + total_pages + '">' + total_pages + '</a></li>';
		}		
	} else {
		for (i = 1; i <= total_pages; i++){
			if (i == current) 
				html += '<li class="active">' + i + '</li>';
			else
				html += '<li><a href="javascript:void(0)" rel="' + i + '">' + i + '</a></li>';
		}
	}
	
	// The line below adds a text range within the pagination navigation on a page 
	// html += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Page ' + current + ' of ' + total_pages; 
	$('ul.pages').html(html);
	
	current_page = current;
	$('ul.pages li a').click(function(){
		$('div#popup').css('display', 'none');
		var dir = $(this).attr('rel') < current_page ? 'right' : 'left';
		var times = (current_page - $(this).attr('rel')) > 0 ? current_page - $(this).attr('rel') : $(this).attr('rel') - current_page; 
		$('div#citizen_popup').hide();
		moveProfilesSet(dir, times);
		showLeftRightButton(total_pages);
		return false;
	});
}

//-------      -------      -------       -------
// Function to show appropriate button at appropriate page
function showLeftRightButton(){
	if ( current_page == total_pages && total_pages != 1){
		$('div#popup').css('display', 'none');
		$('div.left-button').show();
		$('div.right-button').hide();
	} else if ( current_page == 1 ){
		$('div.left-button').hide();
		if (total_pages > 1 ){
			$('div.right-button').show();
		} else { 
			$('div.right-button').hide();
		}
	} else {
		$('div.right-button').show();
		$('div.left-button').show();
	}
}
//-------      -------      -------       -------
function buildProfilesList(xml,new_page){
	profiles_num = $(xml).find('profiles profile').length;
	total_pages = Math.ceil(profiles_num / 12);
	var html = 
		'<div class="cont3">'+
			'<div class="left-col" style="'+((browser_is_ie('7'))?"left:14px;":"")+'">'+
				'<ul class="info">';
	var bool = 0;
	var total_pict;
	var bool1 = 0;
	var k = 0;
	if(!new_page)
		new_page = 1;
	n = 0;
	count_cloop = 0;
	$(xml).find('profiles profile').each(function(n, profile){
		if(k >= 12*(new_page-1) && k <= (12*new_page)-1){
			var b_orientation;
			if (count_cloop%2==0)
				b_orientation='left'
			else
				b_orientation='right';
			
			total_pict = $(profile).children('total').text();
			_link = $(profile).children('link').text();

			html += '<a href="'+_link+'"></a>';			
			if(browser_is_ie('6')){
				html += '<li style="width:214px">';
				html += '<div class="bg-inf" style="background-image: none; position:absolute; left:'+((b_orientation == "right")?10:0)+'px;">';
			}
			else{
				html += '<li>';
				html +=	'<div class="bg-inf" style="background-image: none; position:absolute; left:-12px;">';
			}

			html += 		'<div id="flashcontent'+k+'">'+
								'<p>'+
									'<a href="http://www.adobe.com/go/getflashplayer">'+
										'<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />'+
									'</a>'+
								'</p>'+
							'</div>'+
							'';
			html+=		'</div>'+
					'</li>';
			//html += '</a>';
			if(bool == 0)
				bool = 1;
			else 
				bool = 0;
				
			if ((n+1) % 6 == 0 && bool1 == 0) {
				bool1 = 1;
				html += 
				'</ul>'+
			'</div>'+
			'<div class="right-col" style="'+((browser_is_ie('7'))?"left:8px;":"")+'">'+
				'<ul class="info">';
			}
			
			if ((n+1) % 12 == 0) {
				bool1 = 0;
				html += 
				'</ul>'+
			'</div>'+
		'</div>';
				// if (profiles_num > 12) {
					// html += 
		// '<div class="cont3">'+
			// '<div class="left-col">'+
				// '<ul class="info">';
				// }
			}
			
			if ((n+1) == profiles_num && (k+1)%12 != 0 ){
				html += 
				'</ul>'+
			'</div>'+
		'</div>';
			}
			count_cloop++;
		}
		k++;
	});
	$('.contents3').html(html);
	
	//so user can access citizen profile	
	 	//var appVer = navigator.appVersion.toLowerCase();
	 	//var iePos = appVer.indexOf('msie'); 
	 	//var is_ie = ((iePos!=-1));
	 	//var ver = appVer.charAt(iePos+5);
	 	//var is_ie6 = (is_ie && ver== 6);
	 if(browser_is_ie("6")){
		$("div.bg-inf").each(function(){
			$(this).click(function(){
				$(this).css('cursor','hand');
				redirect($(this).parent().prev().attr("href"));
			})
		});
	}
	
	buildPages(new_page);

	total_pages = Math.ceil(total_pict/12); //+(total_pict%21 > 0? 2 : 1);
	if(!total_pict) //
		total_pages = 1; //
	return [total_pages,html];
}

//-------      -------      -------       -------

function applyFlash(xml,new_page){
	profiles_num = $(xml).find('profiles profile').length;
	total_pages = Math.ceil(profiles_num / 12);
	var html = 
		'<div class="cont3">'+
			'<div class="left-col">'+
				'<ul class="info">';
	var bool = 0;
	var total_pict;
	var bool1 = 0;
	var k = 0;
	if(!new_page)
		new_page = 1;
	n = 0;
	count_cloop = 0;
	$(xml).find('profiles profile').each(function(n, profile){
		if(k >= 12*(new_page-1) && k <= (12*new_page)-1){
			_name   = $(profile).children('name').text();
			_avatar = $(profile).children('avatar').text();
			_link = $(profile).children('link').text();
			_descr  = $(profile).children('description').text();
			//_descr = str_replace("~~~", "</br>", _descr);
			_photos = $(profile).children('photos').text();
			__title = $(profile).children('title');
			_tag = $(profile).children('tag').text();
			_title =  '<span id="who">'+$(__title).attr('who')+'</span> <span style="font-size:11px;">'+$(__title).attr('between')+'</span> <span id="who">'+$(__title).attr('from')+'</span>';
			
			var b_orientation;
			if (count_cloop%2==0)
				b_orientation='left'
			else
				b_orientation='right';
			
			
			var flashvars = {citizen_name:_name, description:_descr, band_orientation:b_orientation,
				photos:_photos,nickname1:$(__title).attr('who'),nickname2:$(__title).attr('from'),
				citizen_url:_link,userPhoto:_avatar,tag:_tag};
			var params = {bgcolor:"#FFFFFF", quality:"high", align:"middle", allowScriptAccess:"always", wmode:"transparent"};
			swfobject.embedSWF("./profile.swf", "flashcontent"+k, "238", "93", "9.0.0","./expressInstall.swf", flashvars, params);
			if(browser_is_ie('6')){
				$("#flashcontent"+k).css("margin-left",((b_orientation == "left")?"-2px":"-21px"));
				$("#flashcontent"+k).css("width","236px");
			}
			count_cloop++;
		}	
		k++;
	});
}

//-------      -------      -------       -------

function moveProfilesSet(direction,times){	
	//alert('0) - '+$('div.click a').css('margin-left')+direction);
	//alert(navigator.appName+parseFloat(navigator.appVersion));

	if(direction == 'right'){
		index_1=1;
	}
	if(direction == 'right'){
		$('div.click a').css('margin-left','0px');
	}
	if(index_1>0 && direction == 'left'){
		$('div.click a').css('margin-left','26px');
	}
	if(movement==true)
		return false;
	movement=true;	
	
	var next_page = new Array();
	var prev_page = new Array();
	
	times = (times)?times:1;
	if ($('div.contents3').css('margin-left') == 'auto'){ 
		$('div.contents3').css('margin-left', 0);
	}
	//var new_left = (direction=="left") ? parseInt($('div.contents3').css('margin-left')) - 940*times : parseInt($('div.contents3').css('margin-left')) + 940*times;
	var new_left = (direction=="left") ? - 940 : 0;
	
	var new_page = (direction=="left") ? current_page+times : current_page-times;
	//alert(new_page+" new_page "+current_page+" current_page "+times+" times");
	
	var i = 0;
	if(direction == "left"){
		i = 1;
		$('div.cont3').each(function(){
			next_page[i] = '<div class="cont3">'+$(this).html().toString()+'</div>';
			i++;
		});
	}
	if(direction == "right"){
		i = 1;
		$('div.cont3').each(function(){
			next_page[i] = '<div class="cont3">'+$(this).html()+'</div>';
			i++;
		});
	}
	
	var html = buildProfilesList(xml_destinations,new_page)[1];
	
	if(direction == "left"){
		//$('div.contents3').html(next_page[1]+html);
		if($('div.contents3').css("margin-left") == '-940px'){
			$('div.contents3').html(next_page[2]+html);
			$('div.contents3').css("margin-left","0px");
			//alert("second left");
		}
		else{
			$('div.contents3').html(next_page[1]+html);
			////$('div.contents3').html(next_page[1]+html.substr(0,(html.length-17))); //ptr 24 useri
		}
	}
	if(direction == "right"){
		//$('div.contents3').html(html+next_page[1]);
		if($('div.contents3').css("margin-left") == '0px'){
			$('div.contents3').html(html+next_page[1]);
			$('div.contents3').css("margin-left","-940px");
		}
		else
			$('div.contents3').html(html+next_page[2]);
	}
	$('div.contents3').animate( {marginTop:0+'px'}, 500, "linear", function(){movement=false;} );
	applyFlash(xml_destinations,new_page); // Load flash after the first transition
	$('div.contents3').animate( {marginLeft:new_left+'px'}, 1000, "linear", function(){movement=false;} );

	
	//var new_page = (direction=="left") ? current_page+times : current_page-times;
	//buildPages(new_page);
}

//-------      -------      -------       -------

function initProfilesList(){
	if (!$('.contents3').attr('tagName')){
		return false;
	}	
	xml_path = 'citizen_dynamic_ajax_php.php';
	
	$.ajax({
		type: "GET",
		url: xml_path,  
		dataType: "xml",
		success:function(xml){
			xml_destinations = xml;		
			var objects = buildProfilesList(xml);
			var total = objects[0];
			var html = objects[1];
			updateSifr();
			if (total_pages > 1) {
				$('div.right-button').show();
			}
			initLeftRightClicks();
			
			$('div.contents3').css('width',(2*940)+"px");
			applyFlash(xml,1);
		}
	});
}

function initActivitiesFotos(link){
	var xml_path = '';
	var my_url = '';
	var type = 1;
	var act = 0;
	var i = 2;
	var act_val=getURLParam('act',$(link).attr("href"));
	var type_val=getURLParam('type',$(link).attr("href"));
	
	$('.left-button').css('display', 'block');
	$('.right-button').css('display', 'block');
	$('#tabtoggler1_tab'+(i)+' ul.on-board-sub-menu').css('display','block');	
	$('#tabtoggler1_tab'+(i)+' ul.on-board-sub-menu').css('height','auto');						
	
	if (!$('.contents').attr('tagName')){
		return false;
	}		
	if (act_f_ex == 'false') {
		xml_path = 'activities_dynamic_ajax_php.php' + '?act=' + (getURLParamShips('act')?getURLParamShips('act'):0) + '&type=' + (getURLParamShips('type')?getURLParamShips('type'):1);
		my_url='act_get_subcategories.php'+ '?act=' + (getURLParamShips('act')?getURLParamShips('act'):0) + '&type=' + (getURLParamShips('type')?getURLParamShips('type'):1);
	}
	else {
		xml_path = 'activities_dynamic_ajax_php.php' + '?act=' + (getURLParam('act', link) ? getURLParam('act', link) : 0) + '&type=' + (getURLParam('type', link) ? getURLParam('type', link) : 1);
	    my_url='act_get_subcategories.php'+'?act='+(getURLParam('act',link)? getURLParam('act',link):0)+'&type='+(getURLParam('type',link)? getURLParam('type',link) : 1);
	}
	$.ajax({
		type: "GET",
		url: my_url,
		dataType: "xml",
		success: function(xml){
			var objs = $(xml).find("activities activity"); 		
			var html='';
			
			$(objs).each(function(key){
				html+='<li class="'+$(this).attr("class")+'">';
				html+='<span style="color:#EDECEA;"></span>';
			  
				html+='<a href='+$(this).attr("href")+'&type='+$(this).attr("type")+'>'; 
				if($(this).attr("activity_name")=="Flowrider")
					html+=$(this).attr("activity_name")+"&reg;";
				else
					html+=$(this).attr("activity_name");
				html+='</a>';
				html+='</li>';
			});
			$('ul.on-board-sub-menu').empty();

			if (act_f_ex == 'false'){
				$('div#tabtoggler1_tab' + (getURLParamShips('type')?getURLParamShips('type'):1) + ' ul.on-board-sub-menu').html(html);
				act_f_ex = 'true';
			}
			else{
				$('div#tabtoggler1_tab' + (getURLParam('type', link) ? getURLParam('type', link) : 1) + ' ul.on-board-sub-menu').html(html);
			}

			if(browser_is_ie("6")){  // case on IE
				if(type_val == 2)
					$('ul.on-board-sub-menu').css('margin-left','28px');
				else
					$('ul.on-board-sub-menu').css('margin-left','58px');
			}
			$('ul.on-board-sub-menu li a').each(function(){
				$(this).click(function(){
					initActivitiesFotos(this);

					//Omniture Lookup Code Start
					var ActivityType;
					var ActivityName = $(this).text();
					//Ship Type
					switch (getURLParam('type',this))
					{
					case '1':
						ActivityType = "Onboard";
						break;
					case '2':
						ActivityType = "Shore And Land";
						break;
					}

					if (ActivityType != "" && ActivityName !="")
					{
						s.pageName="WN:Activities:"+ActivityType+":"+UCWords(ActivityName).replace(/&/g,'And');
						s.channel="Activities"; 
						void(s.t());
					}

					//End Omniture Code

					//$('ul.on-board-sub-menu li.active').attr('class','no-bg');
					//$(this).addClass('active');
					closePopup();
					return false;
				});
			});
			
			$.ajax({
				type: "GET",
				url: xml_path,
				dataType: "xml",
				success: function(xml){
					xml_destinations = xml;
				   	var parsed = getContentHtml(xml);
				   	var html = parsed[0];
				   	var total = parsed[1];
				   	total_pages = total;
					  
				   	$('div.cont').empty();
				   	$('div.cont').width(2100);  //$('div.cont').width((total-1)*700);
				   	$('div.cont').html(html);
				   	$('div.cont').css('position','relative');
				   	$('div.cont').css('left','0px');
				   	$('div.contents').css('position','absolute');
				   	$('div.contents').css('top','198px');
				   	$('div.contents').css('left','55px');
				   	 
				   	$('div.contents ul.prior, div.contents ul.pages').remove(); //remove old element
				   	var contents_html = $('div.contents').html()+ '<ul class="prior"><li class="family">families</li><li class="romantic">couples</li><li class="singles">solo-travel</li><li class="groups">groups</li></ul>';
				   	contents_html += '<ul class="pages"></ul>';
				   	$('div.contents').html(contents_html);
				   	var pager_html = buildPager(total,1);

				   	$('div.contents ul.prior').css('position','absolute');
				   	$('div.contents ul.prior').css('top','290px');
				   	$('div.contents ul.prior').css('left','0px');
				   	$('div.cont div.conts a[@alt="picture"]').each(function(){
						var activity_name = $('a.'+act).text();
						$(this).click(function(){ 
							loadPopup(this,activity_name,'activity');
							return false;
					   	});
				   	});
		   		},
		   		error: function(xml){
		   			$('div.cont').empty();
		   			$('div.cont').css('position','relative');
				   	$('div.cont').css('left','0px');
				   	$('div.contents').css('position','absolute');
				   	$('div.contents').css('top','198px');
				   	$('div.contents').css('left','55px');
		   		}
			});	
	   },
   	   error: function(xml){
			// alert('xml error2?')
   	   }
	});
}

function initShipsFotos(link){
	var xml_path='';
	var my_url='';
	var type=1;
	var ship=0;
	
	if (browser_is_ie("6")){
		$('#tabtoggler1_content div').css("margin-left","-58px");
	}
	
	for(var i=2;i<=5;i++){
		$('#tabtoggler1_tab'+(i)+' ul.ship-sub-menu').css('display','block');
		$('#tabtoggler1_tab'+(i)+' ul.ship-sub-menu').css('height','auto');
	}		
	$('.left-button').css('display', 'block');
	$('.right-button').css('display', 'block');
	
	if (!$('.contents').attr('tagName')){
		return false;
	}		
	if (f_ex == 'false') {
		xml_path = 'ships_dynamic_ajax_php.php' + '?ship=' + (getURLParamShips('ship')?getURLParamShips('ship'):0) + '&type=' + (getURLParamShips('type')?getURLParamShips('type'):1);
		my_url='get_subcategories.php'+ '?ship=' + (getURLParamShips('ship')?getURLParamShips('ship'):0) + '&type=' + (getURLParamShips('type')?getURLParamShips('type'):1);
	}
	else {
		xml_path = 'ships_dynamic_ajax_php.php' + '?ship=' + (getURLParam('ship', link) ? getURLParam('ship', link) : 0) + '&type=' + (getURLParam('type', link) ? getURLParam('type', link) : 1);
		my_url='get_subcategories.php'+'?ship='+(getURLParam('ship',link)? getURLParam('ship',link):0)+'&type='+(getURLParam('type',link)? getURLParam('type',link) : 1);
		
	}		
	
	$.ajax({
		type: "GET",
		url: my_url,
		dataType: "xml",
		success: function(xml){
			var objs = $(xml).find("ships ship");
			var html='';
			html+= '<li>Ships:</li>';		  
			$(objs).each(function(key){
				var a_ship=getURLParam('ship',$(link).attr("href"));
				var b_ship=getURLParam('ship',$(this).attr("href"));;
				if (a_ship==b_ship){
					html+='<li class="active">';
				}
				else{
					html+='<li class="no-bg">';
					html+='<span style="color:#EDECEA;">|</span>';	
				}  		  		 	  		 	  
				html+='<a href='+$(this).attr("href")+'&type='+$(this).attr("type")+'>'; 
				html+=$(this).attr("ship_name"); 
				html+='</a>';
				html+='</li>';
		  	});
			$('ul.ship-sub-menu').empty();

			if (f_ex == 'false') {
				$('#tabtoggler1_tab' + (getURLParamShips('type')?getURLParamShips('type'):1) + ' ul.ship-sub-menu').html(html);
				f_ex = 'true';
			}
			else {
				$('#tabtoggler1_tab' + (getURLParam('type', link) ? getURLParam('type', link) : 1) + ' ul.ship-sub-menu').html(html);
			}	
			
			$('ul.ship-sub-menu li.no-bg a').each(function(){
				$(this).click(function(){
					initShipsFotos(this);

					//Omniture Lookup Code Start
					var ShipType;
					var ShipName = $(this).text();
					//Ship Type
					switch (getURLParam('type',this))
					{
					case '1':
						ShipType = "Freedom";
						break;
					case '2':
						ShipType = "Radiance";
						break;
					case '3':
						ShipType = "Voyager";
						break;
					case '4':
						ShipType = "Vision";
						break;
					case '5':
						ShipType = "Sovereign";
						break;
					}

					if (ShipName != "" && ShipType !="")
					{
						s.pageName="WN:Ships:"+ShipType+":"+UCWords(ShipName).replace(/&/g,'And');
						s.channel="Ships"; 

						void(s.t());
					}

					//End Omniture Code

					if($('ul.ship-sub-menu li.active').length)
						$('ul.ship-sub-menu li.active').removeClass('active');
					else
						$(this).addClass('active');
					closePopup();
					return false;
				});
			});
				
			$.ajax({
				type: "GET",
				url: xml_path,
				dataType: "xml",
				success: function(xml){
					xml_destinations = xml;
					var parsed = getContentHtml(xml);
					var html = parsed[0];
				   	var total = parsed[1];
				   	total_pages = total;
				   	$('div.cont').empty();
				   	$('div.cont').width(2100); //$('div.cont').width((total-1)*700);
				   	$('div.cont').html(html);
				   	$('div.cont').css('position','relative');
				   	$('div.cont').css('left','0px');
				   	$('div.contents').css('position','absolute');
				   	$('div.contents').css('top','198px');
				   	$('div.contents').css('left','55px');
				   	
				   	$('div.contents ul.prior, div.contents ul.pages').remove(); //remove old element
				   	var contents_html = $('div.contents').html()+ '<ul class="prior"><li class="family">families</li><li class="romantic">couples</li><li class="singles">solo-travel</li><li class="groups">groups</li></ul>';
				   	contents_html += '<ul class="pages"></ul>';
				   	 
				   	$('div.contents').html(contents_html);
				   	 
				   	var pager_html = buildPager(total,1);

				   	$('div.contents ul.prior').css('position','absolute');
				   	$('div.contents ul.prior').css('top','290px');
				   	$('div.contents ul.prior').css('left','0px');
				   	$('div.cont div.conts a[@alt="picture"]').each(function(){
					var ship_name = $('a.'+ship).text().substr(2);
						$(this).click(function(){ 
							loadPopup(this,ship_name,'ship');
							return false;
						});
				   	});
			   	},
				error: function(xml){
					$('div.cont').empty();
					$('div.cont').css('position','relative');
					$('div.cont').css('left','0px');
					$('div.contents').css('position','absolute');
					$('div.contents').css('top','198px');
					$('div.contents').css('left','55px');
				}
			});	
		},
	   	error: function(xml){
			// alert('xml error?')
	   	}
	});
}
/******************************************************/

function initFavStory(){
	
	//this is for passport flir -my story
	$('#favorites h4.sifr3').css('margin-top','5px');
	$('#favorites h4.sifr3').css('height','17px');
	$('#favorites p.sifr').css('height','auto');
	
	//$('#favorites p.sifr').css('font-size','12px');
	
	$('#fav-story a#favorites-toggle').click(function(){
		$('#fav-story a#favorites-toggle').removeClass('fav-yellow');
		$('#fav-story a#favorites-toggle').addClass('fav-blue');
		$('#body-content2.profile-edit #passport-box #mystory').fadeOut();
		$('#body-content2.profile-edit #passport-box #favorites').fadeIn();
		$('#fav-story a#story-toggle').removeClass('story-blue');
		$('#fav-story a#story-toggle').addClass('story-yellow');
		return false;
	});
	
	$('#fav-story a#story-toggle').click(function(){
		$('#fav-story a#story-toggle').removeClass('story-yellow');
		$('#fav-story a#story-toggle').addClass('story-blue');

		$('#body-content2.profile-edit #passport-box #favorites').fadeOut();
		$('#body-content2.profile-edit #passport-box #mystory').fadeIn();
		$('#fav-story a#favorites-toggle').removeClass('fav-blue');
		$('#fav-story a#favorites-toggle').addClass('fav-yellow');
		
		/////this is for passport flir -my story
		$("#mystory").show();
		$('p.sifr6').css('width','140px');
		$('p.sifr6').css('height','auto');
	
		sIFR.replaceElement(named({sSelector:"#mystory p.sifr6", sFlashSrc:"swf/Gotham-Book.swf", sWmode:"transparent", sColor:"#151b51", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=center"}));
		return false;
	});
}
/*
function gotoWidget(widgetName){
	alert(thisMovie("shell").gotoWidget(widgetName));
}

function thisMovie(movieName){
	if (navigator.appName.indexOf("Microsoft") != -1){
		return window[movieName];
	}
	else{
		return document[movieName];
	}
}

function initAbout(){
	$(".subNavigation").click(function(event){
		gotoWidget("tester");
		return false;
	});
}
*/
/******************************************************/

$(document).ready(function(){
	
	initSignIn();
	/*initAbout();*/
	initCustomSelects();
	initCreateProfile();
	initProfilesList();
	initFavStory();
	initMenu();

	//identify ships page
	if ($('#tabtoggler1_tab1 ul.ship-sub-menu').length > 0 ){
		initShipsFotos($('ul#tabtoggler1_menu li a#active'));
	}
	if ($('#tabtoggler1_tab1 ul.on-board-sub-menu').length > 0 ){
		initActivitiesFotos($('ul#tabtoggler1_menu li a#active'));
	}

	var myvar='default';
	if ($('#tabtoggler1_tab1 ul.on-board-sub-menu li').length > 0 ){
		myvar = $('a.active').attr('href');	
		$(myvar).click(function(){
			initActivitiesFotos(myvar);
			return false;
 	 	});
	}

	if($('#scrolling').attr('tagName')){
		$('#scrolling').jScrollPane({showArrows:true, dragMinHeight: 52});
	}
	
	if($('div.drop').attr('tagName')){
		$('div.drop div.logo').mouseover(function(){
			hide=false;
			if(!shown && !movement_b && !movement_f){
				movement_f = true;
				$('div.drop').animate({top:"0px"},700,'linear',function(){movement_f = false});
				shown = true;
			}
		});
		$('div.drop div.logo').mouseout(function(){
			hide = true;
			setTimeout( "if(hide && !movement_b){ movement_b = true; $('div.drop').animate({top:'-133px'},500,'linear',function(){movement_b = false});shown=false;}", 1000 );
		});
	}
	var show=false;
	//$('div.about_drop').css('left','59.2%');
	$('div.about_drop').css('left','89px');
	$('div.about_drop').css('margin-left','50%');
	if($('div.menu').attr('tagName')){
		$('div.menu a#about').mouseover(function(){
			$('div.about_drop').animate({top:"0px"},1000,'linear',function(){movement_f = false});
		});
		
		$('div.menu a#about').mouseout(function(e){
			/*
			$(this).css("z-index","999999");
			 if (!e) e = window.event;
			 if ((e.clientX<800 || e.clientX>890) || (e.clientY<=0)){
				 movement_b = true; 
				 $('div.about_drop').animate({top:'-158px'},700,'linear',function(){movement_b = false});
				 shown=false;
			 }
			
			
			
			
			if(e.pageX < 785 || e.pageX > 915 || e.pageY < 2) {
				$('div.about_drop').animate({top:'-158px'},700,'linear',function(){movement_b = false});
			}
			*/
			//alert(e.pageX+" , "+e.pageY);
			$.timer(1000, function (timer) {
				if(onSubnav == false) {
					$('div.about_drop').animate({top:'-158px'},700,'linear',function(){movement_b = false});
					timer.stop();
				}
			});
		});
		
	}

	if($('div.about_drop').attr('tagName')){
		$('div.about_drop').mouseover(function(){
			onSubnav = true;
			hide=false;
			if(!shown && !movement_b && !movement_f){
				movement_f = true;
				$('div.about_drop').animate({top:"0px"},700,'linear',function(){movement_f = false});
				shown = true;
			}
		});
		$('div.about_drop').mouseout(function(){
			onSubnav = false;
			hide = true;
			setTimeout( "if(hide && !movement_b){ movement_b = true; $('div.about_drop').animate({top:'-158px'},700,'linear',function(){movement_b = false});shown=false;}", 10 );
		});
		/*
		$('div.menu #about').mouseout(function(){
			hide = true;
			setTimeout( "if(hide && !movement_b){ movement_b = true; $('div.about_drop').animate({top:'-158px'},700,'linear',function(){movement_b = false});shown=false;}", 10 );
		});
		*/
	}
	
	if($('ul.info').attr('tagName')){
		$('div.meet-hold div.block1').mouseover(function(){
			li_hide[0]=false;
			if(!li_shown[0] && !li_movement_f[0] && !li_movement_b[0]){
				li_movement_f[0] = true;
				$('div.meet-hold ul.info li ul').slideDown(300,function(){li_movement_f[0] = false;});
				li_shown[0] = true;
			}
		});
		
		$('div.meet-hold div.block1').mouseout(function(){
			li_hide[0] = true;
			setTimeout( "if(li_hide[0] && !li_movement_b[0]){ li_movement_b[0] = true; $('div.meet-hold ul.info li ul').slideUp(300,function(){li_movement_b[0] = false;});li_shown[0]=false;}", 100 );
		});
		
		$('div.about-hold div.block1').mouseover(function(){
			li_hide[1]=false;
			if(!li_shown[1] && !li_movement_f[1] && !li_movement_b[1]){
				li_movement_f[1] = true;
				$('div.about-hold ul.info li ul').slideDown(300,function(){li_movement_f[1] = false;});
				li_shown[1] = true;
			}
		});
		
		$('div.about-hold div.block1').mouseout(function(){
			li_hide[1] = true;
			setTimeout( "if(li_hide[1] && !li_movement_b[1]){ li_movement_b[1] = true; $('div.about-hold ul.info li ul').slideUp(300,function(){li_movement_b[1] = false;});li_shown[1]=false;}", 100 );
		});
	}
	
	if($('ul.tab-menu').attr('tagName')){ // load ships
		if($('ul.tab-menu li a').attr('tagName')){
			$('ul.tab-menu li a').each(function(){
				$(this).click(function(){
					link_param = $(this);
					initShipsFotos(this);
					closePopup();
					return false;
				});
			});
		}		
	}
	
	if($('ul.tab-menu2').attr('tagName')){  // load activities
		if($('ul.tab-menu2 li a').attr('tagName')){
			$('ul.tab-menu2 li a').each(function(){
				$(this).click(function(){
					link_param = $(this);
					initActivitiesFotos(this);
					closePopup();
					return false;
				});
			});
		}		
		
	}
	
	if($('div.cont').attr('tagName')){
		if($('ul.menu li a.default_loads').attr('tagName')){ // load destinations
			loadContent($('ul.menu li a.default_loads'));
			$('ul.menu li a').each(function(){
				$(this).click(function(){
					link_param = $(this);
					loadContent(this);
					closePopup();
					return false;
				});
			});
		}
	}
		
	$('div.click a[@rel="left"],div.click a[@rel="right"]').each(function(){
		var direction = $(this).attr('rel');
		if($('ul.menu-center li.active a').html() != 'Citizens')
			$(this).click(function(){
				movePictureSet(direction);
				return false;
			});
	});
	
	$('#clicksignin').click(function(){
		"signinform"
	});
	$('#signinform').mouseout(function(){
		hide = true;
		setTimeout( "if(hide && !movement_b){ movement_b = true; $('div.drop').animate({top:'-133px'},500,'linear',function(){movement_b = false});shown=false;}", 10 );
	});

// Sign up form jquery functions
	$('#loginfrm').ajaxForm({ 
		dataType:  'json', 
		success: function(data){
			if(data.status == 'success'){
				//Omniture Track Successful log in
				s.linkTrackVars="events"; s.linkTrackEvents="event3";
				s.events="event3";
				s.tl(this,'o','WN:Site:Successful Login');
				window.location="profile_edit.php?type=login";
			}
			else{
				if (data.error_type == 1){
					$('#error_mail_msg').html(data.msg)
					$('#error_mail').css("display", "block");
					$('#error_password').css("display", "none");
					$('.sign-bottom').css("top", "186px");
				}
				else 
					if (data.error_type == 2) {
						$('#error_password_msg').html(data.msg)
						$('#error_mail').css("display", "none");
						$('#error_password').css("display", "block");
						$('.sign-bottom').css("top", "186px");
					}
			}
		} 
	});
	
	$('#forgetfrm').ajaxForm({ 
		dataType:  'json', 
		success: function(data){
			if(data.status == 'success'){
				$('#forgetfrm').clearForm();
				$('#password_sent').show();
				$('#password_form').hide();
				$('#sentmsg').html(data.msg);
			}
			else 
				if( data.status == 'error'){
					$('#password_msg').html(data.msg);
				}
		} 
	});


	$('textarea[maxlength]').keyup(function(){ 
		if($(this).val().length > $(this).attr('maxlength')){ 
			$(this).val($(this).val().substr(0, $(this).attr('maxlength'))); 
		} 
			// $(this).parent().find('.charsRemaining').html('You have ' + ($(this).attr('maxlength') - $(this).val().length) + ' characters remaining'); 
	});
	
	$("#user_email").focus(function() {if($(this).val()=="Enter email") { $(this).val(""); }});
	$("#user_email").blur(function() {if($(this).val().length<3) { $(this).val("Enter email"); }});
	// Flickr photo selection screen
	// $("#flickr-photos").wslide({
	    // width: 240,
	    // height: 320,
		// duration: 1000, 
		// horiz: true
	// });
	
	// Flickr photo selection border toggle
	// $("#flickr-photos li a").click(function () {
		// $("#flickr-photos li a span").hide();
		// $(this).children("span").toggle();
		// return false;
	// });
});
