$(document).ready(function(){
 	/*------------------- Galeries ------------------------------------------------------------------------*/
	//----------- Main Slideshow
	
	$('#specialOffer').cycle({ 
		fx:     'scrollUp', 
		speed:   1500, 
		timeout: 6000, 
		cleartype:  1
	 });
	
	function onBefore(curr,next,opts) { 
		$(this).find('p').hide();
	}
	
	function onAfter(curr,next,opts) { 
		$(this).find('p').fadeIn();
	}
	
	$('#pause').click(function() { $('#slideshow').cycle('pause'); return false; });
    $('#play').click(function() { $('#slideshow').cycle('resume'); return false; });

	/*-----------------------------------------------------------------------------------------*/
	//$('#content p:first').css('font-size','14px');
	
	target_h = $('#contentInner').find('h1').eq(0);
	heading = target_h.html();
	if (heading == '') target_h.hide();

	//Home content slider
	$("#flowpanes").scrollable({
		size: 1,
		clickable: false,
		easing:	'easeOutExpo',
		loop: true,
		speed: 1000
	}).mousewheel(1000).navigator({ 
        navi: "#flowtabs", 
        naviItem: 'a', 
        activeClass: 'active'
    })
	
	$('#flowtabs li:last').css('margin-right','0');
	$('div.offer:last').css('background','none');
	
	if  (!($('#subSubMenu').length)) {
		$('#content').not('#content.home').css({
			'background': 'none',
			'width': '690px',
			'left': '0',
			'top': '0',
			'padding': '0'
		});
		
	}
	$('div.offer').hover(function() { 
		$(this).css('background-color','#d1d1d1');
	}, function() {
		$(this).css('background-color','#d4e2f4');
	});

	$('#content a img').parent().css('border-bottom','none');	
	
	$('div.offer').click(function () {
		var link = $(this).find('a').attr('href');
		window.location = '/' + link;
	});

	$("img.tooltip[title]").tooltip({ 
		tip: '#tooltipWrapper', 
		position: "top left", 
	    offset: [-12, -10],
		effect: 'bouncy'
    // add dynamic plugin  
    }); 
	$.tools.tooltip.addEffect("bouncy", 
		function(done) { 
			this.getTip().animate({top: '+=15'}, 500, 'bouncy', done).show(); 
		}, 
		function(done) { 
			this.getTip().animate({top: '-=15'}, 500, 'bouncy', function()  { 
				$(this).hide(); 
				done.call(); 
			}); 
		} 
	);
	/*--------------------------------65--------------------------------------------------------*/
	/*-----------------------------------------------------------------------------------------*/
	$.easing.custom = function (x, t, b, c, d) { 
		var s = 1.70158;  
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; 
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; 
	}
	$.easing.easeOutExpo = function (x, t, b, c, d) {
		return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
	};
	$.easing.easeOutBounce = function (x, t, b, c, d) {
		if ((t/=d) < (1/2.75)) {
			return c*(7.5625*t*t) + b;
		} else if (t < (2/2.75)) {
			return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
		} else if (t < (2.5/2.75)) {
			return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
		} else {
			return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
		}
	};
	$.easing.bouncy = function (x, t, b, c, d) { 
		var s = 1.70158; 
		if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; 
		return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; 
	} 
	/*------------------------------------------------------------------------------------------------------*/
	//Search form validation
	$("form#ajaxSearch_form").submit(function() {
		if ( ($("input#ajaxSearch_input").val() == "") || ($("input#ajaxSearch_input").val() == "Search here...")){
			//alert('Please type your name');
			alert('At least 3 characters are required for your search term');
			return false;
		}
    });
	
	/*---- Date picker---*/
	$('.date-pick-noback').datePicker({
			clickInput:true
	});
	
	/*-------------------------------------------------*/
	
	var status = $("input[name='meeting']:checked").val();
	if (status == 'Yes') {
		$('#meeting_details').show();
	}
	
	$("input[name='meeting']").click( function() {
	  var data = $("input[name='meeting']:checked").val();
	  if (data == 'Yes') {
	 	$('#meeting_details').slideDown();

	  } else {
		$('#meeting_details').slideUp();
	  }

	});
	/*---------------------------------------------------------------------------------*/
	
	$(".date-pick").datepicker({
			changeMonth: true,
			changeYear: true,
			minDate: -36524,
			dateFormat: 'dd/mm/yy',
			showOn: 'both', 
			buttonImage: 'assets/templates/default_tpl/images/calendar.gif',
			buttonImageOnly: true,
			buttonText: 'Pick the date'
	});


	/*---- Quotes -----------------*/
	$('input#arrange_cover_btn, input#request_callback_btn').click(function() 
	{
		if ($('input#terms').is(':checked')) 
		{
			//alert('Checked');
			return true;
		}
		else 
		{
			alert('You need to corfirm terms and conditions');
			return false;
		}
	});
	
	/*--- Mortgage Protection ----*/
	var status = $("select[name='JointCoverBasis']").val();
	if (status == 'JLFD' || (status == 'DUAL')) {
	 	$('#add_person').show();
	}

	$("select[name='JointCoverBasis']").change( function() {
	  var data = $("select[name='JointCoverBasis']").val();
	  if ((data == 'JLFD') || (data == 'DUAL')) {
	 	$('#add_person').slideDown();
	  } else {
		$('#add_person').slideUp();
	  }
	});

	$("form#mortgage_protection_form").submit(function() {
		
		person_status = $("select[name='JointCoverBasis']").val();	
		
		gender2 = $("select[name='Sex2']").val();
		dob2 = $("input[name='Dob2']").val();

		if (person_status != 'Single') {
			if (gender2 == '' || dob2 == '') {
				$("select[name='Sex2']").addClass('requiredValue');
				$("input[name='Dob2']").addClass('requiredValue');

				return false;
			} 
		}
		return true;
	});


	
	/*----------------------------------------------------------------------------------*/
	
}); //Close document.ready

$(window).bind("load", function() {							
    //-----------  Preload images for 
	
	$('.loading').each(function () {
		$(this).hide();
	});
	$('#specialOffer, #tabs').fadeIn('slow');
	$('#slideshowWrapper').fadeIn('slow');

});

function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}

function bookmarksite(title,url)
{
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
}

