/***********************************************
*************  PRELOAD IMAGES  ****************
************************************************/

	//$(document).ready(function(){
	//	$("<img>").attr("src", "/images/navigation/navigation-main.png");
	//});

/***********************************************
**********  CUFON REPLACEMENTS  ****************
************************************************/

	$(document).ready(function(){
							   
		Cufon.replace('#callUs h1');
		Cufon.replace('#contentWrapper h2',{hover: true});
		Cufon.replace('#contentWrapper h3');
		Cufon.replace('#rightPanel h1');
		Cufon.replace('#rightPanel h2');
		Cufon.replace('#rightPanel h3');
		Cufon.replace('#askExperts p');
		Cufon.replace('.featureAreaGeneral h1');
		Cufon.replace('.featureText .callWidget span');
		Cufon.replace('#customerTestimonials h2');
		Cufon.replace('h1.mNews');
		Cufon.replace('#mortgageQuote h1');
		Cufon.replace('#contactUs h1');
		Cufon.replace('#mortgageCalculators h1');
		Cufon.replace('#advancedBroker h1');
		Cufon.replace('#advancedBroker h2');
		Cufon.replace('#advancedBroker .contactNumbers p span');
		Cufon.replace('#careers h1');
	});
	


/***********************************************
************  HOMEPAGE BANNER   ****************
************************************************/



/***********************************************
***  BUTTON ROLLOVER & PRELOAD  ****************
************************************************/

$(document).ready(function() {
	// button rollover
	if ($('.imgBtn') != null) {
		$('.imgBtn').hover(function(){
				if(!$(this).is('.disabled'))
					$(this).attr("src", $(this).attr("src").replace(/^(.*?)(?:-hover)?(\..*?)$/i,'$1-hover$2'));
			},
			function(){
					if(!$(this).is('.disabled'))
						$(this).attr("src", $(this).attr("src").replace(/^(.*)-hover(\..*?)$/i, '$1$2'));
				});
	}
	// preload image rollovers
	if ($("img.imgBtn, img[src^='images/buttons/btn'], input[src^='images/buttons/btn']") != null) {
	    $("img.imgBtn, img[src^='images/buttons/btn'], input[src^='images/buttons/btn']").each(function(){
			    $("<img>").attr("src", $(this).attr("src").replace(/(btn-.*)(\..*?)/i, '$1-hover$2'));
		    });
	}

/***********************************************
***  EXTERNAL LINKS  ***************************
************************************************/

	$("a[rel=external]").each(function() {
		$(this).addClass('external');
		$(this).attr({
			target: "_blank"
		});
	})
});

/***********************************************
********  ANIMATED SCROLLING   *****************
************************************************/

$(document).ready(function(){
		$('.GoTop').click(function(){
				var id = $(this).attr('href');
				if(id.length === 1) return;
				var ele = $(id);
				if(ele.length) {
					var destination = ele.offset().top;
					$('html:not(:animated), body:not(:animated)').animate({
							scrollTop: destination -20
						}, 700, 'easeOutQuint');
				}
			});
	});

/***********************************************
***  COMPACT FORM (LABEL OVER INPUT)  **********
************************************************/

$(function(){
	$('form.compact input, form.compact select, form.compact textarea').focus(function(){
			$('label[for=' + $(this).attr('id') + ']').hide();
		});
	$('form.compact input, form.compact select, form.compact textarea').each(function(ele){
			if($(this).val().length > 0)
				$('label[for=' + $(this).attr('id') + ']').css({ display: "none" });
		});
	$('form.compact input, form.compact select, form.compact textarea').blur(function(){
			if($(this).val().length == 0)
				$('label[for=' + $(this).attr('id') + ']').show();
		});
	$('form.compact').removeClass('compact');
});





  
/***********************************************
*************** TWITTER FEEDS ******************
************************************************/  
  
$(function(){
      $("#twitterFeed").tweet({
        join_text: "auto",
        //username: "1300BROKER",
        username: ["1300BROKER", "1300BROKER"], // IE9 fix
        avatar_size: 24,
        count: 3,
        auto_join_text_default: "we said,",
        auto_join_text_ed: "we",
        auto_join_text_ing: "we were",
        auto_join_text_reply: "we replied",
        auto_join_text_url: "we were checking out",
        loading_text: "loading tweets..."
      });
});




/***********************************************
******** HOME PAGE PARTNER LOGO ROTATOR ********
************************************************/  


function theRotator() {
	$('div.rotator ul li').css({opacity: 0.0});
	$('div.rotator ul li:first').css({opacity: 1.0});
	setInterval('rotate()',6000);
}

function rotate() {	
	var current = ($('div.rotator ul li.show')?  $('div.rotator ul li.show') : $('div.rotator ul li:first'));
    if ( current.length == 0 ) current = $('div.rotator ul li:first');
	var next = ((current.next().length) ? ((current.next().hasClass('show')) ? $('div.rotator ul li:first') :current.next()) : $('div.rotator ul li:first'));
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
};
$(document).ready(function() {		
	theRotator();
	$('div.rotator').fadeIn(1000);
    $('div.rotator ul li').fadeIn(1000); // tweek for IE
});


/***********************************************
******************** MISC *********************
************************************************/  

$(document).ready(function(){
	// SMS Broker Button
	$('a.btnSmsBroker').click(function(){
		$(this).css('opacity','0.25');
		$('#brokerInfoBlock').hide();
		$('#smsBrokerForm').fadeIn(500);
		return false
	});
	
		// SMS Broker BACK Button
	$('a.backBtn').click(function(){
		$('a.btnSmsBroker').css('opacity','1');
		$('#smsBrokerForm').hide();
		$('#brokerInfoBlock').fadeIn(500);
		return false
	});
	
		// News Item PDF Btn
	$(".newsItem").hover(function () {
	  $(this).addClass("hilite");
      $(this).find('a.downloadPDF').stop().animate({
			opacity:1											
		},500);
    }, function () {
      $(this).find('a.downloadPDF').stop().animate({
			opacity:0											
		},500);
	   $(this).removeClass("hilite");
	   return false
    });
	
	// Advanced Broker Page
	$("#advancedBroker div.advancedBrokerFeature .abDetails .emailWeb a").hover(function () {
      $(this).stop().animate({
		color: '#fff',
		backgroundColor:'#72b6f3'
		});
    }, function () {
	  $(this).stop().animate({
		color: '#2D52A4',
		backgroundColor:'#eee'
		});
    });
	
	// Advanced Broker Page SMS Broker Button
	$('.abDetails a.smsBroker').click(function(){
		$(this).fadeOut('fast');
		$('.contactNumbers,.emailWeb').hide();
		$('#smsAdvBrokerForm').fadeIn('slow');
		return false
	});
	$('#smsAdvBrokerForm a.backBtn').click(function(){
		$('#smsAdvBrokerForm').hide();
		$('.contactNumbers,.emailWeb,.abDetails a.smsBroker').fadeIn('fast');
		return false
	});
	
	// Mortgage Guide PDF Btn
	$(".mortgageGuideDownloads div").hover(function () {
      $(this).find('a.downloadPDF').stop().animate({
			opacity:1											
		},500);
    }, function () {
      $(this).find('a.downloadPDF').stop().animate({
			opacity:0											
		},150);
	   return false
    });
	
	
	
	
	
	
	
});





