// Global jQuery file included sitewide

$(document).ready(function(){
						   
		//facebox
  	$('a[rel*=facebox]').facebox();
	//facebox image slideshow
	$(document).bind('reveal.facebox', function() {//binds the click event only after the facebox has revealed
		$('#travel-to').hide();	
		$('#slideshow img').hover(function(event) {
			/*
			change the main-img src attribute by removing 'thumbnails' - 
			eg. /worldphone/img/content/heroshots/thumbnails/c118-angle.jpg > /worldphone/img/content/heroshots/c118-angle.jpg			
			*/
			$('#slideshow img').removeClass('hover-img');
			$(this).addClass('hover-img');
			$('#main-img img').attr('src',($(this).attr('src').replace('thumbnails','')));			
		});			
	});
	$(document).bind('close.facebox', function() {
	$('#travel-to').show();	
	});	
	
	//=====Special Offer Expanders START=====
		$('a.expand-offer').click(function(event){
			event.preventDefault();
			$(this).parent().next('div.offer-expander').slideToggle(200);
			//$('div.offer-expander').slideToggle(200);
		});

	//=====Special Offer Expanders END=====				   
						   
	//=====Expanders START=====
	$('div.toggle').hide();
	$('ul.product-info li a').toggle(function(event){
		//$('#faq-copy .answer').hide();
		event.preventDefault();
		$(this).next('div').slideToggle(200);
    	$(this).contents('img.expander').attr('src','/worldphone/img/content/info-close.png');
		//alert('on');
	},function(event) { // same here
		event.preventDefault();
		$(this).next('div').slideToggle(200);
    	$(this).contents('img.expander').attr('src','/worldphone/img/content/info-open.png');
    });
			
    //=====Expanders END=====	
	
	
	//=====FAQ Expanders ( added for split test, not on original )
	
	$('div.answer').hide();
	$('ol#answers li h5 a').toggle(function(event){
		event.preventDefault();
		$(this).parent().next('div').slideToggle(200);
	},function(event) { // same here
		event.preventDefault();
		$(this).parent().next('div').slideToggle(200);
    });

						   
	//noscript - hide the sections that are not needed with javascript.
	$(".noscript").hide();
	
	//rollovers
	$('.rollover').hover(
            function(){ // Change the input image's source when we "roll on"
                t = $(this);
                t.attr('src',t.attr('src').replace(/([^.]*)\.(.*)/, "$1-over.$2"));
            },
            function(){ 
                t= $(this);
                t.attr('src',t.attr('src').replace('-over',''));
            }
     );
	
	



		
		
		
	
	
	//heroshot slideshow
	
	       //$(this).contents('img.expander').attr('src','/worldphone/img/content/info-open.png');
		   ///worldphone/img/content/heroshots/thumbnails/c118-front.jpg

	



	
	//show javascript dependent elements
						   
	//ebook signup
	var fromLabel = $('#free-guide label').remove().text();
	$('#from').addClass('placeholder').val(fromLabel).focus(function(){
		if(this.value == fromLabel){
			$(this).val('');
		};
	}).blur(function(){
		if(this.value == ''){
			$(this).val(fromLabel);
		};	
	});
	
	
	//call rates dropdown
	$('.travel-to').change(function(){	
		$.ajax({
			type: "GET",
			url: "/worldphone/inc/rates/rates-viewer.php",
			data: "shtech=y&c_name="+escape($(this).val()),
			success: function(html){
				$(".rates-viewer").html(html);
				$(".rates-viewer tr.numbers td").css({ opacity: 0 }).fadeTo("slow",1);
			}
		});
	});
	
	//call rates dropdown h
	$('.travel-to-h').change(function(){	
		$.ajax({
			type: "GET",
			url: "/worldphone/inc/rates/rates-viewer-h.php",
			data: "shtech=y&c_name="+escape($(this).val()),
			success: function(html){
				$(".rates-viewer").html(html);
				$(".rates-viewer tr.numbers td").css({ opacity: 0 }).fadeTo("slow",1);
			}
		});
	});
	
	//shipping dropdown
	$('.ship-to').change(function(){	
		$.ajax({
			type: "GET",
			url: "/worldphone/inc/rates/shipping-viewer.php",
			data: "zone="+escape($(this).val()),
			success: function(html){
				$(".shipping-viewer").html(html);
				$(".shipping-viewer tr.numbers td").css({ opacity: 0 }).fadeTo("slow",1);
			}
		});
	});
	
	//frequency dropdown
	$('#network-freq').change(function(){	
		$.ajax({
			type: "GET",
			url: "/worldphone/inc/rates/freq-viewer.php",
			data: "c_name="+escape($(this).val()),
			success: function(html){
				$(".frequency-viewer.top").html(html);
				//$(".shipping-viewer tr.numbers td").css({ opacity: 0 }).fadeTo("slow",1);
			}
		});
	});
	//frequency dropdown
	$('#network-freq2').change(function(){	
		$.ajax({
			type: "GET",
			url: "/worldphone/inc/rates/freq-viewer.php",
			data: "c_name="+escape($(this).val()),
			success: function(html){
				$(".frequency-viewer.bottom").html(html);
				//$(".shipping-viewer tr.numbers td").css({ opacity: 0 }).fadeTo("slow",1);
			}
		});
	});
	
	//autocompleter
	
	/*var values = jQuery.map(jQuery("#travel-to")[0].options, function(option)
             {
                return option.value;
             });

	$("#auto").autocompleteArray(
	
	values							 
    //["Allen","Albert","Alberto","Alladin"]
	,
    {
            delay:10,
            minChars:1,
            matchSubset:1,
            //onItemSelect:selectItem,
            //onFindValue:findValue,
            autoFill:true,
            maxItemsToShow:10
    }
);*/
	
	




















});