function logThis(logitem) {
	if (window.console) {
		console.log(logitem);
	}
}


$(document).ready(function() {



    //Calendar
    $("#calendar").accordion({ collapsible: true });

//$('.ie input.go').click(function() {
//	$('form#aspNet').submit();
//});

	$('ul.nav li.current').append("<span class='current'></span>");

  	$('ul.nav li:not(li.current)').hover(function() {
  		$(this).append("<span class='hover'></span>");
  	}, function() {
  		$(this).find('span.hover').remove();
  	});
  	$('ul.nav li:not(li.current) a').focus(function(){
		$(this).parent().append("<span class='hover'></span>");
	});
  	$('ul.nav li:not(li.current) a').blur(function(){
  		$(this).parent().find('span.hover').remove();
	});
  	
  	//homepage rollover links
	var over = 0,
	    total = $('p#home-banner-nav a').length,
	    counter = 1,
	    delayed = null,
	    delayTimer = 4000;
		
		

  	$('p#home-banner-nav a').hover(function() {
  		homeHoverDest = $(this).attr('class');
  		$('p.fade:not(p#'+homeHoverDest+')').animate({'opacity':0}, 200);	
  		$('p#'+homeHoverDest).animate({'opacity':1}, 500);
		over = 1;
		counter = 1;
		stopRotation();
  	}, function() {
  		over = 0;
		startRotation();
  	});

	function startRotation() {
		if (delayed) clearInterval(delayed);
		if (over == 0) {
			delayed = setInterval(function(){ goNext(); },delayTimer);	
		}
	}	
	function stopRotation() {
		if (delayed) clearInterval(delayed);
	}
	function goNext() {
		if (counter >= total) {
  			homeHoverDest = $('p#home-banner-nav a').eq(counter -1).attr('class');
  			$('p.fade:not(p#'+homeHoverDest+')').animate({'opacity':0}, 200);	
  			$('p#'+homeHoverDest).animate({'opacity':1}, 500);
			counter = 1;
		} else {
  			homeHoverDest = $('p#home-banner-nav a').eq(counter - 1).attr('class');
  			$('p.fade:not(p#'+homeHoverDest+')').animate({'opacity':0}, 200);	
  			$('p#'+homeHoverDest).animate({'opacity':1}, 500);
			counter++;
		}		
	}
	startRotation();

	
	$('p#home-banner-nav a').focus(function(){
  		homeHoverDest = $(this).attr('class');
  		$('p.fade:not(p#'+homeHoverDest+')').animate({'opacity':0}, 200);	
  		$('p#'+homeHoverDest).animate({'opacity':1}, 500);
	});
	
	
	

	$('input.default-val').each(function(){
		var valText = $(this).attr('title');
		$(this)
			.attr({title: valText})
			.focus(function(){
					if($(this).val() === valText){
							$(this).val('');
					}
			})
			.blur(function(){
					if($(this).val() === ''){
							$(this).val(valText);
					}
			})
			.val(valText);
	});
	
	$('ul#home-flashes li').each(function() {
		
		if ($(this).find("a").length > 0) {
			$(this).css('cursor','pointer');
			$(this).click(function() {
				var goTo = $(this).find("a:first").attr('href');
				window.location = goTo;
			});
			$('a',this).focus(function(){ 
				$(this).parents('li:first').css('background-position','0px -120px'); 
			});
			$('a',this).blur(function(){ 
				$(this).parents('li:first').css('background-position','0px 0px'); 
			});
		};
		
	});

	//accordian 
	$('ul.page-accordian div.acc-content').hide();
	$('ul.page-accordian li > h3').addClass('clickable').click(function() {
		$(this).next('.acc-content').fadeToggle('fast');
	});
	
	if ($('#quit-sidebar div').length > 0 || $('.quiz-results').length > 0) {
		$('p.suggestion').css('visibility','visible');
	}

});


/*tool tips*/
$(document).ready(function(){
$('.fixed[title]').qtip({
	    content: {
     
   },
   style: {
      classes: 'ui-tooltip-orange' 
   },
 position: { target: 'mouse' }
	});

$('.group[title]').qtip({
	    content: {
     
   },
   style: {
      classes: 'ui-tooltip-red' 
   },
 position: { target: 'mouse' }
	});

$('.onetoone[title]').qtip({
	    content: {
     
   },
   style: {
      classes: 'ui-tooltip-blue' 
   },
 position: { target: 'mouse' }
	});



$('.tel[title]').qtip({
	    content: {
     
   },
   style: {
      classes: 'ui-tooltip-green' 
   },
 position: { target: 'mouse' }
	});

});



/*local help*/
function submitAddress(){
		var telephone = $('#telephone').val();
		var day = $('#day').val();
		var month = $('#month').val();
		var year = $('#year').val();
		var httpheader = 'http%3A%2F%2Fcanstopsmoking.storyuk.com%2Ftext-support';
		var url = './address.php';
		var rand = Math.random(9999);
		$.get(url, { telephone: telephone, day: day, month: month, year: year, httpheader: httpheader, rand: rand}, function(data){
			showResponse(data);
		});
		
	}

	function showResponse(response) {
		//alert(response);
		if(response == 0 || response == 1) {
			//$('result').value = response;
			showError();
			
		}else if(response == 22) {
			//$('result').value = response;
			showSuccess();
		}else{
			//$('result').value = response;
			showPostFailure();
		} 
	}
	
	function showError() {
		$('#adiqErrorMessage').css('display','block');
		$('#adiqDefaultMessage').css('display','none');
	}
	
	function showError() {
		$('#adiqErrorMessage').css('display','block');
		$('#adiqDefaultMessage').css('display','none');
		$('#adiqForm').css('display','block');
		focusCursor();
		$('#formLoading').css('display','none');
	}
	
	function showSuccess() {
		$('#adiqSuccessMessage').css('display','block');
		$('#adiqDefaultMessage').css('display','none');
		$('#adiqErrorMessage').css('display','none');
		$('#adiqFormPanel').css('display','none');
		$('#adiqFooter').css('display','none');
		$('#formLoading').css('display','none');
		
	}
	
	function showPostFailure() {
		$('#adiqPostFailureMessage').css('display','block');
		$('#formLoading').css('display','none');
		$('#adiqDefaultMessage').css('display','none');
		$('#adiqErrorMessage').css('display','none');
		$('#adiqFormPanel').css('display','none');
		$('#adiqFooter').css('display','none');
	}
	
	function showLoading(){
		$('#adiqForm').css('display','none');
		$('#formLoading').css('display','block');
	}
	
	function focusCursor() {
		$('#telephone').focus();
	}





