$(document).ready(function() {
	smoothScroll();
	issueLinks();
	newsLink();
	myAjax();
	webkitImage();
});

function smoothScroll() {

  // Scroll slowly
  $('a[href*=#]').click(function() {

    // duration in ms
    var duration=1000;

    // easing values: swing | linear
    var easing='swing';

    // get / set parameters
    var newHash=this.hash;
    var target=$(this.hash+', a[name='+this.hash.slice(1)+']').offset().top;
    var oldLocation=window.location.href.replace(window.location.hash, '');
    var newLocation=this;

    // make sure it's the same location
    if(oldLocation+newHash==newLocation)
    {
       // set selector
       if($.browser.safari) var animationSelector='body:not(:animated)';
       else var animationSelector='html:not(:animated)';

       // animate to target and set the hash to the window.location after the animation
       $(animationSelector).animate({ scrollTop: target }, duration, easing, function() {

          // add new hash to the browser location
          window.location.href=newLocation;
       });

       // cancel default click action
       return false;
    }

  });
  
}

function issueLinks() {
	var liOdd = $("#issue nav ul li:odd");
	var liEven = $("#issue nav ul li:even");
	
	liOdd.find('a').click(function(){
		$('body').find('#background').addClass('purple');
		return false;
	});
	
		
	liEven.find('a').click(function(){
		$('body').find('#background').removeClass('purple');
		return false;
	});		
	
	
	//$('.issue_contents article:last-child .issue_content').show();
}

function newsLink() {
	$('#news h1 a').click(function(){
		$('#current_news').slideToggle('1000');
		$('#old_news').hide('1000');
		return false;
	});
	
	$('#news h2 a').click(function(){
		$('#old_news').slideToggle('1000');
		$('#current_news').hide('1000');
		return false;
	});
}

// Ajax load in index solution
function myAjax(){
	var siteUrl = "http://" + top.location.host.toString();
	var intLink = $("a[href^=" + "'" + siteUrl + "'" + "]");
	var mainContent = $("#maincontent");
	
	intLink.click(function(){
		
		var fire = $(this);
		URL = fire.attr("href");
		URL = URL + "#issue_content";
		
		mainContent.load(URL);
		
	});
}



