/*		MagicCarpet.js		*/
var alltheboxe, curBox,nextBox,prevBox;
jQuery(document).ready(function($){
			/*		Slider Code by BinaryKitten		*/
			/*		www.BinaryKitten.me.uk 			*/
alltheboxes = $("li.block");

firstBox = alltheboxes.filter(':first');
curBox = alltheboxes.filter(':first');
nextBox = curBox.nextAll('li.block:first');
prevBox = alltheboxes.filter(':last');

alltheboxes.bind('nova.scrollto',function() {
		$(this).trigger('nova.setCurrent');
		$.scrollTo(curBox, 3500, {axis:'x'});
		return false;
	})
	.bind('nova.setCurrent',function() {
		curBox.removeClass('current prev next');
		curBox = $(this);
    		curBox.addClass('current');

		nextBox.removeClass('next');    
		nextBox = curBox.nextAll('li.block:first');
		if (nextBox.length == 0) {
			nextBox = alltheboxes.filter(':first');
	    	}
    
	 	prevBox.removeClass('prev');
    		prevBox = curBox.prevAll('li.block:first');
    		if (prevBox.length == 0) {
        		prevBox =  alltheboxes.filter(':last');
    		}
    
    		nextBox.addClass('next');
    		prevBox.addClass('prev');
	});

$(window).scroll(function(e){
    var scrollLeft = $(window).scrollLeft();
    var leftMostItem = $(alltheboxes[0]);
    alltheboxes.each(function() {
        var p = $(this).position();
        if (p.left > scrollLeft) {
            return false;
        }
        leftMostItem = $(this);
    });    
    leftMostItem.trigger('nova.setCurrent');	
});

$('#NavNext').click(function(){
    nextBox.trigger('nova.scrollto');
});

$('#NavPrev').click(function(){
    prevBox.trigger('nova.scrollto');
});
$('#NavStart').click(function(){
    $.scrollTo(0, 3500, {axis:'x'});
});
$.scrollTo(0, 0, {axis:'x'});
	/*		Check for keystrokes		*/
			function checkKey(e){
     		switch (e.keyCode) {
        case 37:
            prevBox.trigger('nova.scrollto');
			return false;
            break;
        case 39:
            nextBox.trigger('nova.scrollto');
			return false;
            break;
        default:
            }      
}

if ($.browser.mozilla) {
    $(document).keypress (checkKey);
} else {
    $(document).keydown (checkKey);
}

	/*		Sidebar links - Find Their Post		*/
	$('.sidebarlinkLI').find('a.sidelink').click(function(){
		$.scrollTo($("h2:contains('"+$(this).attr('id')+"')"), 3500, {axis:'x'});
		return false;
	});
	
	var DSW = $.cookie('DailyStory_Welcome');
      if (DSW === null) { $.cookie('DailyStory_Welcome', 'firstvisit');
          GB_show();
          return false;
          }
          if (DSW = 'visited') { $.cookie('DailyStory_Welcome', 'visited'); return false; }
});

function StoryGoToLeft() {prevBox.trigger('nova.scrollto');}
function StoryGoToRight() {nextBox.trigger('nova.scrollto');}

$(function(){
$("#NavNext").tipTip({maxWidth: "auto"}); $("#NavPrev").tipTip({maxWidth: "auto"}); $(".sidelink").tipTip({maxWidth: "auto"}); $(".post-edit-link").tipTip({maxWidth: "auto"}); $(".archivelink").tipTip({maxWidth: "auto"}); $("#NavIndex").tipTip({maxWidth: "auto"}); $(".external").tipTip({maxWidth: "auto"}); $(".NavStart").tipTip({maxWidth: "auto"});
});


$('#randombutton').click(function(){
    window.open('http://dailystory.ideaprison.com/?random');
});