function Accordian() {
	var togglers = $('.faqAccordion h2');
	var elements = ".details";

	$(elements).each(function(){
		if ($(this).parentsUntil('ul').parent().hasClass('faqAccordion')){
			$(this).hide();	
		}
	});
	
	togglers.click(
	function() {
		if ($(this).parentsUntil('ul').parent().hasClass('faqAccordion')){
			var checkElement = $(this).next();
				if((checkElement.is(elements)) && (checkElement.is(':visible'))) {
				checkElement.slideUp(500);
				return false;
			}
			if((checkElement.is(elements)) && (!checkElement.is(':visible'))) {
				$(elements).each(function(){
					if ($(this).parentsUntil('ul').parent().hasClass('faqAccordion')){
						$(this).slideUp(500);	
					}
				});
				checkElement.slideDown(500);
				return false;
			}
		}
	});
}

$(document).ready(function(){
	
	$('input').customInput();
	Accordian();

	$('#customVideoPlayer').flash({
		src: '/_images/flash/YoutubePlayer.swf',
		width:650,
		height: 400,
		flashvars:	{
			videoID:"yAJn3CD2atU", 
			videoQuality:"hd1080", 
			videoBackgroundColor:"0x666666",
			strokeColor:"0x999999",
			controlColor:"0x333333",
			controlHoverColor:"0xed1c24",
			defaultVol:30
		}
	});

	//Pop-ups
	$(".video #playVideo").colorbox({iframe:true, innerWidth:560, innerHeight:315});
	$("#productLineup li a, ul.thumbnails a, ul.seminars a").colorbox();

	// Forms
	$('.contentForm select').selectmenu();

	//Ticker	
	var ticker = new $.newsTicker($('#keyBrands ul'));

	//Carousels
	var slideCounter = $('#bannerWrap li').size();
	$("#bannerWrap li:not(:first) a").attr("tabIndex", "-1");	
	$("#bannerWrap #banner").carouFredSel({
		width: 950,
		height: 335,
		scroll: {
			pauseOnHover: true,
			duration: 700,
			fx: "fade",
			onBefore: function(oldItems, newItems) {
				oldItems.children('a').attr("tabIndex", "-1");
				newItems.children('a').removeAttr("tabIndex");
			}
		},
		items: {
			width: 950
		},
		pagination: {
			container: "#bannerWrap .controls",
			anchorBuilder: function( nr ) {
				var str  = '<li><a href="#">';
					str += 'Slide'+' '+nr+' '+'of'+' '+ slideCounter;
					str += '</a></li>';
				return str;
			}
		}
	});
	
		
	$("ul.slides").carouFredSel({
		width: 310,
		height: 175,
		direction: "up",
		scroll: 750,
		items: {
			width: 310
		}
	});

	$("ul.quotes").carouFredSel({
		width: 310,
		height: 155,
		items: {
			width: 310
		},
		scroll: {
			fx: "fade"
		}
	});

	$("#productLineup").carouFredSel({
		width: 900,
		height: 110,
		items: {
			visible: 6,
			width: 150,
			height: 110
		},
		scroll: 1,
		prev: "#slideShow .controls .prev",
		next: "#slideShow .controls .next"
	});

	//Twitter
	$("#latestTweet").tweet({
		screen_name: "Pulse_London_",
		count: 1,
		include_rts: true,
		loading_html: "<p id='loadingTweets'>Loading...</p>",
		markup_format: function(o){
			return "<p class='tweet'>"+ o.tweet_text_fancy +"</p><p class='timeStamp'><a href='"+ o.tweet_url +"'>" + o.tweet_relative_time + "</a></p>"	
		}
	});

	//Surgeries
    $("ul.surgeries").hide();

	$("h2.surgeries").click(function (e) {
    	$(this).next('ul.surgeries').slideToggle(500);
		return false;
    });
	
});

