// JavaScript Document




var transitionTime = 700;
var clickCounter = 0;
var today = new Date();
var expiry = new Date(today.getTime() + 2 * 60 * 60 * 1000);



function checkKey(e){

     switch (e.keyCode) {

        case 37:

            $('#kevinsfoto').fadeOut(transitionTime);

            setTimeout("self.location.href=prev",transitionTime);

            //self.location.href=prev;

            break;

        case 39:

            $('#kevinsfoto').fadeOut(transitionTime);

            setTimeout("self.location.href=next",transitionTime);

            //self.location.href=next;

            break; 

            }      

}



if ($.browser.mozilla) {

    $(document).keypress (checkKey);

} else {

    $(document).keydown (checkKey);

}



function elementContainsMouse(evt,element){
  var x = evt.pageX;
  var y = evt.pageY;
  
  var xEpos = $(element).offset().left;
  var yEpos = $(element).offset().top;
  
  var width = $(element).width();
  var height = $(element).height();

}


$(document).ready(function()

        {
      //  $('.arrows').blur(function(evt) {
      //    elementContainsMouse(evt,"#right");
      //  });
          
        $("#kevinsfoto").fadeIn(transitionTime);
        
        //setTimeout("$('.arrows').click();",transitionTime);
        
        var isPrev = $.getUrlVar('prev');
        var isNext = $.getUrlVar('next');
        if (isPrev!="true")
          $("#left").animate({opacity : 0.0}, 0);
        else
          $("#left").animate({opacity : 0.2}, 0);
        
        if (isNext!="true")
          $("#right").animate({opacity : 0.0}, 0);
        else
          $("#right").animate({opacity : 0.2}, 0);

        var right = $("#right").offset();
        
      $('.arrows').hover(function(evt)     
        {
    			$(this).clearQueue().stop().animate({opacity:0.7},{queue:false,duration:200}).delay(1500).animate({opacity:0.2},700);
          //$("this").stop().animate({opacity:0.8},200); //.delay(3000).animate({overlay:0.0},200);	
    		}, function() {
    			$(this).clearQueue().stop().animate({opacity:0.0},200);
    		});   
    		
    		
    		$(".arrows").click( function(event) {
          elementContainsMouse(event,"#right");
          $(this).transition();
          //$(".arrows").blur();
        });
       $(".jsIsOff").css("display","none");
       $(".firstLevel").click(function(evt){

            var id = evt.target.id.substring(1);

            $('#li'+id+'> ul').show(500);

            $('li> ul').not('#li'+id+'> ul').hide(500);
            SetCookie('opened', id, expiry);
            /*$('#hide'+id).animate({ 

              opacity: 1,

              margin: "0px"

            }, 500 );

            $('#li'+id+'> ul').show(500);

            var str = GetCookie('opened');

            str += id+";";

            SetCookie('opened', str, expiry);*/

            return false;

          });

        

        $(".hideButton").click(function (evt) {

            var id = evt.target.id.substring(4);

            $('#li'+id+'> ul ').hide(500);
            $('#hide'+id).animate({ 

              opacity: 0,

              margin: "15px"

            }, 500 );

            

            var str = GetCookie('opened');

            var strArr = str.split(";");

            //alert (strArr[0]);  

            str = '';

            for (var i=0; i < strArr.length; i++){

              if (strArr[i] == id)

               strArr[i]= 'x';

            }

            for (var i=0; i < strArr.length; i++){

              if ((strArr[i] != 'x')&&(strArr[i] != ''))

                str += strArr[i]+';';

            }

            SetCookie('opened', str, expiry);           

        });
});

        

$.fn.transition = function(){
  $('#kevinsfoto').fadeOut(transitionTime);
  if ($(this).attr("id")=="right")
    setTimeout("self.location.href=next+'&next=true'",transitionTime);
  else
    setTimeout("self.location.href=prev+'&prev=true'",transitionTime);
}

// cookies.js

// Derived from the Bill Dortch code at http://www.hidaho.com/cookies/cookie.txt

// Thanks Bill ;-)





function getCookieVal (offset) {

  var endstr = document.cookie.indexOf (";", offset);

  if (endstr == -1) { endstr = document.cookie.length; }

  return unescape(document.cookie.substring(offset, endstr));

  }



function GetCookie (name) {

  var arg = name + "=";

  var alen = arg.length;

  var clen = document.cookie.length;

  var i = 0;

  while (i < clen) {

    var j = i + alen;

    if (document.cookie.substring(i, j) == arg) {

      return getCookieVal (j);

      }

    i = document.cookie.indexOf(" ", i) + 1;

    if (i == 0) break; 

    }

  return null;

  }



function DeleteCookie (name,path,domain) {

  if (GetCookie(name)) {

    document.cookie = name + "=" +

    ((path) ? "; path=" + path : "") +

    ((domain) ? "; domain=" + domain : "") +

    "; expires=Thu, 01-Jan-70 00:00:01 GMT";

    }

  }



function SetCookie (name,value,expires,path,domain,secure) {

  document.cookie = name + "=" + escape (value) +

    ((expires) ? "; expires=" + expires.toGMTString() : "") +

    ((path) ? "; path=" + path : "") +

    ((domain) ? "; domain=" + domain : "") +

    ((secure) ? "; secure" : "");

  }
  
  /*
    getUrlVars function from jquery-howto.blogspot.com 
  */

  $.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});

