$(document).ready(function() {
						   
	$('ul.productList li a').hover(function(){
		//alert("hi");
		$(this).parent().find(".description").css({"display" : "Block"});		
	},function(){
		$(this).parent().find(".description").css({"display" : "None"});
	
	});	
	
	$('.myPanel2 .infoTooltip a').hover(function(){
		//alert("hi");
		$(this).parent().parent().parent().find(".tooltip2").css({"display" : "Block"});		
	},function(){
		$(this).parent().parent().parent().find(".tooltip2").css({"display" : "None"});
	
	});
	
	$('.myPanel2 .infoTooltip a').click(function(){
		return false;
	});
	
	$('.myPanel2 .filterOff').live("click", function(){
		$(this).removeClass("filterOff");
		$(this).addClass("filterOn");
		$(this).parent().parent().addClass("on");
		$(this).parent().parent().parent().find(".checkboxrow").css({"display" : "Block"});
		return false;
	});
	
	$('.myPanel2 .filterOn').live("click", function(){
		$(this).removeClass("filterOn");
		$(this).addClass("filterOff");
		$(this).parent().parent().removeClass("on");
		$(this).parent().parent().parent().find(".checkboxrow").css({"display" : "None"});
		return false;
	});
							   
	$(".shareNugget input").val("Enter your email address");
	$(".shareNugget input").focus(function () {        
            $(this).css({ "color": "#000" });
            $(this).val("");
    });						   
						   
	$('ul#alphabet a').click(function(){
		var jump = $(this).parent().attr('id');
		var new_position = $('.jumpTo'+jump).offset();
		window.scrollTo(new_position.left,new_position.top);
		return false;
	});
	
	$('.alphabetSectionHeader a').click(function(){
		window.scrollTo(0,0);
		return false;
	});
		
	$("#voucherSearch").tokenInput("http://www.cheap.co.uk/shopping/discount-codes/retailers/jsonFeed.aspx", {
		onAdd: function (item) {
			$(".token-input-list").css({"display":"none"});
			$("#searchBoxArea a").css({"display":"none"});
			$("#searchBoxArea").append("<div class='searchLoading'><img src='/images/ajax-loader.gif' /></div>");
			setTimeout(function(){
				//alert(item.url); 
				$url = item.url;				
				window.location = "http://www.cheap.co.uk/discount-codes/retailers/"+$url.toLowerCase()+".htm";		
			},1000);
		},
		onDelete: function (item) {
			
		}
	});
	
	$("#retailSliderRight").click(function() {
										   
			clearInterval(intervalID);
			var pos = parseInt($('ul#voucherRetailers').css('marginLeft'));
			$("ul#voucherRetailers").animate({marginLeft: (pos-176)});
			return false;
	});

	$("#retailSliderLeft").click(function() {
			clearInterval(intervalID);										  
			var pos = parseInt($('ul#voucherRetailers').css('marginLeft'));
			$("ul#voucherRetailers").animate({marginLeft: (pos+176)});
			return false;
	});
	
	
	
	var intervalID = setInterval(slideRetailers, 3000);
	
	$("ul#voucherRetailers").hover(function() {
		clearInterval(intervalID);
	}, function(){
		
		intervalID = setInterval(slideRetailers, 3000);
	});

						   
	$("a.getVoucher").click(function() {
			$(this).parent().parent().parent().find(".hiddenTR").slideDown();
			$(this).parent().parent().parent().parent().parent().css({"backgroundColor":"#f1f9fc"});
	});
	
	$("#slider2").easySlider({
		auto: 				true, 
		continuous: 		true,
		pauseable:			true,
		speed: 				1500
	});	
	
	/* Initialise calendar control IF it exists on the page */
	if ($('a.calendar').length > 0) {
		$('body').append("<script type='text/javascript' src='/controls/datecontrol/calendar.js'></script>");
	};
	
	$('.cc_placeholder img').hover(function(){
		$(this).parent().find('.cc_tooltip').show();								   
	},function(){$(this).parent().find('.cc_tooltip').hide();});
	
	/* Tell a friend */
		$("#tellafriendmiddle a").click(function() {
			if($("#tellafriendform").css("display") == "none")
			{
				$('#tellafriendform').slideToggle();
			}
			else
			{
				alert("fill form");	
			}
		});
		
	var page = $('body').attr('class');
	
	
	//alert(page);
	
	
	
	if(page == "default" || page == "money" || page == "travel" || page == "insurance" || page == "legalservices" || page == "shopping" || page == "tickets")
	{
		$('body').find('#mainNavigation #'+page).addClass("on");
	}
	else
	{	
		var level = $('body').find('#mainNavigation #'+page).parent().attr("class");
		if(level == "topLevel")
		{
			
			$('body').find('#mainNavigation #'+page).parent().parent().addClass("on");
		}
		else
		{
			$('body').find('#mainNavigation #'+page).parent().parent().parent().parent().addClass("on");
		}
		
		
		//$('body').find('#mainNavigation #'+page).parent().parent().parent().parent().addClass("on");
	}
	
	$("a.tellFriend").click(function() {
		$('#tellafriendform').slideDown();
		$('.large').animate({height : '350px'});
		return false;
	});

/*ferries provider tables*/
$(".tableMask").each(function(){
	if($(this).find(".ferryCrossings tr").length < 5)
	{
		var height = 29*$(this).find(".ferryCrossings tr").length;
		$(this).css({"height": height});		
	}
	else
	{
		$(this).append('<div class="maskViewMore"><div class="viewMoreLeft"></div><a class="tableViewMore" href="#"><span>View More</span></a><a class="tableViewMore2" href="#"><span>Close</span></a><div class="viewMoreRight"></div></div>');
		$(this).css({"height": 121});	
	}
});

/* Credit Cards Table Bubbles */
$('.creditCardTable a.moreInfoek').click(function(){
	$(this).parent().append("<div class='bubblePoint'></div>");
	$(this).parent().parent().next().find('div:first').append("<div class='bubblePoint'></div>");
	$(this).parent().parent().next().find('td').fadeIn();
	$(this).parent().parent().prev().find("div").css({"display":"none"});
	$(".transparent").css({"display":"inline"});
	return false;
})
$(".bubbleClose").click(function(){
	$(".creditCardTable").find(".bubblePoint").remove();
	$(this).parent().parent().parent().parent().parent().find(".holder").css({"display":"block"});
	$(this).parent().parent().parent().fadeOut();
	$('.transparent').fadeOut();
	
	return false;
})


$(".creditCardTable .bgArea a").hover(function(){
	//$(this).parent().css({"background":"#f1fbfe"});
},
function(){
	$(this).parent().css({"background":"none"});
});
/* Credit Cards Table Bubbles END */

$("#mapCont2 a").hover(function(){
	$(this).html("");
	$(this).css({"textIndent":"0px"});
	$(this).append("<div class='mapToolTip'>"+$(this).attr('title')+"</div>");
},
function(){
	$(this).html("");
});



/* large Thumb hover */
$('.largeThumbs li a').hover(function(){
	$(this).parent().css({"background":"url(/images/largeThumbBG2.gif)"});
},
function(){
	$(this).parent().css({"background":"url(/images/largeThumbBG.gif)"});
});

 

	$('#mainNavigation li a').not(".on a").mouseenter(function(){	
		$("#mainNavigation li.on ul li ul").hide();
		$(this).next().show();		
		$(this).parent().next().mouseenter(function(){
			$(this).prev().find('ul').hide();
		});		
		$(this).parent().prev().mouseenter(function(){
			$(this).next().find('ul').hide();
		});		
	});
	
	$('#mainNavigation li.on ul li a').mouseenter(function(){														   
		$(this).next().show();
		$(this).parent().next().mouseenter(function(){
			$(this).prev().find('ul').hide();
		});		
		$(this).parent().prev().mouseenter(function(){
			$(this).next().find('ul').hide();
		});		
	});
	
	$('#mainNavigation li ul li ul').mouseleave(function(){														   
		$("#mainNavigation li ul li ul").hide();	
	});
	
	$('#mainNavigation').mouseleave(function(){
		$('#mainNavigation li ul').not(".on ul").hide();
		//$('#mainNavigation li a.topLevel').css({"background":"none"});
	});
	
	$('#mainNavigation').mouseleave(function(){
		$('#mainNavigation li.on ul li ul').hide();
		//$('#mainNavigation li a.topLevel').css({"background":"none"});
	});
	
	$('#mainNavigation .on ul').mouseenter(function(){
		$('#mainNavigation li ul').not(".on ul").hide();		
	});

/* Dropdown Navigation
	$('#mainNavigation').mouseleave(function(){
		$('#mainNavigation li ul').hide();
		//$('#mainNavigation li a.topLevel').css({"background":"none"});
	});
	
	$('#mainNavigation li.secondLevel ul').mouseleave(function(){
		$('#mainNavigation li.secondLevel ul').hide();
		//$('#mainNavigation li a.topLevel').css({"background":"none"});
	});

*/
/* End */

$("a.tableViewMore").click(function() {
	$(this).css({"display": "none"});
	$("a.tableViewMore2").css({"display": "block"});
	height = $(this).parent().parent().find(".ferryCrossings").height()+15;
	$(this).parent().parent().animate({
    	height: height
  	});
	return false;
});

$("a.tableViewMore2").click(function() {
	$(this).css({"display": "none"});
	$("a.tableViewMore").css({"display": "block"});
	$(this).parent().parent().animate({
    	height: 121
  	});
	return false;
});

/* footer providers */
$("ul.providersFooter li a").click(function() {
	$("ul.providersFooter").each(function(){
		$(this).find(".on").css({"display":"none"});	
		$(this).find(".off").css({"display":"inline"});	
	});
	//alert("click");
	$(this).find(".off").css({"display":"none"});
	$(this).find(".on").css({"display":"inline"});
});
	
	/* Initialise user rating IF it exists on the page */
	if ($('.userRating').length > 0) {
		$('body').append("<script type='text/javascript' src='/scripts/jquery.rating.js'></script>");
	};

	/* Intialise tabbed pannel IF it exists on the page */
	if ($(".panelTabbed").length > 0) {
		$('body').append("<script type='text/javascript' src='/scripts/jquery.tabs.pack.js'></script>");
		$('.tabs-hide').css('display', 'none');
		$('.panelTabbed').tabs({ fxFade: false, fxSpeed: 'fast' });
	};

	/* Initialise slider panel IF it exists on the page */
	if ($(".panelSlider").length > 0) {
		$('body').append("<script type='text/javascript' src='/scripts/jquery.anythingslider.js'></script>" + "<script type='text/javascript' src='/scripts/jquery.easing.1.2.js'></script>");
		function formatText(index, panel) {
			return index + "";
		}
		$(function() {
			$('.panelSlider').anythingSlider({
				easing: "easeInOutExpo",        		// Anything other than "linear" or "swing" requires the easing plugin
				autoPlay: true,                 		// This turns off the entire FUNCTIONALY, not just if it starts running or not.
				delay: 7000,                    		// How long between slide transitions in AutoPlay mode
				startStopped: false,            		// If autoPlay is on, this can force it to start stopped
				animationTime: 900,             		// How long the slide transition takes
				hashTags: false,                 		// Should links change the hashtag in the URL?
				buildNavigation: true,          		// If true, builds and list of anchor links to link to each slide
				pauseOnHover: true,             		// If true, and autoPlay is enabled, the show will pause on hover
				startText: "Go",             			// Start text
				stopText: "Stop",               		// Stop text
				navigationFormatter: formatText      	// Details at the top of the file on this use (advanced use)
			});
			$("#slide-jump").click(function() {
				$('.panelSlider').anythingSlider(6);
			});
		});
	};
	$(".informationPanel .reviewToggle").click(function() {
		$(this).closest(".informationPanel").find(".reviewInfo").toggle();
	});
	$("a.openHelp").click(function() {
		$(".helpContent").slideToggle();
	});
	$('a.summaryToggle').click(function() {
		$('#summary').slideToggle();
	});
	$('#stepProcess ul li#activeStep img').fadeIn("slow")

	$('.adNugget img.adAvatar').fadeTo('fast', 0.5);
	$('.adNugget').mouseenter(function() {
		$(this).find('img.adAvatar').fadeTo('slow', 1.0);
	});
	$('.adNugget').mouseleave(function() {
		$(this).find('img.adAvatar').fadeTo('slow', 0.5);
	});

	/* Help Area*/
	$(".helpContent li a").click(
		function() {
			$(this).parent().animate({ marginTop: "-130px" }, 200);
		});

	$(".helpContent li").mouseleave(
		function() {
			$(this).animate({ marginTop: "0px" }, 200);
		});
	$(".helpContent a").bind("click", function(e) {
		e.preventDefault(); /* prevents default behavior */
	});
	/* Help Area End */

	/* Quote Information Panels */

	jQuery.fn.fadeToggle = function(speed, easing, callback) {
		return this.animate({ opacity: 'toggle' }, speed, easing, callback);

	};

	$("a.toggleDirections").click(function() {
		$(this).toggleClass('directionsButtonSelected');
		$(this).text($(this).text() == 'Get Directions & View Map' ? 'Click to close panel' : 'Get Directions & View Map');
		$(this).parent().parent().next(".supplierInfo").slideToggle("fast", function() {
			$(this).parent().parent().find(".newPanel").toggleClass("newPanelSelected");
			$(this).parent().parent().find(".overlay").css('display', 'none');
		});
		$(".overlay").fadeToggle("slow");
		$.scrollTo($(this).parent().parent().parent().parent().find(".newPanel"), 500, { queue: true });
	});
	
	$("a.toggleReviews").click(function() {
		$(this).toggleClass('reviewsButtonSelected');
		$(this).text($(this).text() == '2 reviews' ? 'Close' : '2 reviews');
		$(this).parent().parent().next().next(".reviewInfo").slideToggle("fast", function() {
			$(this).parent().parent().find(".newPanel").toggleClass("newPanelSelected");
			$(this).parent().parent().find(".overlay").css('display', 'none');
		});
		$(".overlay").fadeToggle("slow");
		$.scrollTo($(this).parent().parent().parent().parent().find(".newPanel"), 500, { queue: true });
	});
	$("a.toggleMoreInfo").click(function() {
		$(this).toggleClass('directionsButtonSelected');
		$(this).text($(this).text() == 'See More Information' ? 'Click to close panel' : 'See More Information');
		$(this).parent().parent().next(".moreInformation").slideToggle("fast", function() {
			$(this).parent().parent().find(".newPanel").toggleClass("newPanelSelected");
			$(this).parent().parent().find(".overlay").css('display', 'none');
		});
		$(".overlay").fadeToggle("slow");
		$.scrollTo($(this).parent().parent().parent().parent().find(".newPanel"), 500, { queue: true });
	});
	
	$("a.toggleBookMoreInfo").click(function() {
		if($(this).find("img").attr("src") == "/images/buttons/bookButton.gif")
		{
			$(this).find("img").attr("src", "/images/buttons/bookButtonClose.gif");
		}
		else
		{
			$(this).find("img").attr("src", "/images/buttons/bookButton.gif");
		}
		
		$(this).parent().parent().next(".moreInformation").slideToggle("fast", function() {
			//$(this).closest(".newPanel").toggleClass("newPanelSelected");
			$(this).parent().find(".overlay").css('display', 'none');
		});
		$(".overlay").toggle();		
	});
	
	$("a.toggleDirections, a.toggleReviews, a.toggleMoreInfo, a.infoToggle, a.toggleBookMoreInfo").bind("click", function(e) {
		e.preventDefault();
	});
	/* Quote information panel end */

	var $url = self.location.href;

	$url = $url.split("/");
	
	if(($url[4] == "PaymentDetails.aspx") || ($url[4] == "3NewCustomer.aspx")){
		$('#summary').slideToggle("slow");
	}
	
	$("table.extras tr td u").click(function(){
		$(this).parent().parent().next().find(".infoExtra").fadeToggle();
	});
	
	/* Sub Menu (more ifnormation) */
	$('.moreInfo a').mouseenter(function(){
		$(this).css({'background' : 'url(/images/buttons/moreInfoHover.gif) no-repeat', 'text-decoration' : 'none', 'color' : '#336699'});
		$(this).parent().next('ul.subMenu').show();
	});
	$('.offers, .help').mouseenter(function(){
		$('.moreInfo a').css({'background' : 'none', 'color' : '#468aab'});
		$('ul.subMenu').hide();
	});
	$('ul.subMenu,  .tabs-container').mouseleave(function(){
		$('.moreInfo a').css({'background' : 'none', 'color' : '#468aab'});
		$('ul.subMenu').hide();
	});
	
	/* weather */
	
	if ($('#weatherwidget').length > 0) {
		//$destination = $('h1').text().replace("Cheap", "").replace("downtown", "").replace("airport", "").replace("Car Hire", "");
		$.ajax({
			 url: "http://www.google.com/ig/api?weather=Mountain+View",
			 type: "GET",
			 data: "",
			 success: function (xml) {		
			 	//alert("success");
				//$("#weatherwidget").html($(xml).find('city').text());
				 //$(xml).find('Comment').each(function(){
				//	$(".comments").append('<li>'+$(this).find('User').text()+'</a><span>'+$(this).find('Text').text()+'</span><span>'+$(this).find('Date').text()+'</span></li>');
				//});
			},
			error: function (xml, xml1, xml2) {		
			 	//alert(xml1);
				//$("#weatherwidget").html($(xml).find('city').text());
				 //$(xml).find('Comment').each(function(){
				//	$(".comments").append('<li>'+$(this).find('User').text()+'</a><span>'+$(this).find('Text').text()+'</span><span>'+$(this).find('Date').text()+'</span></li>');
				//});
			} ,
			complete: function(){
				//alert("complete");
			 // Handle the complete event
		   }

		});
	};
	/* New feature Slider */
	$('#featureSlider').ready(function(){
		$('a.right').bind('click', animateLeft);
		function animateLeft(){
			$('a.right').unbind('click');
			$('.slideContainer:first').animate({marginLeft: '-307px', opacity: '0'}, 500, function() {
				$(this).removeAttr('style').appendTo($('.features'));
				$('a.right').bind('click', animateLeft);
			});
			return false;
		};
		$('a.left').bind('click', animateRight);
		function animateRight(){
			$('a.left').unbind('click');
			$('.slideContainer:last').css({'margin-left' : '-307px'}).prependTo($('.features'))
			$('.slideContainer:first').animate({marginLeft: '0px'}, 500, function() {
				$('a.left').bind('click', animateRight);
			});
			$('.slideContainer').eq(2).animate({opacity: '0'}, 500, function() {
				$(this).animate({opacity: '1'})
			});
			return false;
		};
	});
	/* End */
	/* New Panel Fader */
	$('#panelFader').ready(function(){
		var first = 0;
		var speed = 700;
		var pause = 3500;
		
			function removeFirst(){
				first = $('ul#panelFader li:first').html();
				$('ul#panelFader li:first')
				.animate({opacity: 0}, speed)
				.fadeOut('slow', function() {$(this).remove();});
				addLast(first);
			}
			
			function addLast(first){
				last = '<li style="display:none">'+first+'</li>';
				$('ul#panelFader').append(last)
				$('ul#panelFader li:last')
				.animate({opacity: 1}, speed)
				.fadeIn('slow')
			}
		
		interval = setInterval(removeFirst, pause);
	});
	
	if($('#quote .time').length > 0){
		AddTimes();
	}
	
});

function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  } 	
}	

function sayCountry(country)
{
	$("#mapBubble").css({"color": "#359b35", "font-size": "160%"});
	var $im = "/quotes/ferries/images/"+country+"_flag.png".toLowerCase();
	$("#regionFlag").attr("src", $im)
	$("#mapBubble").text(country);
}

function CreateBookmarkLink() 
{
	title="Cheap.co.uk - travel extras"; 
	url="http://www.cheap.co.uk/";
	if (window.sidebar) 
	{ 
		// Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} 
	else if( window.external ) 
	{ 
		// IE Favorite
		window.external.AddFavorite( url, title);
	} 
	else if(window.opera && window.print) 
	{ 
		// Opera Hotlist
		return true; 
	}
}

function selectBoxes(){
	$('.dropDown').sSelect()
};

var slideCount = 0;
function slideRetailers()
{
	if (slideCount < 5)
	{
		var pos = parseInt($('ul#voucherRetailers').css('marginLeft'));
		$("ul#voucherRetailers").animate({marginLeft: (pos-176)});
		slideCount++;
	}
}

