$(document).ready(function(){

$("#thislogo").load(function() {
$('#splash .logo').hide().fadeIn(2000);
$('.splashfooter').hide().fadeIn(2000);
});
$("#splash").delay(5000).fadeOut(2000);

var currentPosition = 0;
var naviPosition = 0;
var slideWidth = 626;
var numberOfSlides = $(".slide").length;
var easing = 'easeOutCirc';
var positionIs;
var lastHash = '';
var newLocation = '0';


function pollHash() {
    if(lastHash !== location.hash) {
        lastHash = location.hash;
        // hash has changed, so do stuff:
var hash_value = window.location.hash.replace('#', '');
if (hash_value != "fs") {
var getvalue = $('.'+hash_value).attr('rel');
if(getvalue) {
currentPosition = getvalue;
$('.current').removeClass('current');
$("#slidestrip").animate({"margin-left": (-626*getvalue)}, {duration: 400, easing: easing});
arrowLocation(getvalue);
$('[rel="' +getvalue+'"]').addClass("current");
makeVisible ();
}
}
}
}

setInterval(pollHash, 100);

$(document).keydown(function(e) {
  if(e.keyCode == 37) { // left
previousSlidestrip ();
  }
  else if(e.keyCode == 39) { // right
nextSlidestrip();
  }
 else if(e.keyCode == 27) { // right
$(".overlay").animate({"opacity":"0"}, 0, "linear");
$(".overlay").css({"z-index":"-1"});
  }

if(e.keyCode == 13) { // return
var getvalue = $('.current a').attr('href');
if (getvalue != undefined) {
window.location = getvalue;
}
}

});


if(window.location.hash == "#fs") {
$(".overlay").animate({"opacity":"1"}, 0, "linear");
$(".overlay").css({"z-index":"50"});
$('#slideshow').css({visibility: "visible"});
}

$('[rel="' + currentPosition + '"]').addClass("current");

makeVisible ();


$(".control.next").click(function(){
nextSlidestrip();
});

$(".control.previous").click(function(){
previousSlidestrip();
});

$(".fsnext").click(function(){
var getvalue = $('#slideshow > .current').attr('rel');
nextSlidestrip();
});

$(".fsleft").click(function(){

var getvalue = $('#slideshow > .current').attr('rel');
previousSlidestrip()
});

$('.navislide').click(function() {
var getvalue = $(this).attr('rel');
$("#slidestrip").animate({"margin-left": (-slideWidth*getvalue)});
$('.current').removeClass('current');
$('.previous').css({visibility: "hidden"});
$('.next').css({visibility: "hidden"});
$('.project-title').css({visibility: "hidden"});
$('[rel="' + getvalue + '"]').addClass("current");
currentPosition = parseInt(getvalue);
moveOverlay(getvalue);
arrowLocation(getvalue);

makeVisible ();

});



$(".navi-next").click(function(){
var percentNavi = 0;

percentNavi = numberOfSlides / 10;

if (percentNavi > 1 && naviPosition == 0) {
$('.arrow').css({visibility: "hidden"});

$("#navistrip").animate({"margin-left": "-=260px"});
naviPosition = 1;
} else if (percentNavi > 2 && naviPosition == 1) {
$('.arrow').css({visibility: "hidden"});

$("#navistrip").animate({"margin-left": "-=260px"});
naviPosition = 2;
console.log(naviPosition);
} else {

}

});

$(".navi-previous").click(function(){
console.log("yes");
percentNavi = numberOfSlides / 10;

if (percentNavi > 2 && naviPosition == 2) {
$('.arrow').css({visibility: "hidden"});

$("#navistrip").animate({"margin-left": "+=260px"});
naviPosition = 1;
console.log(naviPosition);

} else if (percentNavi > 1 && naviPosition == 1) {
$('.arrow').css({visibility: "hidden"});

$("#navistrip").animate({"margin-left": "+=260px"});
naviPosition = 0;
console.log(naviPosition);
}

});

jQuery.extend( jQuery.easing,
{
		easeOutCirc: function (x, t, b, c, d) {
		return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
	}
});

$(".options-fullscreen").click(function(){
$(".overlay").animate({"opacity":"1"}, 0, "linear");
$(".overlay").css({"z-index":"50"});
$('#slideshow').css({visibility: "visible"});
});

$(".options-remove").click(function(){
$(".overlay").animate({"opacity":"0"}, 0, "linear");
$(".overlay").css({"z-index":"-1"});
});

function moveSlider(positionIs) {
$("#slidestrip").animate({"margin-left": (-626*positionIs)}, {duration: 400, easing: easing});
}

function moveOverlay(overlayPosition) {
$('#slideshow img').removeClass('active');
$('#slideshow img [rel="' + overlayPosition + '"]').addClass("active");
}

function slideSwitch() {

var getvalue = $(this).attr('rel');

    var $active = $('.current');

    if ( $active.length == 0 ) $active = $('.current:last');

    var $next =  $active.next().length ? $active.next()
        : $('.current:first');

    $active.addClass('last-active');

    $next.css({opacity: 0.0})
        .addClass('current')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('current last-active');
        });

}

