/*
 * JustinaBox -jQuery plugin
 * Version: 1.2.1 (13/03/2009)
 * based on FancyBox Copyright (c) 2009 Janis Skarnelis
 * Licensed under the MIT License: http://en.wikipedia.org/wiki/MIT_License
 * Requires: jQuery v1.3+
*/
;(function($){$.fn.fixPNG=function(){return this.each(function(){var image=$(this).css('backgroundImage');if(image.match(/^url\(["']?(.*\.png)["']?\)$/i)){image=RegExp.$1;$(this).css({'backgroundImage':'none','filter':"progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod="+($(this).css('backgroundRepeat')=='no-repeat'?'crop':'scale')+", src='"+image+"')"}).each(function(){var position=$(this).css('position');if(position!='absolute'&&position!='relative')$(this).css('position','relative')})}})};var elem,opts,busy=false,imagePreloader=new Image,loadingTimer,loadingFrame=1,imageRegExp=/\.(jpg|gif|png|bmp|jpeg)(.*)?$/i;var isIE=($.browser.msie&&(parseInt($.browser.version.substr(0,1))<8||document.compatMode=='BackCompat'));$.fn.justinabox=function(settings){settings=$.extend({},$.fn.justinabox.defaults,settings);var matchedGroup=this;function _initialize(){elem=this;opts=settings;_start();return false};function _start(){if(busy)return;if($.isFunction(opts.callbackOnStart)){opts.callbackOnStart()}opts.itemArray=[];opts.itemCurrent=0;if(settings.itemArray.length>0){opts.itemArray=settings.itemArray}else{var item={};if(!elem.rel||elem.rel==''){var item={href:elem.href,title:elem.title};if($(elem).children("img:first").length){item.orig=$(elem).children("img:first")}opts.itemArray.push(item)}else{var subGroup=$(matchedGroup).filter("a[rel="+elem.rel+"]");var item={};for(var i=0;i<subGroup.length;i++){item={href:subGroup[i].href,title:subGroup[i].title};if($(subGroup[i]).children("img:first").length){item.orig=$(subGroup[i]).children("img:first")}opts.itemArray.push(item)}while(opts.itemArray[opts.itemCurrent].href!=elem.href){opts.itemCurrent++}}}if(opts.overlayShow){if(isIE){$('embed, object, select').css('visibility','hidden')}$("#justinabox_overlay").css('opacity',opts.overlayOpacity).show()}_change_item()};function _change_item(){$("#justinabox_right, #justinabox_left, #justinabox_close, #justinabox_title").hide();var href=opts.itemArray[opts.itemCurrent].href;if(href.match(/#/)){var target=window.location.href.split('#')[0];target=href.replace(target,'');target=target.substr(target.indexOf('#'));_set_content('<div id="justinabox_div">'+$(target).html()+'</div>',opts.frameWidth,opts.frameHeight)}else if(href.match(imageRegExp)){imagePreloader=new Image;imagePreloader.src=href;if(imagePreloader.complete){_proceed_image()}else{$.fn.justinabox.showLoading();$(imagePreloader).unbind().bind('load',function(){$(".justinabox_loading").hide();_proceed_image()})}}else if(href.match("iframe")||elem.className.indexOf("iframe")>=0){_set_content('<iframe id="justinabox_frame" onload="$.fn.justinabox.showIframe()" name="justinabox_iframe'+Math.round(Math.random()*1000)+'" frameborder="0" hspace="0" src="'+href+'"></iframe>',opts.frameWidth,opts.frameHeight)}else{$.get(href,function(data){_set_content('<div id="justinabox_ajax">'+data+'</div>',opts.frameWidth,opts.frameHeight)})}};function _proceed_image(){if(opts.imageScale){var w=$.fn.justinabox.getViewport();var r=Math.min(Math.min(w[0]-36,imagePreloader.width)/imagePreloader.width,Math.min(w[1]-60,imagePreloader.height)/imagePreloader.height);var width=Math.round(r*imagePreloader.width);var height=Math.round(r*imagePreloader.height)}else{var width=imagePreloader.width;var height=imagePreloader.height}_set_content('<img alt="" id="justinabox_img" src="'+imagePreloader.src+'" />',width,height)};function _preload_neighbor_images(){if((opts.itemArray.length-1)>opts.itemCurrent){var href=opts.itemArray[opts.itemCurrent+1].href;if(href.match(imageRegExp)){objNext=new Image();objNext.src=href}}if(opts.itemCurrent>0){var href=opts.itemArray[opts.itemCurrent-1].href;if(href.match(imageRegExp)){objNext=new Image();objNext.src=href}}};function _set_content(value,width,height){busy=true;var pad=opts.padding;if(isIE){$("#justinabox_content")[0].style.removeExpression("height");$("#justinabox_content")[0].style.removeExpression("width")}if(pad>0){width+=pad*2;height+=pad*2;$("#justinabox_content").css({'top':pad+'px','right':pad+'px','bottom':(pad+4)+'px','left':pad+'px','width':'auto','height':'auto'});if(isIE){}}else{$("#justinabox_content").css({'top':0,'right':0,'bottom':0,'left':0,'width':'100%','height':'100%'})}if($("#justinabox_outer").is(":visible")&&width==$("#justinabox_outer").width()&&height==$("#justinabox_outer").height()){$("#justinabox_content").fadeOut("fast",function(){$("#justinabox_content").empty().append($(value)).fadeIn("normal",function(){_finish()})});return}var w=$.fn.justinabox.getViewport();var itemLeft=(width+36)>w[0]?w[2]:(w[2]+Math.round((w[0]-width-36)/2));var itemTop=(height-36)>w[1]?w[3]:(w[3]+Math.round((w[1]-height-41)/2));var itemOpts={'left':itemLeft,'top':itemTop,'width':width+'px','height':height+'px'};if($("#justinabox_outer").is(":visible")){$("#justinabox_content").fadeOut("normal",function(){$("#justinabox_content").empty();$("#justinabox_outer").animate(itemOpts,opts.zoomSpeedChange,opts.easingChange,function(){$("#justinabox_content").append($(value)).fadeIn("normal",function(){_finish()})})})}else{if(opts.zoomSpeedIn>0&&opts.itemArray[opts.itemCurrent].orig!==undefined){$("#justinabox_content").empty().append($(value));var orig_item=opts.itemArray[opts.itemCurrent].orig;var orig_pos=$.fn.justinabox.getPosition(orig_item);$("#justinabox_outer").css({'left':(orig_pos.left-18)+'px','top':(orig_pos.top-18)+'px','width':$(orig_item).width(),'height':$(orig_item).height()});if(opts.zoomOpacity){itemOpts.opacity='show'}$("#justinabox_outer").animate(itemOpts,opts.zoomSpeedIn,opts.easingIn,function(){_finish()})}else{$("#justinabox_content").hide().empty().append($(value)).show();$("#justinabox_outer").css(itemOpts).fadeIn("normal",function(){_finish()})}}};function _set_navigation(){if(opts.itemCurrent!=0){$("#justinabox_left, #justinabox_left_ico").unbind().bind("click",function(e){e.stopPropagation();opts.itemCurrent--;_change_item();return false});$("#justinabox_left").show()}if(opts.itemCurrent!=(opts.itemArray.length-1)){$("#justinabox_right, #justinabox_right_ico").unbind().bind("click",function(e){e.stopPropagation();opts.itemCurrent++;_change_item();return false});$("#justinabox_right").show()}};function _finish(){_set_navigation();_preload_neighbor_images();$(document).keydown(function(e){if(e.keyCode==27){$.fn.justinabox.close();$(document).unbind("keydown")}else if(e.keyCode==37&&opts.itemCurrent!=0){opts.itemCurrent--;_change_item();$(document).unbind("keydown")}else if(e.keyCode==39&&opts.itemCurrent!=(opts.itemArray.length-1)){opts.itemCurrent++;_change_item();$(document).unbind("keydown")}});if(opts.centerOnScroll){$(window).bind("resize scroll",$.fn.justinabox.scrollBox)}else{$("div#justinabox_outer").css("position","absolute")}if(opts.hideOnContentClick){$("#justinabox_wrap").click($.fn.justinabox.close)}$("#justinabox_overlay, #justinabox_close").bind("click",$.fn.justinabox.close);$("#justinabox_close").show();if(opts.itemArray[opts.itemCurrent].title!==undefined&&opts.itemArray[opts.itemCurrent].title.length>0){$('#justinabox_title div').html(opts.itemArray[opts.itemCurrent].title);$('#justinabox_title').show()}if(opts.overlayShow&&isIE){$('embed, object, select',$('#justinabox_content')).css('visibility','visible')}if($.isFunction(opts.callbackOnShow)){opts.callbackOnShow()}busy=false};return this.unbind('click').click(_initialize)};$.fn.justinabox.scrollBox=function(){var pos=$.fn.justinabox.getViewport();$("#justinabox_outer").css('left',(($("#justinabox_outer").width()+36)>pos[0]?pos[2]:pos[2]+Math.round((pos[0]-$("#justinabox_outer").width()-36)/2)));$("#justinabox_outer").css('top',(($("#justinabox_outer").height()+0)>pos[1]?pos[3]:pos[3]+Math.round((pos[1]-$("#justinabox_outer").height()-41)/2)))};$.fn.justinabox.getNumeric=function(el,prop){return parseInt($.curCSS(el.jquery?el[0]:el,prop,true))||0};$.fn.justinabox.getPosition=function(el){var pos=el.offset();pos.top+=$.fn.justinabox.getNumeric(el,'paddingTop');pos.top+=$.fn.justinabox.getNumeric(el,'borderTopWidth');pos.left+=$.fn.justinabox.getNumeric(el,'paddingLeft');pos.left+=$.fn.justinabox.getNumeric(el,'borderLeftWidth');return pos};$.fn.justinabox.showIframe=function(){$(".justinabox_loading").hide();$("#justinabox_frame").show()};$.fn.justinabox.getViewport=function(){return[$(window).width(),$(window).height(),$(document).scrollLeft(),$(document).scrollTop()]};$.fn.justinabox.animateLoading=function(){if(!$("#justinabox_loading").is(':visible')){clearInterval(loadingTimer);return}$("#justinabox_loading > div").css('top',(loadingFrame*-40)+'px');loadingFrame=(loadingFrame+1)%16};$.fn.justinabox.showLoading=function(){clearInterval(loadingTimer);var pos=$.fn.justinabox.getViewport();$("#justinabox_loading").css({'left':((pos[0]-40)/2+pos[2]),'top':((pos[1]-40)/2+pos[3])}).show();$("#justinabox_loading").bind('click',$.fn.justinabox.close);loadingTimer=setInterval($.fn.justinabox.animateLoading,66)};$.fn.justinabox.close=function(){busy=true;$(imagePreloader).unbind();$("#justinabox_overlay, #justinabox_close").unbind();if(opts.hideOnContentClick){$("#justinabox_wrap").unbind()}$("#justinabox_close, .justinabox_loading, #justinabox_left, #justinabox_right, #justinabox_title").hide();if(opts.centerOnScroll){$(window).unbind("resize scroll")}__cleanup=function(){$("#justinabox_overlay, #justinabox_outer").hide();if(opts.centerOnScroll){$(window).unbind("resize scroll")}if(isIE){$('embed, object, select').css('visibility','visible')}if($.isFunction(opts.callbackOnClose)){opts.callbackOnClose()}busy=false};if($("#justinabox_outer").is(":visible")!==false){if(opts.zoomSpeedOut>0&&opts.itemArray[opts.itemCurrent].orig!==undefined){var orig_item=opts.itemArray[opts.itemCurrent].orig;var orig_pos=$.fn.justinabox.getPosition(orig_item);var itemOpts={'left':(orig_pos.left-18)+'px','top':(orig_pos.top-18)+'px','width':$(orig_item).width(),'height':$(orig_item).height()};if(opts.zoomOpacity){itemOpts.opacity='hide'}$("#justinabox_outer").stop(false,true).animate(itemOpts,opts.zoomSpeedOut,opts.easingOut,__cleanup)}else{$("#justinabox_outer").stop(false,true).fadeOut("fast",__cleanup)}}else{__cleanup()}return false};$.fn.justinabox.build=function(){var html='';html+='<div id="justinabox_overlay"></div>';html+='<div id="justinabox_wrap">';html+='<div class="justinabox_loading" id="justinabox_loading"><div></div></div>';html+='<div id="justinabox_outer">';html+='<div id="justinabox_inner">';html+='<div id="justinabox_close"></div>';html+='<div id="justinabox_bg"><div class="justinabox_bg justinabox_bg_n"></div><div class="justinabox_bg justinabox_bg_ne"></div><div class="justinabox_bg justinabox_bg_e"></div><div class="justinabox_bg justinabox_bg_se"></div><div class="justinabox_bg justinabox_bg_s"></div><div class="justinabox_bg justinabox_bg_sw"></div><div class="justinabox_bg justinabox_bg_w"></div><div class="justinabox_bg justinabox_bg_nw"></div></div>';html+='<a href="javascript:;" id="justinabox_left"><span class="justinabox_ico" id="justinabox_left_ico"></span></a><a href="javascript:;" id="justinabox_right"><span class="justinabox_ico" id="justinabox_right_ico"></span></a>';html+='<div id="justinabox_content"></div>';html+='<div id="justinabox_title"></div>';html+='</div>';html+='</div>';html+='</div>';$(html).appendTo("body");$('<table cellspacing="0" cellpadding="0" border="0"><tr><td class="justinabox_title" id="justinabox_title_left"></td><td class="justinabox_title" id="justinabox_title_main"><div></div></td><td class="justinabox_title" id="justinabox_title_right"></td></tr></table>').appendTo('#justinabox_title');if(isIE){$("#justinabox_inner").prepend('<iframe class="justinabox_bigIframe" scrolling="no" frameborder="0"></iframe>');$("#justinabox_close, .justinabox_bg, .justinabox_title, .justinabox_ico").fixPNG()}};$.fn.justinabox.defaults={padding:10,imageScale:true,zoomOpacity:false,zoomSpeedIn:0,zoomSpeedOut:0,zoomSpeedChange:300,easingIn:'swing',easingOut:'swing',easingChange:'swing',frameWidth:425,frameHeight:355,overlayShow:true,overlayOpacity:0.3,hideOnContentClick:true,centerOnScroll:true,itemArray:[],callbackOnStart:null,callbackOnShow:null,callbackOnClose:null};$(document).ready(function(){$.fn.justinabox.build()})})(jQuery);
