$(function() {
	initSearchBox();
	loginBox();

/******************************
   Terms & conditions expander
 ******************************/

	$('.tc').hide();
	$('.tclink').click(function(){
		if($(this).hasClass('tcL1')){
			if(!($('#tandc1').hasClass('open'))){
				$('.open').slideUp('slow').removeClass('open');
				$('#tandc1').slideDown('slow').addClass('open');
			}
		}
		if($(this).hasClass('tcL2')){
			if(!($('#tandc2').hasClass('open'))){
				$('.open').slideUp('slow').removeClass('open');
				$('#tandc2').slideDown('slow').addClass('open');
			}
		}
	
	});

/*******************************
	Terms & conditions toggle
*******************************/

	$('.tclink').click(function(){
		$('.on').removeClass('on');
		$(this).addClass('on');
	});

/** FAQ
*************************************/

$('.faq dd').hide();
// FAQs
	//$('.faq .back2top').hide();
	$('dt').hover(function(){$(this).addClass('hover')},function(){$(this).removeClass('hover')}).click(function(){
		if($(this).next().hasClass('open')){
			$('.open').slideUp('slow').removeClass('open');
		}
		else{
			$('.open').slideUp('slow').removeClass('open');
			$(this).next().slideToggle('normal').addClass('open');
		}
	});

/******************************
   Set the content of the 
   searchbox
 ******************************/
function initSearchBox() {
	/******************************
      Searchbox Content
     ******************************/
	var searchboxContent = 'Search';
	var searchbox = '#search';
	focusBlurContent (searchboxContent, searchbox);
}

/******************************
  Set content of the login fields
 ******************************/
function loginBox () {
	$('.field-title').remove();
	focusBlurContent('Login email', '#username');
	
	/** Add / Remove Password Background Image
	 ********************************************/
	$('#password').focus(
		function() {
			$('#password').removeClass('password-field');
		}
	);
}

/******************************
   function for showing / hiding
   content of field on focus /
   blur
 ******************************/
function focusBlurContent (content, elementID) {
	
	$(elementID).attr('value', content);
	$(elementID).focus(
		function() {
			if ($(elementID).attr('value') == content) {
				$(elementID).attr('value', '');
			}
		}
	);
	$(elementID).blur(
		function() {
			if ($(elementID).attr('value') == '' || !$(elementID).attr('value')) {
				$(elementID).attr('value', content);
			}
		}
	);		
}

/******************************
   Show a help bubble
 ******************************/

function bubble(i) {
	if ($('.bubble-pos:visible').length) {
		if ($('#' + i + ':visible').length) {
			$('#' + i).hide();
		} else {
			$('#' + i).show();
		}
	} else {
		$('#' + i).show();
	}
}

/******************************
   Price plans code
 ******************************/

$('.tabs-content .priceplan:first-child').addClass('first');
$('.tabs-content-inner .priceplan:first-child').addClass('first');
$('.tabs-content-inner .priceplan:last-child').addClass('last');

$('ul.tabs-inner li .arrow').hide();

if ($('#smtabs').length > 0)
{
	$('#smtabs').tabs();
}

$(".line1").animate({"left": "+=50px"}, "slow");
$(".line2").animate({"left": "+=150px"}, "slow");
$(".line3").animate({ "left": "+=170px" }, "slow");
$(".line4").animate({"left": "+=170px"}, "slow");
$(".line5").animate({"left": "+=216px"}, "slow");

$("h4.rate-details a").click(function(){
		$('h4 a span').html('Click here');
		$(this).toggleClass('active');
		$('h4 a.active span').html('Click here to close');
		$(this).parent().parent('.content-rates').toggleClass('open', 400);
		}
);

$('.content-rates table tr td:last-child').addClass('right-column');
$('.content-rates table tr td::nth-child(2)').addClass('middle-column');

});

/** Launch bill function
*************************************/
var $path;
function launchBill($path) {
	mywindow=open($path,'bill','resizable=no,width=592,height=750,menubar=no,scrollbars=yes,toolbar=no,location=no,left=0,top=0');
	mywindow.location.href = $path;
	if (mywindow.opener == null) mywindow.opener = self;
}
