BTRAV.updateRegisterLoginInfo = 'yes';

BTRAV.updateRegisterInfo = function(what) {
	if (typeof(BTRAV.updateRegisterLoginInfo) != "undefined" && BTRAV.updateRegisterLoginInfo == 'yes') {
        if (what == 'login') {
            var $infoDiv = $("#benefitsInfo");        
        } else {
            var $infoDiv = $("#registerInfo");
        }
		$.ajax({
		   type: "GET",
		   url: 'http://www.budgettravel.com/bt-srv/register/' + what + '_info.html',
		   dataType: "html",
		   success: function(data) {
			   $infoDiv.html(data);
		   }
		});  			
		if (what == 'register') {
			if ( $("#promo_opt_in").css("display") == 'none') {
				$("#promo_opt_in").remove();
			}
		}
	}
}
    
if (typeof(BTRAV.spammers_id) == "undefined") { BTRAV.spammers_id = [];}
BTRAV.isInArray = function(searchVal,searchArray) {
	var index = 0;
	while (index < searchArray.length)
	{
        if (searchArray[index] == searchVal) { 
 	    index = searchArray.length; 		  
		return true;
	  } else { 
	  	index++;
	  }
	}
	return false;	
}

    
if (typeof("BTRAV.ads.activeAdSlots" != "undefined")) {
    BTRAV.ads.activeAdSlots += ',rightpromotile';
    BTRAV.ads.featureBar_ad_sitename += ',budgettravel.destinations/europe,budgettravel.destinations/caribbean,budgettravel.destinations/mexicoandcentralamerica, budgettravel.destinations/asia,budgettravel.destinations/southamerica,budgettravel.destinations/australiaandsouthpacific,,budgettravel.destinations/africaandmiddleeast,budgettravel.strategies, budgettravel.strategies/airfares,budgettravel.strategies/cruises, budgettravel.strategies/carrentals,budgettravel.strategies/dining,budgettravel.tripideas,budgettravel.tripideas/family,budgettravel.tripideas/roadtrips, budgettravel.tripideas/adventuretravel, budgettravel.tripideas/nationalparks,budgettravel.tripideas/wine,budgettravel.tripideas/solotravel,budgettravel.tripideas/longweekends';
}

$(function() {
    if ( typeof(BTRAV.getQueryVariable("src")) != "undefined" ) {
        $("#content-body .pagination a").each(function() {
          var $aHref = $(this).attr("href");
          if ($aHref.indexOf("?") >= 0) { var newHref = $aHref + '&src=' + BTRAV.getQueryVariable("src"); } else {var newHref = $aHref + '?src=' + + BTRAV.getQueryVariable("src");}
          $(this).attr("href", newHref)
        });        
    } 
});

$(function() {
    if ( $("#commentsbar").length > 0 && $("#commentsbar").text().length > 5 && $("#commentsbar").css("margin-left") == '4px') {
        $("#commentsbar").appendTo($("#sharetools"));
    }
});


$(function() {
    $("#deals-scroller a.next, #deals-scroller a.prev").unbind('click');
		$("#deals-scroller a.next, #deals-scroller a.prev").click(function(e) {
		e.preventDefault();		
		var item_width = 340;
		var item_per_scroll = 1;
		var $dealsLi = $("#deals-scroller>li");
		var num_items = $dealsLi.length;	
		
		if ($(this).hasClass("next")) {
			var nextActive = 0;
			 $dealsLi.each(function(i) {
				if ($(this).hasClass("active")) {
					nextActive = i + 1;
					$(this).removeClass("active");
				}
			});

		} else {
			var nextActive = 0;
			 $dealsLi.each(function(i) {
				if ($(this).hasClass("active")) {
					nextActive = i - 1;
					$(this).removeClass("active");
				}
			});
		}		
		var $nextActive =  $dealsLi.eq(nextActive).addClass("active");						
		var nextLeft = $nextActive.position().left * -1;			
		$("#deals-scroller").animate({left: nextLeft});
		
	});
});


// Photoslideshow update on Contest page

