//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' : '390px'
	})
	$('#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
  });
  
  /*
  //The powerpackpage - replacing images with videos
  //Then add the button to display it
  $('.main-feature.video').append('<a href="" title="Play Video" class="play-button"><img src="/images/video-icon.png" alt=""/> Play Video</a>');
  //Now grab the correct item and video and display it on click
  $('.play-button').click(function(){
    var parent_div = "#" + $(this).parent().attr("id");
    var video_id = $(this).parent().attr("id").replace('powerpack-feature-', '');
    var video = '<object width="638" height="399"><param name="wmode" value="transparent" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=' + video_id + '&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=5c1f87&amp;fullscreen=1&amp;autoplay=1&amp;loop=0" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=' + video_id + '&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=5c1f87&amp;fullscreen=1&amp;autoplay=1&amp;loop=0" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="638" height="399" wmode="transparent"></embed></object>';
    $('.main-feature').css({
      'background':'url(/images/image-loader.gif) no-repeat 67% 50%'
    });
    $(parent_div + ' img').hide();
    $(video).append(video).insertAfter($(parent_div + ' img'));
    $(this).hide();
    return false;
  });
  */

});