function reverseslideSwitch() {

var getvalue = $(this).attr('rel');

    var $active = $('.current');

    if ( $active.length == 0 ) $active = $('.current:last');

    var $previous =  $active.prev().length ? $active.prev()
        : $('.current:first');

    $active.addClass('last-active');

    $previous.css({opacity: 0.0})
        .addClass('current')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('current last-active');
        });

}
function arrowLocation(thisLocation){
$('.arrow').css({visibility: "visible"});

if ((thisLocation > 9) && (thisLocation < 20)) {
newLocation = thisLocation - 10;
$("#navistrip").animate({"margin-left": "-260px"});
} 
else if (thisLocation > 19) {
newLocation = thisLocation - 20;
$("#navistrip").animate({"margin-left": "-520px"});
} 

else {
newLocation = thisLocation;
$("#navistrip").animate({"margin-left": "0"});
}

if (newLocation == 0)
$(".arrow").animate({"margin-left": "20px"}, {duration: 200, easing: easing});

if (newLocation == 1)
$(".arrow").animate({"margin-left": "46px"}, {duration: 200, easing: easing});

if (newLocation == 2)
$(".arrow").animate({"margin-left": "71px"}, {duration: 200, easing: easing});

if (newLocation == 3)
$(".arrow").animate({"margin-left": "97px"}, {duration: 200, easing: easing});

if (newLocation == 4)
$(".arrow").animate({"margin-left": "124px"}, {duration: 200, easing: easing});

if (newLocation == 5)
$(".arrow").animate({"margin-left": "150px"}, {duration: 200, easing: easing});

if (newLocation == 6)
$(".arrow").animate({"margin-left": "176px"}, {duration: 200, easing: easing});

if (newLocation == 7)
$(".arrow").animate({"margin-left": "202px"}, {duration: 200, easing: easing});

if (newLocation == 8)
$(".arrow").animate({"margin-left": "228px"}, {duration: 200, easing: easing});

if (newLocation == 9)
$(".arrow").animate({"margin-left": "254px"}, {duration: 200, easing: easing});

currentPosition = thisLocation;

}



function nextSlidestrip() {

var thisLocation = '0';


var getvalue = $('.current').attr('rel');

$('.current').removeClass('current');

$('.previous').css({visibility: "hidden"});
$('.next').css({visibility: "hidden"});
$('.project-title').css({visibility: "hidden"});

if (numberOfSlides-1 == getvalue) {

arrowLocation("0");

$("#slidestrip").animate({"margin-left": "0"}, {duration: 400, easing: easing});

$('[rel="' + thisLocation + '"]').addClass("current");

} else {

arrowLocation(getvalue);

thisLocation = 1+parseInt(getvalue);

$("#slidestrip").animate({"margin-left": "-=626px"}, {duration: 400, easing: easing});

arrowLocation(thisLocation);

$('[rel="' + thisLocation + '"]').addClass("current");

}

makeVisible ();

}

function previousSlidestrip () {

var thisLocation = '0';

var getvalue = $('.current').attr('rel');

$('.current').removeClass('current');

$('.previous').css({visibility: "hidden"});
$('.next').css({visibility: "hidden"});
$('.project-title').css({visibility: "hidden"});

if (getvalue == 0) {

thisLocation = numberOfSlides-1;

arrowLocation(numberOfSlides-1);

$("#slidestrip").animate({"margin-left": (-626*(numberOfSlides-1))}, {duration: 400, easing: easing});

$('[rel="' + thisLocation + '"]').addClass("current");

} else {

arrowLocation(getvalue);

thisLocation = parseInt(getvalue)-1;

$("#slidestrip").animate({"margin-left": "+=626px"}, {duration: 400, easing: easing});

arrowLocation(thisLocation);

$('[rel="' + thisLocation + '"]').addClass("current");

}

makeVisible ();


}
function makeVisible () {
$('.current .previous').css({opacity: 0.0, visibility: "visible"}).animate({opacity: 1.0},1000);
$('.current .next').css({opacity: 0.0, visibility: "visible"}).animate({opacity: 1.0},1000);
$('.current .project-title').css({opacity: 0.0, visibility: "visible"}).animate({opacity: 1.0},1000);
}
function addthis_click() 
{ 
var aturl ='http://www.addthis.com/bookmark.php'; 
aturl+='?v=10'; 
aturl+='&pub='+'ra-4e723e2908340888'; 
aturl+='&url='+encodeURIComponent(location.href); 
aturl+='&title='+encodeURIComponent(document.title); 
window.open(aturl,'addthis','scrollbars=yes,menubar=no,width=620,height=620,resizable=yes,toolbar=no,location=no,status=no,screenX=200,screenY=100,left=200,top=100');
return false; 
}

$("#slidestrip").touchwipe({
     wipeLeft: function() { nextSlidestrip(); },
     wipeRight: function() { previousSlidestrip(); },
     min_move_x: 20,
     min_move_y: 20,
     preventDefaultEvents: true
});



});

