/*
 *
 * Copyright (c) 2006/2007 Sam Collett (http://www.texotela.co.uk)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 */

(function($){
	var URI = location.href.replace(/#.*/,'');//local url without hash

	var $localScroll = $.localScroll = function( settings ){
		$('body').localScroll( settings );
	};

	//Many of these defaults, belong to jQuery.ScrollTo, check it's demo for an example of each option.
	//@see http://www.freewebs.com/flesler/jQuery.ScrollTo/
	$localScroll.defaults = {//the defaults are public and can be overriden.
		duration:1000, //how long to animate.
		axis:'y',//which of top and left should be modified.
		event:'click',//on which event to react.
		stop:true//avoid queuing animations 
		/*
		lock:false,//ignore events if already animating
		lazy:false,//if true, links can be added later, and will still work.
		target:null, //what to scroll (selector or element). Keep it null if want to scroll the whole window.
		filter:null, //filter some anchors out of the matched elements.
		hash: false//if true, the hash of the selected link, will appear on the address bar.
		*/
	};

	//if the URL contains a hash, it will scroll to the pointed element
	$localScroll.hash = function( settings ){
		settings = $.extend( {}, $localScroll.defaults, settings );
		settings.hash = false;//can't be true
		if( location.hash )
			setTimeout(function(){ scroll( 0, location, settings ); }, 0 );//better wrapped with a setTimeout
	};

	var $scrollTo = $.scrollTo = function( target, duration, settings ){
		$scrollTo.window().scrollTo( target, duration, settings );
	};

	$scrollTo.defaults = {
		axis:'y',
		duration:1
	};

	//returns the element that needs to be animated to scroll the window
	$scrollTo.window = function(){
		return $( $.browser.safari ? 'body' : 'html' );
	};

	$.fn.extend({
		localScroll: function( settings ){
			settings = $.extend( {}, $localScroll.defaults, settings );

			return ( settings.persistent || settings.lazy ) 
					? this.bind( settings.event, function( e ){//use event delegation, more links can be added later.
						var a = $([e.target, e.target.parentNode]).filter(filter)[0];//if a valid link was clicked.
						a && scroll( e, a, settings );//do scroll.
					})
					: this.find('a,area')//bind concretely, to each matching link
							.filter( filter ).bind( settings.event, function(e){
								scroll( e, this, settings );
							}).end()
						.end();

			function filter(){//is this a link that points to an anchor and passes a possible filter ? href is checked to avoid a bug in FF.
				return !!this.href && !!this.hash && this.href.replace(this.hash,'') == URI && (!settings.filter || $(this).is( settings.filter ));
			};
		},
		scrollTo: function( target, duration, settings ){
			if( typeof duration == 'object' ){
				settings = duration;
				duration = 0;
			}
			settings = $.extend( {}, $scrollTo.defaults, settings );
			duration = duration || settings.speed || settings.duration;//speed is still recognized for backwards compatibility
			settings.queue = settings.queue && settings.axis.length > 1;//make sure the settings are given right
			if( settings.queue )
				duration /= 2;//let's keep the overall speed, the same.
			settings.offset = both( settings.offset );
			settings.over = both( settings.over );

			return this.each(function(){
				var elem = this, $elem = $(elem),
					t = target, toff, attr = {},
					win = $elem.is('html,body');
				switch( typeof t ){
					case 'number'://will pass the regex
					case 'string':
						if( /^([+-]=)?\d+(px)?$/.test(t) ){
							t = both( t );
							break;//we are done
						}
						t = $(t,this);// relative selector, no break!
					case 'object':
						if( t.is || t.style )//DOM/jQuery
							toff = (t = $(t)).offset();//get the real position of the target 
				}
				$.each( settings.axis.split(''), function( i, axis ){
					var Pos	= axis == 'x' ? 'Left' : 'Top',
						pos = Pos.toLowerCase(),
						key = 'scroll' + Pos,
						act = elem[key],
						Dim = axis == 'x' ? 'Width' : 'Height',
						dim = Dim.toLowerCase();

					if( toff ){//jQuery/DOM
						attr[key] = toff[pos] + ( win ? 0 : act - $elem.offset()[pos] );

						if( settings.margin ){//if it's a dom element, reduce the margin
							attr[key] -= parseInt(t.css('margin'+Pos)) || 0;
							attr[key] -= parseInt(t.css('border'+Pos+'Width')) || 0;
						}
						
						attr[key] += settings.offset[pos] || 0;//add/deduct the offset
						
						if( settings.over[pos] )//scroll to a fraction of its width/height
							attr[key] += t[dim]() * settings.over[pos];
					}else
						attr[key] = t[pos];//remove the unnecesary 'px'

					if( /^\d+$/.test(attr[key]) )//number or 'number'
						attr[key] = attr[key] <= 0 ? 0 : Math.min( attr[key], max(Dim) );//check the limits

					if( !i && settings.queue ){//queueing each axis is required					
						if( act != attr[key] )//don't waste time animating, if there's no need.
							animate( settings.onAfterFirst );//intermediate animation
						delete attr[key];//don't animate this axis again in the next iteration.
					}
				});			
				animate( settings.onAfter );			

				function animate( callback ){
					$elem.animate( attr, duration, settings.easing, callback && function(){
						callback.call(this, target);
					});
				};
				function max( Dim ){
					var el = win ? $.browser.opera ? document.body : document.documentElement : elem;
					return el['scroll'+Dim] - el['client'+Dim];
				};
			});
		}
    });

	function scroll( e, link, settings ){
		var id = link.hash.slice(1),
			elem = document.getElementById(id) || document.getElementsByName(id)[0];
		if ( elem ){
			e && e.preventDefault();
			var $target = $( settings.target || $.scrollTo.window() );//if none specified, then the window.

			if( settings.lock && $target.is(':animated') ||
			settings.onBefore && settings.onBefore.call(link, e, elem, $target) === false ) return;

			if( settings.stop )
				$target.queue('fx',[]).stop();//remove all its animations
			$target
				.scrollTo( elem, settings )//do scroll
				.trigger('notify.serialScroll',[elem]);//notify serialScroll about this change
			if( settings.hash )
				$target.queue(function(){
					location = link.hash;
					// make sure this function is released
					$(this).dequeue();
				});
		}
	};

	function both( val ){
		return typeof val == 'object' ? val : { top:val, left:val };
	};

})(jQuery);


// cookie script http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days){
	if (days){
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

$(document).ready(function(){
	$('#top').localScroll();
});





/*
 * Facebox (for jQuery)
 * version: 1.2 (05/05/2008)
 * @requires jQuery v1.2 or later
 */
(function($) {
  $.facebox = function(data, klass) {
    $.facebox.loading()

    if (data.ajax) fillFaceboxFromAjax(data.ajax)
    else if (data.image) fillFaceboxFromImage(data.image)
    else if (data.div) fillFaceboxFromHref(data.div)
    else if ($.isFunction(data)) data.call($)
    else $.facebox.reveal(data, klass)
  }

  /*
   * Public, $.facebox methods
   */

  $.extend($.facebox, {
    settings: {
      opacity      : 0,
      overlay      : true,
      loadingImage : '/img/fb_loading.gif',
      closeImage   : '/img/fb_closelabel.gif',
      imageTypes   : [ 'png', 'jpg', 'jpeg', 'gif' ],
      faceboxHtml  : '\
    <div id="facebox" style="display:none;"> \
      <div class="popup"> \
        <table> \
          <tbody> \
            <tr> \
              <td class="tl"/><td class="b"/><td class="tr"/> \
            </tr> \
            <tr> \
              <td class="b"/> \
              <td class="body"> \
                <div class="content"> \
                </div> \
                <div class="footer"> \
                  <a href="#" class="close"> \
                    <img src="/img/fb_closelabel.gif" title="close" class="close_image" /> \
                  </a> \
                </div> \
              </td> \
              <td class="b"/> \
            </tr> \
            <tr> \
              <td class="bl"/><td class="b"/><td class="br"/> \
            </tr> \
          </tbody> \
        </table> \
      </div> \
    </div>'
    },

    loading: function() {
      init()
      if ($('#facebox .loading').length == 1) return true
      showOverlay()

      $('#facebox .content').empty()
      $('#facebox .body').children().hide().end().
        append('<div class="loading"><img src="'+$.facebox.settings.loadingImage+'"/></div>')

      $('#facebox').css({
        top:	getPageScroll()[1] + (getPageHeight() / 10),
        left:	385.5
      }).show()

      $(document).bind('keydown.facebox', function(e) {
        if (e.keyCode == 27) $.facebox.close()
        return true
      })
      $(document).trigger('loading.facebox')
    },

    reveal: function(data, klass) {
      $(document).trigger('beforeReveal.facebox')
      if (klass) $('#facebox .content').addClass(klass)
      $('#facebox .content').append(data)
      $('#facebox .loading').remove()
      $('#facebox .body').children().fadeIn('normal')
      $('#facebox').css('left', $(window).width() / 2 - ($('#facebox table').width() / 2))
      $(document).trigger('reveal.facebox').trigger('afterReveal.facebox')
    },

    close: function() {
      $(document).trigger('close.facebox')
      return false
    }
  })

  /*
   * Public, $.fn methods
   */

  $.fn.facebox = function(settings) {
    init(settings)

    function clickHandler() {
      $.facebox.loading(true)

      // support for rel="facebox.inline_popup" syntax, to add a class
      // also supports deprecated "facebox[.inline_popup]" syntax
      var klass = this.rel.match(/facebox\[?\.(\w+)\]?/)
      if (klass) klass = klass[1]

      fillFaceboxFromHref(this.href, klass)
      return false
    }

    return this.click(clickHandler)
  }

  /*
   * Private methods
   */

  // called one time to setup facebox on this page
  function init(settings) {
    if ($.facebox.settings.inited) return true
    else $.facebox.settings.inited = true

    $(document).trigger('init.facebox')
    makeCompatible()

    var imageTypes = $.facebox.settings.imageTypes.join('|')
    $.facebox.settings.imageTypesRegexp = new RegExp('\.' + imageTypes + '$', 'i')

    if (settings) $.extend($.facebox.settings, settings)
    $('body').append($.facebox.settings.faceboxHtml)

    var preload = [ new Image(), new Image() ]
    preload[0].src = $.facebox.settings.closeImage
    preload[1].src = $.facebox.settings.loadingImage

    $('#facebox').find('.b:first, .bl, .br, .tl, .tr').each(function() {
      preload.push(new Image())
      preload.slice(-1).src = $(this).css('background-image').replace(/url\((.+)\)/, '$1')
    })

    $('#facebox .close').click($.facebox.close)
    $('#facebox .close_image').attr('src', $.facebox.settings.closeImage)
  }
  
  // getPageScroll() by quirksmode.com
  function getPageScroll() {
    var xScroll, yScroll;
    if (self.pageYOffset) {
      yScroll = self.pageYOffset;
      xScroll = self.pageXOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
      yScroll = document.documentElement.scrollTop;
      xScroll = document.documentElement.scrollLeft;
    } else if (document.body) {// all other Explorers
      yScroll = document.body.scrollTop;
      xScroll = document.body.scrollLeft;	
    }
    return new Array(xScroll,yScroll) 
  }

  // Adapted from getPageSize() by quirksmode.com
  function getPageHeight() {
    var windowHeight
    if (self.innerHeight) {	// all except Explorer
      windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
      windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
      windowHeight = document.body.clientHeight;
    }	
    return windowHeight
  }

  // Backwards compatibility
  function makeCompatible() {
    var $s = $.facebox.settings

    $s.loadingImage = $s.loading_image || $s.loadingImage
    $s.closeImage = $s.close_image || $s.closeImage
    $s.imageTypes = $s.image_types || $s.imageTypes
    $s.faceboxHtml = $s.facebox_html || $s.faceboxHtml
  }

  // Figures out what you want to display and displays it
  // formats are:
  //     div: #id
  //   image: blah.extension
  //    ajax: anything else
  function fillFaceboxFromHref(href, klass) {
    // div
    if (href.match(/#/)) {
      var url    = window.location.href.split('#')[0]
      var target = href.replace(url,'')
      $.facebox.reveal($(target).clone().show(), klass)

    // image
    } else if (href.match($.facebox.settings.imageTypesRegexp)) {
      fillFaceboxFromImage(href, klass)
    // ajax
    } else {
      fillFaceboxFromAjax(href, klass)
    }
  }

  function fillFaceboxFromImage(href, klass) {
    var image = new Image()
    image.onload = function() {
      $.facebox.reveal('<div class="image"><img src="' + image.src + '" /></div>', klass)
    }
    image.src = href
  }

  function fillFaceboxFromAjax(href, klass) {
    $.get(href, function(data) { $.facebox.reveal(data, klass) })
  }

  function skipOverlay() {
    return $.facebox.settings.overlay == false || $.facebox.settings.opacity === null 
  }

  function showOverlay() {
    if (skipOverlay()) return

    if ($('facebox_overlay').length == 0) 
      $("body").append('<div id="facebox_overlay" class="facebox_hide"></div>')

    $('#facebox_overlay').hide().addClass("facebox_overlayBG")
      .css('opacity', $.facebox.settings.opacity)
      .click(function() { $(document).trigger('close.facebox') })
      .fadeIn(200)
    return false
  }

  function hideOverlay() {
    if (skipOverlay()) return

    $('#facebox_overlay').fadeOut(200, function(){
      $("#facebox_overlay").removeClass("facebox_overlayBG")
      $("#facebox_overlay").addClass("facebox_hide") 
      $("#facebox_overlay").remove()
    })
    
    return false
  }

  /*
   * Bindings
   */

  $(document).bind('close.facebox', function() {
    $(document).unbind('keydown.facebox')
    $('#facebox').fadeOut(function() {
      $('#facebox .content').removeClass().addClass('content')
      hideOverlay()
      $('#facebox .loading').remove()
    })
  })

})(jQuery);

$(document).ready(function($) {
  $('a[rel*=facebox]').facebox()
})



/**
 * jQuery.LocalScroll
 * Copyright (c) 2007-2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 6/3/2008
 *
 * @projectDescription Animated scrolling navigation, using anchors.
 * http://flesler.blogspot.com/2007/10/jquerylocalscroll-10.html
 */

/**
 * Copyright (c) 2006/2007 Sam Collett (http://www.texotela.co.uk)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 * 
 */

/**
 *  jquery.popupt
 *  (c) 2008 Semooh (http://semooh.jp/)
 *
 *  Dual licensed under the MIT (MIT-LICENSE.txt)
 *  and GPL (GPL-LICENSE.txt) licenses.
 *
 **/
(function($){ var URI = location.href.replace(/#.*/,''); var $localScroll = $.localScroll = function( settings ){ $('body').localScroll( settings );}; $localScroll.defaults = { duration:1000, axis:'y', event:'click', stop:true
}; $localScroll.hash = function( settings ){ settings = $.extend( {}, $localScroll.defaults, settings ); settings.hash = false; if( location.hash )
setTimeout(function(){ scroll( 0, location, settings );}, 0 );}; var $scrollTo = $.scrollTo = function( target, duration, settings ){ $scrollTo.window().scrollTo( target, duration, settings );}; $scrollTo.defaults = { axis:'y', duration:1
}; $scrollTo.window = function(){ return $( $.browser.safari ? 'body' : 'html' );}; $.fn.extend({ localScroll: function( settings ){ settings = $.extend( {}, $localScroll.defaults, settings ); return ( settings.persistent || settings.lazy )
? this.bind( settings.event, function( e ){ var a = $([e.target, e.target.parentNode]).filter(filter)[0]; a && scroll( e, a, settings );})
: this.find('a,area')
.filter( filter ).bind( settings.event, function(e){ scroll( e, this, settings );}).end()
.end(); function filter(){ return !!this.href && !!this.hash && this.href.replace(this.hash,'') == URI && (!settings.filter || $(this).is( settings.filter ));};}, scrollTo: function( target, duration, settings ){ if( typeof duration == 'object' ){ settings = duration; duration = 0;}
settings = $.extend( {}, $scrollTo.defaults, settings ); duration = duration || settings.speed || settings.duration; settings.queue = settings.queue && settings.axis.length > 1; if( settings.queue )
duration /= 2; settings.offset = both( settings.offset ); settings.over = both( settings.over ); return this.each(function(){ var elem = this, $elem = $(elem), t = target, toff, attr = {}, win = $elem.is('html,body'); switch( typeof t ){ case 'number':
case 'string':
if( /^([+-]=)?\d+(px)?$/.test(t) ){ t = both( t ); break;}
t = $(t,this); case 'object':
if( t.is || t.style )
toff = (t = $(t)).offset();}
$.each( settings.axis.split(''), function( i, axis ){ var Pos = axis == 'x' ? 'Left' : 'Top', pos = Pos.toLowerCase(), key = 'scroll' + Pos, act = elem[key], Dim = axis == 'x' ? 'Width' : 'Height', dim = Dim.toLowerCase(); if( toff ){ attr[key] = toff[pos] + ( win ? 0 : act - $elem.offset()[pos] ); if( settings.margin ){ attr[key] -= parseInt(t.css('margin'+Pos)) || 0; attr[key] -= parseInt(t.css('border'+Pos+'Width')) || 0;}
attr[key] += settings.offset[pos] || 0; if( settings.over[pos] )
attr[key] += t[dim]() * settings.over[pos];}else
attr[key] = t[pos]; if( /^\d+$/.test(attr[key]) )
attr[key] = attr[key] <= 0 ? 0 : Math.min( attr[key], max(Dim) ); if( !i && settings.queue ){ if( act != attr[key] )
animate( settings.onAfterFirst ); delete attr[key];}
}); animate( settings.onAfter ); function animate( callback ){ $elem.animate( attr, duration, settings.easing, callback && function(){ callback.call(this, target);});}; function max( Dim ){ var el = win ? $.browser.opera ? document.body : document.documentElement : elem; return el['scroll'+Dim] - el['client'+Dim];};});}, jQIR: function(format, path, onload){ if(!document.images) return this; path = path || ""; this.each( function()
{ var img = $("<img>"), el = jQuery(this); var file; var re = /(?:{src\:)(\S+)(?:})/i; var m = this.className.match(re); if(m)
{ file = path + m[1];}
else
{ file = path + this.id + "." + format;}
jQuery(img).attr( { src: file, alt: el.text()
}).load(typeof onload == "function" ? onload : function(){} ); var a = el.find("a"); var toAppend = a.length ? a.empty().append(img) : img; el.empty().append(toAppend);}
)
return this;}, imghover: function(opt){ return this.each(function() { opt = $.extend({ prefix: '', suffix: '_on', src: '', btnOnly: true, fade: false, fadeSpeed: 200
}, opt || {}); var node = $(this); if(!node.is('img')&&!node.is(':image')){ var sel = 'img,:image'; if (opt.btnOnly) sel = 'a '+sel; node.find(sel).imghover(opt); return;}
var orgImg = node.attr('src'); var hoverImg; if(opt.src){ hoverImg = opt.src;}else{ hoverImg = orgImg; if(opt.prefix){ var pos = hoverImg.lastIndexOf('/'); if(pos>0){ hoverImg = hoverImg.substr(0,pos-1)+opt.prefix+hoverImg.substr(pos-1);}else{ hoverImg = opt.prefix+hoverImg;}
}
if(opt.suffix){ var pos = hoverImg.lastIndexOf('.'); if(pos>0){ hoverImg = hoverImg.substr(0,pos)+opt.suffix+hoverImg.substr(pos);}else{ hoverImg = hoverImg+opt.suffix;}
}
}
if(opt.fade){ var offset = node.offset(); var hover = node.clone(true); hover.attr('src', hoverImg); hover.css({ position: 'absolute', left: offset.left, top: offset.top, zIndex: 1000
}).hide().insertAfter(node); node.mouseover( function(){ var offset=node.offset(); hover.css({left: offset.left, top: offset.top}); hover.fadeIn(opt.fadeSpeed); node.fadeOut(opt.fadeSpeed,function(){node.show()});} ); hover.mouseout( function(){ node.fadeIn(opt.fadeSpeed); hover.fadeOut(opt.fadeSpeed);} );}else{ node.hover( function(){node.attr('src', hoverImg)}, function(){node.attr('src', orgImg)} );}
});}
}); function scroll( e, link, settings ){ var id = link.hash.slice(1), elem = document.getElementById(id) || document.getElementsByName(id)[0]; if ( elem ){ e && e.preventDefault(); var $target = $( settings.target || $.scrollTo.window() ); if( settings.lock && $target.is(':animated') || settings.onBefore && settings.onBefore.call(link, e, elem, $target) === false ) return; if( settings.stop )
$target.queue('fx',[]).stop(); $target
.scrollTo( elem, settings )
.trigger('notify.serialScroll',[elem]); if( settings.hash )
$target.queue(function(){ location = link.hash; $(this).dequeue();});}
}; function both( val ){ return typeof val == 'object' ? val : { top:val, left:val };};})(jQuery); 

$(document).ready(function(){
	$(".nav").jQIR("gif", "images/nav/");
	$(".img").jQIR("gif", "images/");
/*
	$('#top_img').cycle({
		fx:    'fade',
		delay: -1000,
		speed:  400
	});
*/
	$('#content').attr({scrollTop:0,scrollLeft:0});
	$.localScroll.hash({
		target: '#content', //could be a selector or a jQuery object too.
		axis:'xy',//the default is 'y'
		queue:true,
		duration:1500
	});
	$('#season_btn').localScroll({
		target:'.profile',
		axis:'xy',
		queue:true,
		speed:1500
	});
	$('.btn img').imghover();
});

