//All JQuery goodness goes in here

$(document).ready(function() {
  
  //Hide the terms and conditions on page load
	$('#terms-and-conditions').hide();
		
		//For the value text replacement in input boxes
		$('input[type="text"]').focus(function() {
					value=$(this).val();
					if($(this).val()=="Enter your email address...") {
					  $(this).attr("value","");
					}
				});
		$('input[type="text"]').blur(function() {
					if($(this).val()=="") {
						$(this).val(value);
				}
		});
		
		//Page scrolling
		$('a[href*=#]').click(function() {
			if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			  var $target = $(this.hash);
			  $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			  	if ($target.length) {
			  	  if($('#powerpack-menu').length != 0) {
			  	    var targetOffset = $target.offset().top - 70;
			  	  } else {
			  	    var targetOffset = $target.offset().top - 30;
			  	  }
						$('html,body')
						.animate({scrollTop: targetOffset}, 1000);
					   return false;
				  }
			}
	  });
	
	//The Modal Window for the terms and conditions
	//Start the Facebox and unbind the scrolling just for this link
	$('a[rel*=facebox]').unbind();
	$('a[rel*=facebox]').facebox({
		opacity:0.5
	});
	$("a[rel*=gallery1]").facebox({
	  opacity:0.5
	});
	
	//Tabbed Content
	$('#feature-content').css('background','url(/images/image-loader.gif) no-repeat 50% 30%');
	$('#feature-thumbnails li a').unbind();
	$('#feature-content li').css({
	  'padding-top' : '335px'
	})
	$('#feature-content li').hide();
  $('#feature-content li:first-child').show(function(){
    var first_img = new Image();
    $(first_img).fadeIn();
    $(this).prepend(first_img);
    $(first_img).attr({
	    'src': '/images/tabbed-content/applicationlauncher.jpg',
	    'alt': ''
	  });
  });
	$('#feature-thumbnails li:first-child').addClass('active');

  $("#feature-thumbnails li").click(function() {
      
      $('#feature-content img').remove();
  		$("#feature-thumbnails li").removeClass("active"); 
  		$(this).addClass("active"); 
  		$("#feature-content li").hide(); 
      
      var activeTab = $(this).find("a").attr("href"); 
      var imageSrc = $(this).find("img").attr("src").replace("-tab", "");;
  		
  		$(activeTab).fadeIn('fast', function() {
  		  
  		  var img = new Image();
  		  
  		  $(img).fadeIn();
  		  $(activeTab).prepend(img);
  		  $(img).attr({
  		    'src': imageSrc,
  		    'alt': ''
  		  });
  		  
      });
  		
  		return false;
  });
  
  //Make the top men active when on that section
  $("#top-bar-menu ul li a").click(function() {
    $("#top-bar-menu ul li a").removeClass('active');
    $(this).addClass("active"); //Add "active" class to selected tab
  });
  
  //Rotating quotes/content on the homepage
  $('#alfred-quotes ul').cycle({
    next:    '#next',
    prev:    '#prev', 
    fx:     'scrollHorz', 
    timeout: 6000, 
    delay:  -2000
  });
  
});