/**
 * @author Muhenda Bagenda
 */
// Game Launchers
//External links
jQuery(document).ready(function() {
    jQuery('a.external-link').click( function() {
        window.open(jQuery(this).attr('href'));
    return false;
    });
});

// Popup Window
jQuery(document).ready(function() {
    jQuery('a.popup').click(function(ev){
    window.open( jQuery(this).attr('href'),'','width=750,height=550,scrollbars=1' );
    return false;
  })
});

// Hide terms and conditions
jQuery(function () {
    jQuery('.terms').addClass('close')
  jQuery('.terms .toggle').click(function(e) {
    e.preventDefault();
    var $terms = jQuery(this).parents(".terms"); 
    $terms.children(".content").slideToggle('slow');
    $terms.toggleClass('close').toggleClass('open');
  });
});

// IE6 Button Hover fix
jQuery(function() {
  jQuery(".button").hover(function(){
       jQuery(this).find(".decor").addClass('over');
  }, function() {
       jQuery(this).find(".decor").removeClass('over');
  });
});

// Portfolio launchers
jQuery(function () {
	var $launchers = jQuery(".webphysiology_portfolio ul");
	var $launcherItems = $launchers.find("li");
	
	// Launcher items hover
	$launcherItems.hover(
	    function() {
	      jQuery(this).addClass('hover');
	    },
	    function() {
	      jQuery(this).removeClass('hover');
	    }
	  );
	
	// Wrap the launcher text
	$launcherItems.each(
		function() {
			var $this = jQuery(this)
			var $text = $this.find(".portfolio_title, .portfolio_description, .portfolio_meta");
			$text.wrapAll('<div class="portfolio_text" />');
			$this.find(".Portfolio-Link.thickbox").append('<div class="magnify">&nbsp;</div>')
			var $textContainer = $this.find(".portfolio_text"),
				$imageContainer = $this.find("img"),
				$imageFadeSpeed = 'fast',
				$imageFadeOpacity = 0.2;
				
			jQuery(this).hover(
			    function() {
			      $textContainer.stop(true,true).slideDown('fast')
			      $imageContainer.stop(true,true).fadeTo($imageFadeSpeed, $imageFadeOpacity);
			    },
			    function() {
			      $textContainer.stop(true,true).slideUp('fast');
			      $imageContainer.stop(true,true).fadeTo('fast', 1);
			    }
			  );
		}
	);
	
});
