var sliderHeight = "53px";

$(document).ready(function(){ 

	$('.slideshow').cycle({
		fx: 'scrollRight',
		timeout: 7000,
		speed: 1500,
		pager:  '.buttons',
    	pagerAnchorBuilder: function(idx, slide) { 
        	return '.buttons li:eq(' + idx + ') a';
		}
	});
	
	$('ul.buttons li a.btn_limited').click(function() {
		window.location = '/services/limited-company-service';							
	})
	
	$('ul.buttons li a.btn_umbrella').click(function() {
		window.location = '/services/umbrella-company-service';							
	})
	
	$('ul.buttons li a.btn_sole_trader').click(function() {
		window.location = '/services/sole-trader-service';							
	})
	
	$('#other').click(function() {
  		$('#target').click();
	});
	
	$('.quotes').cycle({
		fx: 'fade',
		timeout: 7000,
		speed: 2000
	});
	
	$('.brands').cycle({
		fx: 'fade',
		timeout: 7000,
		speed: 2000
	});
	
	function addMega(){
        $(this).addClass("hovering");
		$(this).find('.section_div').height(($(this).find('.inner').height()-13));
	}

	function removeMega(){
		$(this).removeClass("hovering");
	}

	var megaConfig = {
		interval: 50,
		sensitivity: 8,
		over: addMega,
		timeout: 50,
		out: removeMega
	};

	$("li.mega").hoverIntent(megaConfig);

	var default_values = new Array();
	
	$("input.default_value").focus(function() {
		if (!default_values[this.id]) {
			default_values[this.id] = this.value;
		}
		
		if (this.value == default_values[this.id]) {
			this.value = '';
			$(this).css({'color' : '#415A68'});
		}
		
		$(this).blur(function() {
			if (this.value == '') {
				this.value = default_values[this.id];
				$(this).css({'color' : '#99ABB7'});
			}
		});
	});
	
	$('.form_newsletter').submit(function() {
		if($('#cm-name').val() == 'Your name'){
			alert('Please enter a name');
			return false;
		}
		
		if($('#cm-pwhhh-pwhhh').val() == 'Your email'){
			alert('Please enter a email');
			return false;
		}					  
	});
	
	$('.slider').each(function () {
		var current = $(this);
		current.attr("box_h", current.height());
	});

 
    $(".slider").css("height", sliderHeight);
    $(".slider_menu").html('<a href="">Read more &raquo;</a>');
    $(".slider_menu a").click(function() { 
		openSlider();
		return false; 
	});
	
	$('.faqs_list div').hide();
	$('.faqs_list div').append('<a href="" class="close">&uarr; Close</a>');
	$('.faqs_list div:last').addClass('last');
	$('.faqs_list li h2').wrapInner('<a href=""/>')
	
	$('.faqs_list li h2 a').click(function() {
		$(this).parent().parent().children('div').slideDown('fast');
		return false;
	});
	
	$('.faqs_list li div a.close').click(function() {
		$(this).parent().slideUp('fast');
		return false;
	});
	
	//Fees Grid popup
	$(".fees_grid").colorbox({
		innerWidth:"709px", 
		innerHeight:"737px",
		iframe:true,
		scrolling:false
	});
	
	//switch popup
	$(".switch_form").colorbox({
		innerWidth:"660px", 
		innerHeight:"590px",
		iframe:true,
		scrolling:false
	});
	
	//Package Grid popup
	$(".package_grid").colorbox({
		innerWidth:"709px", 
		innerHeight:"849px",
		iframe:true,
		scrolling:false
	});

    
}); 

function openSlider()
{
    var open_height = $(".slider").attr("box_h") + "px";
    $(".slider").animate({"height": open_height}, {duration: "slow" });
    $(".slider_menu").html('<a href="">Close</a>');
    $(".slider_menu a").click(function() { 
		closeSlider();
		return false;
	});
}

function closeSlider()
{
	$(".slider").animate({"height": sliderHeight}, {duration: "slow" });
    $(".slider_menu").html('<a href="">Read more &raquo;</a>');
    $(".slider_menu a").click(function() {
		openSlider();
		return false;
	});
}
