/**
 * jQuery largePhotoBox plugin
 * This jQuery plugin was inspired and based on lightBox by Leandro Vieira (http://leandrovieira.com/projects/jquery/lightbox/)
 * and the Parallax effect of Danilo (http://www.tidbits.com.br/myparallax-parallax-com-javascript-com-jquery)
 * and modified by me.
 * @name jquery-largephotobox-0.1.0.min.js
 * @author Acaz Souza Pereira - acazsouza@gmail.com
 * @version 0.1.0
 * @date August 07, 2009
 * @category jQuery plugin
 * @copyright (c) 2009 Acaz Souza Pereira (acazsouza@gmail.com)
 * @license CC Attribution-No Derivative Works 2.5 Brazil - http://creativecommons.org/licenses/by-nd/2.5/br/deed.en_US
 * @example Visit http://code.google.com/p/jquery-largephotobox/ for more informations about this jQuery plugin
 */

(function($){$.fn.largePhotoBox=function(settings){settings=jQuery.extend({overlayBgColor:'#000',overlayOpacity:0.8,imageLoading:'http://bus.keifuku.co.jp/images/largephotobox-ico-loading.gif',imageBtnClose:'http://bus.keifuku.co.jp/images/largephotobox-btn-close.png',marginSize:20,keyToClose:'c',imageArray:[],activeImage:0},settings);var arrPageSizes=[];var jQueryMatchedObj=this;function _initialize(){_start(this,jQueryMatchedObj);return false;}
function _start(objClicked,jQueryMatchedObj){$('embed, object, select').css({'visibility':'hidden'});_set_interface();settings.imageArray.length=0;settings.activeImage=0;if(jQueryMatchedObj.length==1){settings.imageArray.push(new Array(objClicked.getAttribute('href')));}else{for(var i=0;i<jQueryMatchedObj.length;i++){settings.imageArray.push(new Array(jQueryMatchedObj[i].getAttribute('href')));}}
while(settings.imageArray[settings.activeImage][0]!=objClicked.getAttribute('href')){settings.activeImage++;}
_set_image_to_view();}
function _set_image_to_view(){$('#largephotobox-image,#largephotobox-btnclose').hide();var objImagePreloader=new Image();objImagePreloader.onload=function(){$('#largephotobox-image').attr('src',settings.imageArray[settings.activeImage][0]);_resize_container_image_box(objImagePreloader.width,objImagePreloader.height);objImagePreloader.onload=function(){};};objImagePreloader.src=settings.imageArray[settings.activeImage][0];};function _resize_container_image_box(intImageWidth,intImageHeight){var margin=(settings.marginSize*2)
var imageMaxWidth=arrPageSizes[2]-margin;var imageMaxHeight=arrPageSizes[3]-margin;var largePhotoBoxContainer=$('#largephotobox-container');var largePhotoBoxContainerImage=$('#largephotobox-container-image');var largePhotoBoxImage=$('#largephotobox-image');if(imageMaxWidth<intImageWidth){$(largePhotoBoxContainer).css({width:imageMaxWidth,marginLeft:-(imageMaxWidth/2)});$(largePhotoBoxContainerImage).width(imageMaxWidth);}
else{$(largePhotoBoxContainer).css({width:intImageWidth,marginLeft:-(intImageWidth/2)});$(largePhotoBoxContainerImage).width(intImageWidth);}
if(imageMaxHeight<intImageHeight){$(largePhotoBoxContainer).css({height:imageMaxHeight,marginTop:-(imageMaxHeight/2)});$(largePhotoBoxContainerImage).height(imageMaxHeight);}
else{$(largePhotoBoxContainer).css({height:intImageHeight,marginTop:-(intImageHeight/2)});$(largePhotoBoxContainerImage).height(intImageHeight);}
$(largePhotoBoxContainerImage).mousemove(function(e){var posX=$(largePhotoBoxContainerImage).offset().left;var posY=$(largePhotoBoxContainerImage).offset().top;var containerX=$(largePhotoBoxContainerImage).width();var containerY=$(largePhotoBoxContainerImage).height();var contentX=$(largePhotoBoxImage).width();var contentY=$(largePhotoBoxImage).height();var differenceX=contentX-containerX;var differenceY=contentY-containerY;var halfX=-parseInt(differenceX/2);var halfy=-parseInt(differenceY/2);porcentageX=parseInt((e.pageX-posX)/containerX*100);porcentagey=parseInt((e.pageY-posY)/containerY*100);leftPosition=parseInt(0-(differenceX/100*porcentageX));topPosition=parseInt(0-(differenceY/100*porcentagey));$(largePhotoBoxImage).css({top:topPosition,left:leftPosition});});_show_image();};function _show_image(){$('#largephotobox-image,#largephotobox-btnclose').fadeIn(function(){_enable_keyboard_navigation();});};function _set_interface(){$('body').append('<div id="jquery-overlay"></div><div id="jquery-largephotobox" style="background:transparent url('+settings.imageLoading+') no-repeat scroll center"><div id="largephotobox-container"><a href="#" id="largephotobox-btnclose" style="display:none"><img src="'+settings.imageBtnClose+'"></a><div id="largephotobox-container-image"><img src="" id="largephotobox-image"></div></div></div>');arrPageSizes=___getPageSize();$('#jquery-overlay').css({backgroundColor:settings.overlayBgColor,opacity:settings.overlayOpacity,width:arrPageSizes[0],height:arrPageSizes[1]}).fadeIn();var largePhotoBox=$('#jquery-largephotobox');$(largePhotoBox).css({width:arrPageSizes[2],height:arrPageSizes[3]});$(largePhotoBox).click(function(){_finish();});$('#largephotobox-btnclose').click(function(){_finish();return false;});$(window).resize(function(){arrPageSizes=___getPageSize();$('#jquery-overlay').css({width:arrPageSizes[0],height:arrPageSizes[1]});$('#jquery-largephotobox').css({width:arrPageSizes[2],height:arrPageSizes[3]});_set_image_to_view();});}
function _finish(){$('#jquery-largephotobox').remove();$('#jquery-overlay').fadeOut(function(){$('#jquery-overlay').remove();});$('embed, object, select').css({'visibility':'visible'});}
function _enable_keyboard_navigation(){$(document).keydown(function(objEvent){_keyboard_action(objEvent);});}
function _keyboard_action(objEvent){if(objEvent==null){keycode=event.keyCode;escapeKey=27;}else{keycode=objEvent.keyCode;escapeKey=objEvent.DOM_VK_ESCAPE;}
key=String.fromCharCode(keycode).toLowerCase();if((key==settings.keyToClose)||(key=='x')||(keycode==escapeKey)){_finish();}}
function ___getPageSize(){var xScroll,yScroll;if(window.innerHeight&&window.scrollMaxY){xScroll=window.innerWidth+window.scrollMaxX;yScroll=window.innerHeight+window.scrollMaxY;}else if(document.body.scrollHeight>document.body.offsetHeight){xScroll=document.body.scrollWidth;yScroll=document.body.scrollHeight;}else{xScroll=document.body.offsetWidth;yScroll=document.body.offsetHeight;}
var windowWidth,windowHeight;if(self.innerHeight){if(document.documentElement.clientWidth){windowWidth=document.documentElement.clientWidth;}else{windowWidth=self.innerWidth;}
windowHeight=self.innerHeight;}else if(document.documentElement&&document.documentElement.clientHeight){windowWidth=document.documentElement.clientWidth;windowHeight=document.documentElement.clientHeight;}else if(document.body){windowWidth=document.body.clientWidth;windowHeight=document.body.clientHeight;}
if(yScroll<windowHeight){pageHeight=windowHeight;}else{pageHeight=yScroll;}
if(xScroll<windowWidth){pageWidth=xScroll;}else{pageWidth=windowWidth;}
arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight);return arrayPageSize;};return this.unbind('click').click(_initialize);};})(jQuery);
