﻿/* animateImage.js */
/* Copyright (c) 2010-2011 attosoft. Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php */
var Animations={delay:500,repeat:-1,rewind:false,className:'animation',idPrefix:'animateImage',idIndex:1};function generateAnimationId(){var id;do{id=Animations.idPrefix+Animations.idIndex++;}while(document.getElementById(id));return id;}
function Animation(files,id,repeat,rewind){this.id=id;this.index=0;this.images=generateImages(files);this.repeat=this.count=repeat;this.rewind=rewind;}
function generateImages(files){var isArray=files instanceof Array;var startIndex,endIndex,substr;if(isArray){startIndex=0;endIndex=files.length;}else{var result=files.match(/\[(\d+)-(\d+)\]/);substr=result[0];startIndex=result[1];endIndex=parseInt(result[2])+1;}
var images=new Array();for(var i=startIndex;i<endIndex;i++){var image=new Image();image.src=isArray?files[i]:files.replace(substr,padZero(i,startIndex.length));images[images.length]=image;}
return images;}
function padZero(number,digit){var str=''+number;while(str.length<digit){str='0'+str;}
return str;}
function ImageAnimator(files,title,id,delay,repeat,rewind){id=id||generateAnimationId();delay=delay||Animations.delay;repeat=typeof repeat=='number'?repeat:Animations.repeat;rewind=typeof rewind=='boolean'?rewind:Animations.rewind;var anim=new Animation(files,id,repeat,rewind);var imgElem='<img id="'+id+'" src="'+anim.images[0].src+'"';if(typeof title=='string'){imgElem+=' alt="'+title+'" title="'+title+'"';}
if(Animations.className){imgElem+=' class="'+Animations.className+'"';}
imgElem+=' />';document.write(imgElem);this.animate=function(replay){if(anim.repeat==0){return;}else if(replay){this.stopAnimate();anim.index=-1;anim.count=anim.repeat;}else if(anim.intervalID){return;}else if(anim.count==0){anim.count=anim.repeat;}
anim.intervalID=setInterval(function(){_animate(anim);},delay);}
this.stopAnimate=function(){if(!anim.intervalID){return;}
clearInterval(anim.intervalID);delete anim.intervalID;}}
function animateImage(files,title,id,delay,repeat,rewind){var animator=new ImageAnimator(files,title,id,delay,repeat,rewind);animator.animate();return animator;}
function _animate(anim){document.getElementById(anim.id).src=anim.images[++anim.index].src;if(anim.index==anim.images.length-1){anim.index=-1;if(anim.count<0){return;}else{anim.count--;}}
if(anim.count==0&&(!anim.rewind||anim.index==0)){clearInterval(anim.intervalID);delete anim.intervalID;}}
/* fade.js */
$('head').append('<style type="text/css">body{display:block;height:' + $(window).height() + 'px}</style>');function windowFade(){$('#fade').each(function(){$('#fade').fadeOut(2400).height($('body').height());$('a.navi_menu').click(function(){var url = $(this).attr('href');if( this.href.match(location.hostname) && $(this).attr("href").charAt(0) != "#" && !$(this).attr("rel") && !$(this).attr("target") ){var LinkURL = $(this).attr("href");$('#fade').fadeIn(2400,function(){location.href = LinkURL;});return false;}});});};$(window).load(function(){windowFade();});window.onunload = function() {windowFade();};
/* slidemenu.js */
$(document).ready(function(){$('.slidebox').hover(function(){$(".slidebox_menu", this).stop().animate({top:'-55px'},{queue:false,duration:500});}, function() {$(".slidebox_menu", this).stop().animate({top:'0px'},{queue:false,duration:500});});});$(document).ready(function(){$('#social_media').hover(function(){$("#social_media_icons", this).stop().animate({right:'250px'},{queue:false,duration:1200});}, function() {$("#social_media_icons", this).stop().animate({right:'-30px'},{queue:false,duration:1200});});});

/* jStageAligner.js require jQuery 1.2 (c) Hideaki Tanabe <http://blog.kaihatsubu.com> Licensed under the MIT License. */
$(function() {
$("#containeR").jStageAligner("CENTER_MIDDLE", {time: 1600});
});

$(function() {
$(".slidebox slidebox_content").jStageAligner("CENTER", {time: 1600});
});

(function($) {
  $.fn.jStageAligner = function(position, options) {
    var self = this;
    var isIE6 = !jQuery.support.opacity && !jQuery.support.style && (typeof document.documentElement.style.maxHeight === "undefined");
    this.css("position", "absolute");

    if (!options) {
      var options = {};
    }
    options.marginTop    = options.marginTop    || 0;
    options.marginRight  = options.marginRight  || 0;
    options.marginBottom = options.marginBottom || 0;
    options.marginLeft   = options.marginLeft   || 0;
    options.time         = options.time         || 0;
    options.easing       = options.easing       || "linear";
    options.callback     = options.callback     || null;

    var calculatePosition = function() {
      var targetPosition = {left: 0, top: 0};
      //animate
      if (options.time > 0 || isIE6) {
        targetPosition = {left: $(window).scrollLeft(), top: $(window).scrollTop()};
      }
      var stageWidth = $(window).width();
      var stageHeight = $(window).height();
      var marginX = options.marginLeft - options.marginRight;
      var marginY = options.marginTop - options.marginBottom;

      switch (position) {
		case "CENTER_MIDDLE":
          targetPosition.left += Math.floor(stageWidth / 2 - self.width() / 2 + marginX);
          targetPosition.top  += Math.floor(stageHeight / 2 - self.height() / 2 + marginY);
          break;

        case "CENTER_BOTTOM":
          targetPosition.left += Math.floor(stageWidth / 2 - self.width() / 2 + marginX);
          targetPosition.top  += stageHeight - self.height() + marginY;
          break;
		case "CENTER":
          targetPosition.left += Math.floor(stageWidth / 2 - self.width() / 2 + marginX);
		  targetPosition.top   = 0;
          break;

		
      }
        return targetPosition;
    };
    
    //do alignment
    var align = function() {
      var targetPosition = calculatePosition();
      self.clearQueue();
      //animate
      if (options.time > 0) {
        self.animate({ 
          left: targetPosition.left,
          top : targetPosition.top
        }, options.time, options.easing, options.callback);
      //not animate
      } else {
        //is IE 6
        //IE 6 is not support position: fixed
        //but, this code cause little bit blink bug
        if (isIE6) {
          self.css("position", "absolute");
          self.css("left", targetPosition.left);
          self.css("top", targetPosition.top);
          $("body").css({
              "background-image": "url(null)",
              "background-attachment": "fixed"
          });
        } else {
          self.css("position", "fixed");
          self.css("left", targetPosition.left);
          self.css("top", targetPosition.top);
        }
        if (options.callback) {
          options.callback.call();
        }
    }
    };

    //resize handler
    $(window).resize(function() {
      align();
    });

    $(window).scroll(function() {
      align();
    });

    //initialize
    var targetPosition = calculatePosition();
    this.css("left", targetPosition.left);
    this.css("top", targetPosition.top);

    return this;
  };
})(jQuery);
