
/* CUFON end */
jQuery.noConflict();

function countFavs(){
		jQuery("span.favCount").text(jQuery(".countRows").length);
}


jQuery(document).ready(function() {	

//jQuery("#twitter-block-footer a").text("Read More...");


jQuery.translate(function(){  //when the Google Language API is loaded 
   
    function translateTo( destLang ){ //this can be declared in the global scope too if you need it somewhere else 
        jQuery('body').translate( 'english', destLang, {   //translate from english to the selected language 
          not: '.jq-translate-ui',  //by default the generated element has this className 
          fromOriginal:true,   //always translate from english (even after the page has been translated) 
		    complete: function(){
						
							/* CUFON */
						Cufon.replace('h1, .cufonThis, #footer h3, #footer h4, .dir-entry h3');

               		 Cufon.now(); 
					  //Cufon.refresh('h1'); 
			}
        }); 

    } 
     
   jQuery('#languages ul')
      .find('a')
      .click(function(){
         var lang = jQuery(this).attr('id');
		 //if (lang == "English") {

//}
		 
         translateTo( lang );
         jQuery.cookie('destLang', lang, {expires: 7, path:'/', domain:'grenadagrenadines.com' });
         location.reload();
         return false;
      }) 
	 


    var destLang = jQuery.cookie('destLang'); //get previously translated language 
     
    if( destLang )  //if it was set then 
	{
		if (destLang !== "English"){
			translateTo( destLang ); 
			
		} else {
			
			Cufon.replace('h1, .cufonThis, #footer h3, #footer h4, .dir-entry h3');
      		 Cufon.now();
		}
     } else {
    	 Cufon.replace('h1, .cufonThis, #footer h3, #footer h4, .dir-entry h3');
  		 Cufon.now();
    	 
     }
 
  }); //end of Google Language API loaded 







	var pathname = window.location.pathname;	
	if(pathname.match("search&s-location") != null) {
		jQuery('body,html').animate({scrollTop:330}, 'fast');
	};	
	
	    jQuery('a[rel="external"]').click( function() {
			window.open( $(this).attr('href') );
			return false;
		});
		//Pagination  
	    
		jQuery("#directory div.dir-entry, #directory div.dirbox").quickpaginate({ perpage: 10, showcounter: true, pager : jQuery("div.list_counter") });

		jQuery("#pick-date-start").datepicker({ altFormat: 'yymmdd',  currentText: 'Now', altField: '#pick-date-start-real' });
		jQuery("#pick-date-end").datepicker({ altFormat: 'yymmdd',  currentText: 'Now', altField: '#pick-date-end-real' });
		
		
		jQuery(".cal-icon").click(function() {
			jQuery(this).parent().find(".pick-date").focus();		
		});		
		
		jQuery('.cycleThis').cycle('fade');
		jQuery("a[rel^='prettyPhotoNoResize']").prettyPhoto({
				allowresize: false /* true/false */
				
		});
			
		jQuery("a[rel^='prettyPhoto']").prettyPhoto();
		jQuery(".gallery a[rel^='prettyGallery']").prettyPhoto();
		jQuery("a[rel^='prettyPhoto2']").prettyPhoto({
			default_width: 550,
			default_height: 500
		});
			
			jQuery("#trip-wizard").hide();
			jQuery("#wrap-shadow").hide();
			jQuery(".planner-slide").click(function() {

				if ($(this).hasClass("opened")) {
					$(this).removeClass("opened");
					jQuery("#wrap").animate( {
						marginTop : "0px"
					}, 500);

				} else {
					jQuery("#wrap").animate( {
						marginTop : "450px"
					}, 500, function() {
					 	jQuery("#trip-wizard-loader").show();
					
					jQuery("#trip-wizard-div").load('/embeds/trip-wizard/', function() {
						jQuery("#trip-wizard-loader").hide();
					} );
				  });
				
			
					 $(this).addClass("opened");
				}
				
				

				if (jQuery("#trip-wizard").is(":hidden")) {
					jQuery("#trip-wizard").fadeIn('slow');
				} else {
					jQuery("#trip-wizard").hide();
				}

			});

			// initialize scrollable  

				jQuery("div.scrollable").scrollable( {
					vertical : true,
					size : 3 // use mousewheel plugin 
						}).mousewheel();
				


				jQuery("#nav ul").css( {
					display : "none"
				}); // Opera Fix
				jQuery(" #nav li").hover(function() {
					jQuery(this).find('ul:first').css( {
						visibility : "visible",
						display : "none"
					}).show(400);
				}, function() {
					jQuery(this).find('ul:first').css( {
						visibility : "hidden"
					});
				});

				// Activate jCarousel
				function mycarousel_initCallback(carousel) {
					// Disable autoscrolling if the user clicks the prev or next
					// button.
					carousel.buttonNext.bind('click', function() {
						carousel.startAuto(0);
					});

					carousel.buttonPrev.bind('click', function() {
						carousel.startAuto(0);
					});

					// Pause autoscrolling if the user moves with the cursor
					// over the clip.
					carousel.clip.hover(function() {
						carousel.stopAuto();
					}, function() {
						carousel.startAuto();
					});
				};


				jQuery(function() {

					// find the div.fade elements and hook the hover event

					jQuery('div.fade').hover(function() {

						// on hovering over find the element we want to fade
							// *up*

							var fade = jQuery('> div', this);

							// if the element is currently being animated (to
							// fadeOut)...

							if (fade.is(':animated')) {

								// ...stop the current animation, and fade it to
								// 1 from current position

								fade.stop().fadeTo(0, 1);

							} else {

								fade.fadeIn(0);

							}

						}, function() {

							var fade = jQuery('> div', this);

							if (fade.is(':animated')) {

								fade.stop().fadeTo(550, 0);

							} else {

								fade.stop().fadeOut(550);

							}

							return false;

						});

				});

				jQuery('#about-link *,  #sub-menu').stop().hover(

						function() {
							jQuery("#sub-menu").toggle(), jQuery(
									"#about-link > div").stop().fadeTo(0, 1);
						},

						function() {
							jQuery("#sub-menu").hide(), jQuery(
									"#about-link > div").stop().fadeOut(550);
						}

				);

				jQuery('#photo-gal-link *,  #sub-menu-history').stop().hover(

						function() {
							jQuery("#sub-menu-history").toggle(), jQuery(
									"#photo-gal-link > div").stop()
									.fadeTo(0, 1);
						},

						function() {
							jQuery("#sub-menu-history").hide(), jQuery(
									"#photo-gal-link > div").stop()
									.fadeOut(550);
						}

				);
				
			
						
			// FAV AJAX Clicks
				jQuery(".unfavThis, .favThis, .unfavThisImg, .favThisImg, .unfavThisProfile, .unfavThis-detail, .favThis-detail").live('click',function(e) {
			
				
					var targetz = jQuery(this).attr("id");	
					var newId = targetz.substring(4);
				
					jQuery.ajax({ url: jQuery(this).attr('href'), context: document.body, success: function(){					
					
												 

					}});
					var t= jQuery(this);
					//the list is expanding, rebuild this later
					if(jQuery(this).hasClass('unfavThis')) {
						t.attr('href',t.attr('href').replace('delete','private'));
						t.text("Favorite This");
						t.removeClass("unfavThis");
						t.addClass("favThis");
						jQuery.jGrowl("This item has been removed from your favorites", { life: 5000 });
					} else if(jQuery(this).hasClass('favThis')) {
						t.attr('href',t.attr('href').replace('private','delete'));
						t.text("Remove Favorite");
						t.removeClass("favThis");
						t.addClass("unfavThis");
						jQuery.jGrowl("This item has been added to  your favorites", { life: 5000 });
						
					} else if(jQuery(this).hasClass('favThis-detail')) { //details-page
						t.attr('href',t.attr('href').replace('private','delete'));
						t.html("<img src='/images/icons/remove.png' alt='Remove' />Remove Favorite");
						t.removeClass("favThis-detail");
						t.addClass("unfavThis-detail");
						jQuery.jGrowl("This item has been added to  your favorites", { life: 5000 });
						 
					} else if(jQuery(this).hasClass('unfavThis-detail')) { //details-page unfav
						t.attr('href',t.attr('href').replace('delete','private'));
						t.html("<img src='/images/icons/add.png' alt='Add' />Add to My Grenada");
						t.removeClass("unfavThis-detail");
						t.addClass("favThis-detail");
						jQuery.jGrowl("This item has been removed from your favorites", { life: 5000 });
						
					}
					else if(jQuery(this).hasClass('unfavThisImg')) { //map unfav
						t.attr('href',t.attr('href').replace('delete','private'));
						fimg = t.find("img");
						fimg.attr('src',fimg.attr('src').replace('images/icons/remove.png','images/icons/add.png'));
						t.removeClass("unfavThisImg");
						t.addClass("favThisImg");
						jQuery.jGrowl("This item has been removed from your favorites", { life: 5000 });
					} else if(jQuery(this).hasClass('favThisImg')) {
						fimg = t.find("img");
							t.attr('href',t.attr('href').replace('private','delete'));
						fimg.attr('src',fimg.attr('src').replace('images/icons/add.png','images/icons/remove.png'));
						
						t.removeClass("favThisImg");
						t.addClass("unfavThisImg");
							
						jQuery.jGrowl("This item has been added to  your favorites", { life: 5000 });
					} else if(jQuery(this).hasClass('unfavThisProfile')) {
					jQuery.jGrowl("This item has been removed from your favorites", { life: 5000 });
						jQuery(this).parent().parent().parent().remove();
							countFavs();
					}
					
					
				
	
					e.preventDefault();
					return false;
				});
			

			countFavs();	
			
			

			
				
			});
