//Fix for slideUp and slideDown
function slideToggle(el, bShow){
	var $el = $(el), height = $el.data("originalHeight"), visible = $el.is(":visible");
	
	// if the bShow isn't present, get the current visibility and reverse it
	if( arguments.length == 1 ) bShow = !visible;
	
	// if the current visiblilty is the same as the requested state, cancel
	if( bShow == visible ) return false;
	
	// get the original height
	if( !height ){
	  // get original height
	  height = $el.show().height();
	  // update the height
	  $el.data("originalHeight", height);
	  // if the element was hidden, hide it again
	  if( !visible ) $el.hide().css({height: 0});
	}
	
	// expand the knowledge (instead of slideDown/Up, use custom animation which applies fix)
	if( bShow ){
	  $el.show().animate({height: height}, {duration: 250});
	} else {
	  $el.animate({height: 0}, {duration: 250, complete:function (){
		faq_question.css('border-bottom','1px solid #CCC') //can't just do 'border-bottom','' because IE doens't work
		  $el.hide();
		}
	  });
	}
}

$(document).ready(function(){ //document.ready
	
//Right Column Change
$('.buy_change .button').click(function () {
	$('.first').fadeOut(500, function(){
		$('.second').fadeIn(500);
	});
});


//Tab Change
$('#tabs .tab-12345, #tabs .tab-123, #tabs .tab-1, #tabs .tab-2, #tabs .tab-12, #tabs .tab-345').click(function () {
	var tab = '.' + $(this).attr('class');
	$('#tabs .tab-active').removeClass('tab-active');
	$(this).addClass('tab-active');
	$('#tab-container .tab-active').fadeOut(500, function(){
		$(this).removeClass('tab-active')
		$('#tab-container ' + tab).fadeIn(500, function(){
			$(this).addClass('tab-active')
		});
	});
});

//Background Image Rollovers
$('.where-we-stand, .why-fluenz, .users, .video-tour, .explanations, #sample-session .launch').hover(
	function(over){
		$(this).css('background-position','bottom');
	},
	function(out){
		$(this).css('background-position','');
	}
);



//Languages Menu Mouseover -- NOT CURRENTLY BEING USED. BIG PROBLEMS IN IE
$('#menu .languages .dropdown').hover(
	function(over){
		if($(this).height() == 0) {
			$(this).animate({height:'145px'}, 400);
		}
		$('#menu .languages img').css('visibility','hidden');
		$('#menu .languages div img').css('visibility','');
	},
	function(out){
		$(this).animate({height:''}, 400);
		$('#menu .languages img').css('visibility','');
	}
);

//Order Buttons
$('.view-products, .order-now').hover(function(){
	$(this).css('background-position-y','29px')
},function(){
	$(this).css('background-position-y','')
})

//Sample Session -Back to fluenz.com rollover
$('.back > a').hover(function(){
	$('.arrow').css('background-position-y','-7px')
},function(){
	$('.arrow').css('background-position-y','')
})

//Make Fluenz.org link in footer red -- basically a hack so that I don't have to edit every file :)
org_footer_link = $('#footer a[href=http://www.fluenz.org]')
org_footer_link.css('color','#F00')
org_footer_link.hover(
	function(){
		$(this).css('color','#999')
	},function(){
		$(this).css('color','#F00')
	}
)

//FAQ slide
$('#faq .faq-answer-button').click(function(){
	if($(this).hasClass('faq-closed')){
		$(this).removeClass('faq-closed').addClass('faq-open')
		faq_question = $(this).parent()
		faq_answer = faq_question.next()
		faq_question.css('border-bottom','none')
		slideToggle(faq_answer)
	}else{
		$(this).removeClass('faq-open').addClass('faq-closed')
		faq_question = $(this).parent()
		faq_answer = faq_question.next()
		
		slideToggle(faq_answer)
		
	}
	
})
//What you learn slide
$('#what-you-learn .faq-answer-button').click(function(){
	if($(this).hasClass('faq-closed')){
		$(this).removeClass('faq-closed').addClass('faq-open')
		$(this).css('background-position','0px 35px')
		faq_question = $(this).parent()
		faq_answer = faq_question.next()
		faq_question.css('border-bottom','none')
		slideToggle(faq_answer)
	}else{
		$(this).removeClass('faq-open').addClass('faq-closed')
		$(this).css('background-position','0px 0px')
		faq_question = $(this).parent()
		faq_answer = faq_question.next()
		slideToggle(faq_answer)
	}
});

//Click chat link in header
$('#header .top-links .chat').click(function(){
	$('#scLCct a').eq(0).click();
})

//Holiday Promotion show second #right .divider
$('#right .divider').eq(1).css('display','block')


//our-Story changes


$('.oport_sup_lnk').click(function(){
	$('#work_with_us').fadeOut(300, function(){
			$('#op_support').fadeIn(300);
	})
});

}) //document.ready