var photoSlideshow = {
	moveLeft: 102,
	numPhoto: 3,
	offsetMargin: 30,
    preLoadImages: function() {
        $(".photo-window a").each(function() {
			var tmpImage = new Image();
			tmpImage.src = $(this).attr("href");	            
        });
    },
	init: function(numPhoto,moveLeft) {
        photoSlideshow.preLoadImages();
		photoSlideshow.moveLeftPos = moveLeft;
		photoSlideshow.numPhoto = numPhoto;
        var $finalist = $("#finalists-details");
		$('<img src="" id="photo-slider-Overlay" />').appendTo("body");			
		$finalist.find(".photo-slideshow .nextSlide").click( photoSlideshow.nextSlide);
		$finalist.find(".photo-slideshow .prevSlide").click( photoSlideshow.prevSlide).css("visibility","hidden");		
		$finalist.find(".photo-window a").click(function(e){ e.preventDefault();}).hover(function() {
			$(this).HideAllBubblePopups();
			$(this).CreateBubblePopup( {
				position:  'top', 
				themeName: 'grey', 
				themePath: '/site_media/img/jquerybubblepopup-theme', 
				selectable: false,
				alwaysVisible: false,
				themeMargins: {total: '8px', difference: '4px'}				
			})
			.each( function(){ 
			var tmpImage = new Image();
			tmpImage.src = $(this).attr("href");		
			var titleText = $(this).attr("title");
			if ( typeof($(this).data('titleText')) == "undefined") {
				$(this).data('titleText',titleText);			
				$(this).attr("title","");
			}
			(typeof(tmpImage.width) != "undefined" && tmpImage.width > 90) ? maxcaptionWidth = tmpImage.width + 'px': maxcaptionWidth = 'auto';
			$(this).SetBubblePopupInnerHtml('<div class="largeImage"><img src="' + $(this).attr("href") + '" /><p class="caption" style="width:' + maxcaptionWidth + ';">' + $(this).data('titleText') + '</p></div>' ); });					
			}, function(){ $(this).RemoveBubblePopup();} );
	},
	nextSlide: function(e) {
		e.preventDefault();
		var $currentPhotoWindow = $(this).siblings(".photo-slider").find(".photo-window");
		var nextLeft = $currentPhotoWindow.position().left  - (photoSlideshow.moveLeft * 3);
		$currentPhotoWindow.animate({left: nextLeft});
		 if ( typeof($(this).data("lastPhotoToSlide")) == "undefined") {;
			var lastPhotoToSlide = $(this).siblings(".photo-slider").find(".photo-window a").length * photoSlideshow.moveLeft * -1  + photoSlideshow.offsetMargin;			
			$(this).data("lastPhotoToSlide",lastPhotoToSlide);
			$(this).data("previousSlideBtn",$(this).siblings(".prevSlide"));
		 }
		 $(this).data("previousSlideBtn").css("visibility","visible");	 
		if ( (photoSlideshow.moveLeftPos * photoSlideshow.numPhoto * -1 + nextLeft ) <= $(this).data("lastPhotoToSlide") ) { $(this).css("visibility","hidden")};			
	},
	prevSlide: function(e) {
		e.preventDefault();
		var $currentPhotoWindow = $(this).siblings(".photo-slider").find(".photo-window");
		var nextLeft = $currentPhotoWindow.position().left  + (photoSlideshow.moveLeft * 3);
		$currentPhotoWindow.animate({left: nextLeft});
		 if ( typeof($(this).data("nextSlideBtn")) == "undefined") {;
			$(this).data("nextSlideBtn",$(this).siblings(".nextSlide"));
		 }
		$(this).data("nextSlideBtn").css("visibility","visible");	
		if ( nextLeft >= (photoSlideshow.offsetMargin * -1) ) { $(this).css("visibility","hidden")};					 
	},
	openOverlay: function(imageSrc, imageWith, imageHeight) {
		$("#photo-slider-Overlay").attr("src",imageSrc).modal({width: imageWith, height: imageHeight, onClose: function(dialog){ $("#photo-slider-Overlay").attr("src",""); $.modal.close();}, overlayClose:true});
		return false;
	}
}





