/*
 * version: 1.0 Beta2
 * package: OrangeBox
 * author: David Paul Hamilton - http://orangebox.davidpaulhamilton.net
 * copyright: Copyright (c) 2011 David Hamilton / DavidPaulHamilton.net All rights reserved.
 * license: GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
 */
var ob_fadeInTime=200;var ob_fadeOutTime=200;var ob_overlayOpacity=0.9;var ob_inineWidthPercent=.5;var ob_maxVideoHeight=390;var ob_maxVideoWidth=640;var ob_maxImageHeight=.7;var ob_preloaderDelay=600;var ob_unsupportedMedia_Message="Unsupported Media";var ob_fileNotFound_Message="File Not Found";var ob_showDots=true;var ob_showNav=false;var ob_showClose=true;var ob_showTitle=false;var ob_keyboardNavigation=true;var ob_contentBorderWidth=4;var ob_contentMinHeight=100;var ob_contentMinWidth=200;var ob_imageBorderWidth=1;if(typeof(orangebox)!=='undefined'){ob_fadeInTime=parseFloat(orangebox.ob_fadeInTime);ob_fadeOutTime=parseFloat(orangebox.ob_fadeOutTime);ob_overlayOpacity=parseFloat(orangebox.ob_overlayOpacity);ob_inineWidthPercent=parseFloat(orangebox.ob_inineWidthPercent);ob_maxVideoHeight=parseFloat(orangebox.ob_maxVideoHeight);ob_maxVideoWidth=parseFloat(orangebox.ob_maxVideoWidth);ob_maxImageHeight=parseFloat(orangebox.ob_maxImageHeight);ob_preloaderDelay=parseFloat(orangebox.ob_preloaderDelay);ob_unsupportedMedia_Message=orangebox.ob_unsupportedMedia_Message;ob_fileNotFound_Message=orangebox.ob_fileNotFound_Message;ob_showDots=orangebox.ob_showDots;ob_showNav=orangebox.ob_showNav;ob_showClose=orangebox.ob_showClose;ob_showTitle=orangebox.ob_showTitle;ob_keyboardNavigation=orangebox.ob_keyboardNavigation;ob_contentBorderWidth=parseFloat(orangebox.ob_contentBorderWidth);ob_contentMinHeight=parseFloat(orangebox.ob_contentMinHeight);ob_contentMinWidth=parseFloat(orangebox.ob_contentMinWidth);ob_imageBorderWidth=parseFloat(orangebox.ob_imageBorderWidth);};(function($){$.fn.extend({orangebox:function(){return this.each(function(){$(this).click(function(e){var modalTitle=$('<div id="ob_title"></div>');var modalClose='<div title="close" id="ob_close"></div>';var modalNavRight=$('<a class="ob_nav" id="ob_right"><span id="ob_right-ico"></span></a>');var modalNavLeft=$('<a class="ob_nav" id="ob_left"><span id="ob_left-ico"></span></a>');var modalContent=$('<div id="ob_content"></div>');var overlay=$('<div id="ob_overlay"></div>');var modalWindow=$('<div id="ob_window"></div>');var modalContainer=$('<div id="ob_container"></div>');var modalFloat=$('<div id="ob_float"></div>');var dotnav=$('<ul id="ob_dots"></ul>');var t;var imageType=[".jpg",".png",".jpeg",".bmp",".gif"];var quicktimeType=[".mov",".mp4",".m4v"];var lightboxlink='a[rel=lightboxlink]';overlay.css({"opacity":ob_overlayOpacity,"min-width":$(window).width(),"min-height":$(window).height(),});modalContent.css({"border-width":ob_contentBorderWidth,"min-height":ob_contentMinHeight,"min-width":ob_contentMinWidth});function modalHide(){$(document).unbind("keydown",handleEscape);var remove=function(){$(this).remove().empty();};clearTimeout(t);$("#modal-load").remove();overlay.fadeOut(ob_fadeOutTime,remove);modalContainer.fadeOut(ob_fadeOutTime,remove);};e.preventDefault();if(typeof document.body.style.maxHeight==="undefined"){$("body","html").css({height:"100%",width:"100%"});};$("body").append(overlay.click(function(){modalHide();}));$("body").append(modalContainer.click(function(){modalHide();}));t=setTimeout(function(){$("body").append("<div id='modal-load'></div>");},ob_preloaderDelay);var mainhref=$(this).attr("href");var maintitle=$(this).attr("title");var rel=$(this).attr('rel');var height;var width;var galleryItems=new Array();var titles=new Array();var indexValue;var progress=null;var s;var isImage=false;function checkContentType(itemhref){for(z=0;z<imageType.length;z++){var matchString=imageType[z];if(itemhref.indexOf(matchString)>=0){return"image";};};for(z=0;z<quicktimeType.length;z++){var matchString=quicktimeType[z];if(itemhref.indexOf(matchString)>=0){return"quicktime";};};if(itemhref.indexOf(".swf")>=0){return"flash";};if(itemhref.indexOf("youtube.com/watch?v=")>=0){return"youtube";};if(itemhref.indexOf("vimeo.com/")>=0){return"vimeo";};if(itemhref.indexOf("#")>=0&&$(itemhref).html()){return"inline";};return;};function navigateHandler(index){if(galleryItems[index]){href=galleryItems[index];title=titles[index];indexValue=index;navigate(href,title);}else{progress=null;};};if(ob_showDots||ob_showNav){if(rel.substring(8)){var gallery=rel.substring(rel.indexOf("[")+1,rel.indexOf("]"));};if(gallery){var arrayID=0;var objectMatch='a[rel*=\'lightbox['+gallery+']\']';var length=$(objectMatch).length;if(length>1){for(x=0;x<length;x++){var itemhref=$(objectMatch).eq(x).attr("href");var contentType=checkContentType(itemhref);var inGallery=jQuery.inArray(itemhref,galleryItems);if(contentType&&inGallery==-1){galleryItems[arrayID]=itemhref;titles[arrayID]=$(objectMatch).eq(x).attr("title");if(ob_showDots){if(arrayID==0){dotnav.append('<li class="current" id="ob_dot'+arrayID+'"></li>');}else{dotnav.append('<li id="ob_dot'+arrayID+'"></li>');}};arrayID++;};};};};function showNavigation(currenthref){for(var i=0;i<galleryItems.length;i++){if(galleryItems[i]==currenthref){indexValue=i;};};if(ob_showDots){modalWindow.append(dotnav);};if(ob_showNav){modalWindow.append(modalNavRight).append(modalNavLeft);if(galleryItems[indexValue+1]){modalNavRight.show();}else{modalNavRight.hide();};if(galleryItems[indexValue-1]){modalNavLeft.show();}else{modalNavLeft.hide();};};if(ob_showNav){modalNavLeft.click(function(e){e.stopPropagation();navigateHandler(indexValue-1);});modalNavRight.click(function(e){e.stopPropagation();navigateHandler(indexValue+1);});};if(ob_showDots){dotnav.find("li").hover(function(){if(!$(this).hasClass('current')){$(this).css('background-color','#999999');};},function(){if(!$(this).hasClass('current')){$(this).css('background-color','#666666');};}).click(function(){var id=$(this).attr('id');var newid=id.substr(6);dotnav.find("li").removeClass('current').css('background-color','#666666');$(this).addClass('current');navigateHandler(newid);});};};};function handleEscape(e){if(progress==null){progress="running";if(e.keyCode==27){modalHide();}else if(e.keyCode==37){navigateHandler(indexValue-1);}else if(e.keyCode==39){navigateHandler(indexValue+1);}else{progress=null;};};};function navigate(href,title){clearTimeout(t);t=setTimeout(function(){$("body").append("<div id='modal-load'></div>");},ob_preloaderDelay);modalWindow.fadeOut(ob_fadeOutTime,function(){modalTitle.empty().remove();modalContent.empty().remove();modalWindow.empty().remove();modalContainer.empty();var contentType=checkContentType(href);if(contentType=="image")showImage(href,title);else if(contentType=="inline")showInline(href,title);else if(contentType=="quicktime")showVideo(href,title,contentType);else if(contentType=="youtube")showVideo(href,title,contentType);else if(contentType=="vimeo")showVideo(href,title,contentType);else if(contentType=="flash")showVideo(href,title,contentType);});};overlay.show(ob_fadeInTime);if(ob_keyboardNavigation){$(document).keydown(handleEscape);};function setModalSize(object){var objectHeight=object.outerHeight();var objectWidth=object.outerWidth();if(!ob_contentBorderWidth){ob_contentBorderWidth=0;};if(!ob_imageBorderWidth){ob_imageBorderWidth=0;};var windowHeight=objectHeight+(ob_contentBorderWidth*2);var windowWidth=objectWidth+(ob_contentBorderWidth*2);if(isImage){windowHeight=windowHeight+(ob_imageBorderWidth*2);windowWidth=windowWidth+(ob_imageBorderWidth*2);};if(windowHeight<ob_contentMinHeight){windowHeight=ob_contentMinHeight+(ob_contentBorderWidth*2);};if(windowWidth<ob_contentMinWidth){windowWidth=ob_contentMinWidth+(ob_contentBorderWidth*2);};modalContainer.css({"margin-top":$(window).scrollTop()});modalWindow.css({"height":windowHeight,"width":windowWidth});modalFloat.css({"margin-bottom":-$('#ob_window').outerHeight()/2});modalWindow.click(function(e){e.stopPropagation();});$(lightboxlink).click(function(e){e.preventDefault();e.stopPropagation();navigate($(this).attr('href'),$(this).attr('title'))});if(ob_showDots){var current='#ob_dot'+indexValue;dotnav.find("li").removeClass('current').css('background-color','#666666');$(current).addClass('current');};progress=null;};function throwError(type){var message;if(type==1){message=ob_unsupportedMedia_Message;}else if(type==2){message=ob_fileNotFound_Message;};var modalError=$('<div id="modal-error">'+message+'</div>');clearTimeout(t);$("#modal-load").remove();modalContent.empty().append(modalError).css('min-height','0');modalWindow.empty().append(modalContent);if(ob_showClose){modalWindow.append(modalClose);};modalContainer.empty().append(modalFloat).append(modalWindow);modalWindow.fadeIn(ob_fadeInTime);$("#ob_close").click(function(){modalHide();});setModalSize(modalError);};function showInline(href,title){var inlineContent=$('<div id="modal-inline">'+$(href).html()+'</div>');clearTimeout(t);$("#modal-load").remove();modalTitle.append('<h3>'+title+'</h3>');modalContent.append(inlineContent);modalWindow.append(modalContent);if(ob_showClose){modalWindow.append(modalClose);};if(ob_showTitle){modalWindow.append(modalTitle);};if(galleryItems.length>1)showNavigation(href);modalContainer.append(modalFloat).append(modalWindow);$('#modal-inline').css({"width":$(window).width()*ob_inineWidthPercent});modalWindow.fadeIn(ob_fadeInTime);$("#ob_close").click(function(){modalHide();});setModalSize(inlineContent);};function showVideo(href,title,contentType){var idIndex;var ID;var content;var heightIndex=href.indexOf("height=")+7;var widthIndex=href.indexOf("width=")+6;var ampIndex=href.indexOf("&");var ratio=0;if(href.indexOf("height=")>=0&&href.indexOf("width=")>=0){if(widthIndex>ampIndex){height=href.substring(heightIndex,ampIndex);width=href.substring(widthIndex);}else if(widthIndex<ampIndex){height=href.substring(heightIndex);width=href.substring(widthIndex,ampIndex);};if(height>ob_maxVideoHeight){ratio=ob_maxVideoHeight/height;width=width*ratio;height=ob_maxVideoHeight;};}else{width=ob_maxVideoWidth;height=ob_maxVideoHeight;};if(contentType=="youtube"){idIndex=href.indexOf("?v=")+3;if(href.indexOf("&")>=0){ID=href.substring(idIndex,ampIndex);}else{ID=href.substring(idIndex);};content=$('<object width="'+width+'" height="'+height+'"><param name="movie" value="http://www.youtube.com/v/'+ID+'?fs=1&hl=en_US&rel=0&autoplay=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+ID+'?fs=1&hl=en_US&rel=0&autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+width+'" height="'+height+'"></embed></object>');}else if(contentType=="vimeo"){idIndex=href.indexOf("vimeo.com/")+10;ID=href.substring(idIndex);content=$('<object width="'+width+'" height="'+height+'"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id='+ID+'&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=ff9933&fullscreen=1&autoplay=1&loop=0" /><embed src="http://vimeo.com/moogaloop.swf?clip_id='+ID+'&server=vimeo.com&show_title=0&show_byline=0&show_portrait=0&color=ff9933&fullscreen=1&autoplay=1&loop=0" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="'+width+'" height="'+height+'"></embed></object>');}else if(contentType=="quicktime"){content=$('<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="'+height+'" width="'+width+'"><param name="src" value="'+href+'"><param name="type" value="video/quicktime"><param name="autoplay" value="true"><embed src="'+href+'" height="'+height+'" width="'+width+'" autoplay="true"  type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/" scale="tofit"></object>');}else if(contentType=="flash"){content=$('<embed flashVars="playerVars=autoPlay=yes" src="'+href+'" width="'+width+'" height="'+height+'" wmode="transparent" allowFullScreen="true" allowScriptAccess="always" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>');};clearTimeout(t);$("#modal-load").remove();modalTitle.append('<h3>'+title+'</h3>');modalContent.append(content);modalWindow.append(modalContent);if(ob_showClose){modalWindow.append(modalClose);};if(ob_showTitle){modalWindow.append(modalTitle);};if(galleryItems.length>1)showNavigation(href);modalContainer.append(modalFloat).append(modalWindow);setModalSize(content);modalWindow.fadeIn(ob_fadeInTime);$("#ob_close").click(function(){modalHide();});};function showImage(href,title){function setImageSize(image){var maxHeight=$(window).height()*ob_maxImageHeight;var minHeight=parseInt($(modalContent).css('min-height'));var minWidth=parseInt($(modalContent).css('min-width'));var ratio=0;width=image.width;height=image.height;if(height>maxHeight){ratio=maxHeight/height;width=width*ratio;height=maxHeight;};if(height<minHeight){var imageTopMargin=(minHeight/2)-(height/2);$(image).css({"margin-top":imageTopMargin});};if(width<minWidth){var imageLeftMargin=(minWidth/2)-(width/2);$(image).css({"margin-left":imageLeftMargin});};$(image).css({"height":parseInt(height),"width":parseInt(width),"border-width":ob_imageBorderWidth});isImage=true;setModalSize($(image));isImage=false;};var img=new Image();$(img).load(function(){clearTimeout(t);$("#modal-load").remove();modalTitle.append('<h3>'+title+'</h3>');modalContent.append(img);modalWindow.append(modalContent);if(ob_showClose){modalWindow.append(modalClose);};if(ob_showTitle){modalWindow.append(modalTitle);};if(galleryItems.length>1)showNavigation(href);modalContainer.append(modalFloat).append(modalWindow);setImageSize(img);modalWindow.fadeIn(ob_fadeInTime);$("#ob_close").click(function(){modalHide();});}).error(function(){throwError(2);}).attr({src:href});};var contentType=checkContentType(mainhref);if(contentType=="image")showImage(mainhref,maintitle);else if(contentType=="inline")showInline(mainhref,maintitle);else if(contentType=="quicktime")showVideo(mainhref,maintitle,contentType);else if(contentType=="youtube")showVideo(mainhref,maintitle,contentType);else if(contentType=="vimeo")showVideo(mainhref,maintitle,contentType);else if(contentType=="flash")showVideo(mainhref,maintitle,contentType);else throwError(1);});});}});})(jQuery);$(function(){$('a[rel*=lightbox]').orangebox();});
