/*
 * Author => Company       : Prodo Ltd
 *        => Website       : http://www.prodo.com
 * Code   => Last Modified : 06 April 2010
 */

$(function() {
	
	/*
	 * 
	 */
	$('#content').pngFix();
	
	/*
	 * Make external links open in a new window
	 */
	$('a[rel=external]').click(function(e) {
		open(this.href);
		e.preventDefault();
	}).attr('title', 'Opens in a new window');
	
	/*
	 * 
	 */
	$('.navigation ul li:last').addClass('last-item');
	
	/*
	 * Manipulate Umbraco's image alignment
	 */
	$('#content img').each(function(e) {
		if($(this).css('float') == 'left') {
			$(this).addClass('left');
		}
		else if($(this).css('float') == 'right') {
			$(this).addClass('right');
		}
	});
	
	/*
	 * Form default text
	 */
	$('.defaultText').focus(function(srcc) {
		if($(this).val() == $(this)[0].title) {
			$(this).removeClass('defaultTextActive');
			$(this).val('');
		}
	});
	
	$('.defaultText').blur(function() {
		if($(this).val() == '') {
			$(this).addClass('defaultTextActive');
			$(this).val($(this)[0].title);
		}
	});
	
	$('.defaultText').focus();
	$('.defaultText').blur();
	
	$('form').submit(function() {
		$('.defaultText').each(function() {
			if($(this).val() == this.title) {
				$(this).val('');
			}
		});
	});
	
    /*
     * SWFObject
     */
	if($('.home .flashBanner').length) {
		$('.home .flashBanner').flash({
			height : 320,
			params : {
				wmode  : 'transparent'
			},
			swf    : 'images/banner.swf',
			width  : 690
		});
	}
	
    /*
     * Conveyancing Calculator
     */
	$('.quote:not(.sale)').hide();
	
	$.quoteTypes = {
		'0' : $('.sale'),
		'1' : $('.purchase'),
		'2' : $('.sale, .purchase'),
		'3' : $('.remortgage'),
		'4' : $('.transfer-of-equity'),
		'5' : $('.transfer-of-equity-without-mortgage')
	};
	
	$('.quote-selector').change(function() {
		$('.calculator input:not([type=submit])').each(function() {
			this.value = '';
		});
		
		$.each($.quoteTypes, function() {
			this.hide();
		});
		
		$.quoteTypes[$(this).val()].show();
	});
	
});