/*
 * version: 1.0.4
 * 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,ob_fadeOutTime=200,ob_overlayOpacity=0.9,ob_maxVideoHeight=390,ob_maxVideoWidth=640,ob_preloaderDelay=600,ob_unsupportedMedia_Message="Unsupported Media",ob_fileNotFound_Message="File Not Found",ob_showDots=true,ob_showNav=false,ob_showClose=true,ob_showTitle=false,ob_keyboardNavigation=true,ob_contentBorderWidth=4,ob_contentMinHeight=100,ob_contentMinWidth=200,ob_imageBorderWidth=1,ob_inineWidth=0.5,ob_inineHeight=0,ob_maxImageHeight=0.75,ob_maxImageWidth=0.75,ob_iframeWidth=0.75,ob_iframeHeight=0.75;(function($){$.fn.extend({orangebox:function(){return this.each(function(){$(this).click(function(e){var modalTitle=$('<div id="ob_title"></div>'),modalClose='<div title="close" id="ob_close"></div>',modalNavRight=$('<a class="ob_nav" id="ob_right"><span id="ob_right-ico"></span></a>'),modalNavLeft=$('<a class="ob_nav" id="ob_left"><span id="ob_left-ico"></span></a>'),modalContent=$('<div id="ob_content"></div>'),overlay=$('<div id="ob_overlay"></div>'),modalWindow=$('<div id="ob_window"></div>'),modalContainer=$('<div id="ob_container"></div>'),modalFloat=$('<div id="ob_float"></div>'),dotnav=$('<ul id="ob_dots"></ul>'),ob_load=$('<div id="ob_load"></div>'),t,imageType=[".jpg",".png",".jpeg",".bmp",".gif"],quicktimeType=[".mov",".mp4",".m4v"],lightboxlink='a[rel=lightboxlink]',mainhref=$(this).attr("href"),maintitle=$(this).attr("title"),rel=$(this).attr('rel'),height,width,galleryItems=new Array(),titles=new Array(),currentIndex,progress=null,s,isError=false,content,gallery,scrollPos,docHeight=$(window).height(),docWidth=$(window).width();if(docHeight===0){docHeight=$(document).height();}if(docWidth===0){docWidth=$(document).width();}function getScrollPos(){var pos=$(window).scrollTop();if(pos===0){pos=$(document).scrollTop();}if(pos===0){pos=window.pageYOffset;}return pos;}scrollPos=getScrollPos();overlay.css({"opacity":ob_overlayOpacity,"min-width":docWidth,"min-height":docHeight+scrollPos});modalContent.css({"border-width":ob_contentBorderWidth,"min-height":ob_contentMinHeight,"min-width":ob_contentMinWidth});window.onscroll=function(){var newPos=getScrollPos();if(newPos>scrollPos){var scrolltimer=setTimeout(function(){overlay.css({"height":newPos+docHeight});scrollPos=newPos;clearTimeout(scrolltimer);},300);}};e.preventDefault();if(typeof document.body.style.maxHeight==="undefined"){$("body","html").css({height:"100%",width:"100%"});}t=setTimeout(function(){$("body").append(ob_load);},ob_preloaderDelay);function checkContentType(itemhref){if(itemhref==="ob_hidden_set"){return"ob_hidden_set";}if(itemhref.match(/\?iframe$/)){return"iframe";}if(itemhref.match(/\.(?:jpg|jpeg|bmp|png|gif)$/)){return"image";}if(itemhref.match(/\.(?:mov|mp4|m4v)(\?.{6,}\&.{6,})?$/)){return"quicktime";}if(itemhref.match(/\.swf(\?.{6,}\&.{6,})?$/)){return"flash";}if(itemhref.match(/^http:\/\/\w{0,3}\.?youtube\.\w{2,3}\/watch\?v=[\w\-]{11}/)){return"youtube";}if(itemhref.match(/^http:\/\/\w{0,3}\.?vimeo\.com\/\d{1,10}/)){return"vimeo";}if(itemhref.match(/^#/)){return"inline";}return;}if(rel.substring(8)){gallery=rel.substring(rel.indexOf("[")+1,rel.indexOf("]"));}if(gallery){var arrayID=0,objectMatch='a[rel*=\'lightbox['+gallery+']\']';$(objectMatch).each(function(){var itemhref=$(this).attr("href"),title=$(this).attr("title"),contentType=checkContentType(mainhref),inGallery=jQuery.inArray(itemhref,galleryItems);if(contentType&&inGallery===-1&&itemhref!=="ob_hidden_set"){galleryItems[arrayID]=itemhref;titles[arrayID]=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++;}});if($('#ob_gallery').length>0){$('#ob_gallery li.'+gallery).each(function(){var itemhref=$(this).attr("id"),title=$(this).attr("title"),contentType=checkContentType(mainhref),inGallery=jQuery.inArray(itemhref,galleryItems);if(contentType&&inGallery===-1){galleryItems[arrayID]=itemhref;titles[arrayID]=title;if(ob_showDots){dotnav.append('<li id="ob_dot'+arrayID+'"></li>');}arrayID++;}});}}function navigate(href,title){clearTimeout(t);t=setTimeout(function(){$("body").append(ob_load);},ob_preloaderDelay);modalWindow.fadeOut(ob_fadeOutTime,function(){content.empty();modalTitle.empty().remove();modalContent.empty().remove();modalWindow.empty().remove();modalContainer.empty();var contentType=checkContentType(href);if(contentType==="iframe"){showiFrame(href,title);}else 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);}});}function navigateHandler(index){if(galleryItems[index]){var href=galleryItems[index],title=titles[index];currentIndex=index;navigate(href,title);}else{progress=null;}}function showNavigation(currenthref){for(var i=0;i<galleryItems.length;i++){if(galleryItems[i]==currenthref){currentIndex=i;};}if(ob_showDots){modalWindow.append(dotnav);dotnav.find("li").click(function(){if(!$(this).hasClass('current')){var id=$(this).attr('id'),newid=id.substr(6);dotnav.find("li").removeClass('current');$(this).addClass('current');navigateHandler(newid);}});}if(ob_showNav){modalWindow.append(modalNavRight).append(modalNavLeft);if(galleryItems[currentIndex+1]){modalNavRight.show();}else{modalNavRight.hide();};if(galleryItems[currentIndex-1]){modalNavLeft.show();}else{modalNavLeft.hide();};modalNavLeft.click(function(e){e.stopPropagation();navigateHandler(currentIndex-1);});modalNavRight.click(function(e){e.stopPropagation();navigateHandler(currentIndex+1);});}}function handleEscape(e){if(progress==null){progress="running";if(e.keyCode==27){modalHide();}else if(e.keyCode==37){navigateHandler(currentIndex-1);}else if(e.keyCode==39){navigateHandler(currentIndex+1);}else{progress=null;};};}function modalHide(){$(document).unbind("keydown",handleEscape);var remove=function(){$(this).remove().empty();};clearTimeout(t);ob_load.remove();overlay.fadeOut(ob_fadeOutTime,remove);modalContainer.fadeOut(ob_fadeOutTime,remove);}$("body").append(overlay.click(function(){modalHide();}));$("body").append(modalContainer.click(function(){modalHide();}));if(ob_keyboardNavigation){$(document).keydown(handleEscape);}overlay.show(ob_fadeInTime);function setModalProperties(){var objectHeight=content.outerHeight(),objectWidth=content.outerWidth(),windowHeight=objectHeight+(ob_contentBorderWidth*2),windowWidth=objectWidth+(ob_contentBorderWidth*2);if(windowHeight<ob_contentMinHeight&&isError===false){windowHeight=ob_contentMinHeight+(ob_contentBorderWidth*2);}if(windowWidth<ob_contentMinWidth&&isError===false){windowWidth=ob_contentMinWidth+(ob_contentBorderWidth*2);}modalContainer.css({"margin-top":getScrollPos()});modalWindow.css({"height":windowHeight,"width":windowWidth});if(isError){modalContent.css({"height":objectHeight,"width":objectWidth,"min-height":0});}else{modalContent.css({"height":windowHeight-(ob_contentBorderWidth*2),"width":windowWidth-(ob_contentBorderWidth*2),"min-height":ob_contentMinHeight});}modalFloat.css({"margin-bottom":-windowHeight/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'+currentIndex;dotnav.find("li").removeClass('current');$(current).addClass('current');}progress=null;}function getValue(href){var heightIndex=href.indexOf("height=")+7,widthIndex=href.indexOf("width=")+6,heightString=href.substr(heightIndex),widthString=href.substr(widthIndex);if(heightString.indexOf("&")>0){heightString=heightString.substr(0,heightString.indexOf("&"));}if(widthString.indexOf("&")>0){widthString=widthString.substr(0,widthString.indexOf("&"));}width=widthString;height=heightString;}function buildit(title,href){clearTimeout(t);ob_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);modalWindow.fadeIn(ob_fadeInTime);$("#ob_close").click(function(){modalHide();});setModalProperties();}function throwError(type){var message;if(type==1){message=ob_unsupportedMedia_Message;}else if(type==2){message=ob_fileNotFound_Message;}content=$('<div id="ob_error">'+message+'</div>');clearTimeout(t);ob_load.remove();modalContent.empty().append(content);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();});isError=true;setModalProperties();isError=false;}function showiFrame(href,title){var args='height="100%" width="100%" frameborder="0" hspace="0" scrolling="auto"',newhref=href.replace(/\?iframe$/,'');newhref=newhref.replace(/\?iframe\&/,'?');newhref=newhref.replace(/\&iframe/,'');content=$('<iframe id="ob_iframe" '+args+' src="'+newhref+'"></iframe>');if(ob_iframeWidth>1){content.css({"width":ob_iframeWidth});}else if(ob_iframeWidth>0){content.css({"width":docWidth*ob_iframeWidth});}if(ob_iframeHeight>1){content.css({"height":ob_iframeHeight});}else if(ob_iframeHeight>0){content.css({"height":docHeight*ob_iframeHeight});}buildit(title,href);}function showInline(href,title){content=$('<div id="ob_inline">'+$(href).html()+'</div>');if(ob_inineWidth>1){content.css({"width":ob_inineWidth});}else if(ob_inineWidth>0){content.css({"width":docWidth*ob_inineWidth});}if(ob_inineHeight>1){content.css({"height":ob_inineHeight});}else if(ob_inineHeight>0){content.css({"height":docHeight*ob_inineHeight});}buildit(title,href);}function showVideo(href,title,contentType){var idIndex,ID,ratio=0,maxHeight,maxWidth;if(ob_maxVideoHeight>1){maxHeight=ob_maxVideoHeight;}else if(ob_maxVideoHeight>0){maxHeight=docHeight*ob_maxVideoHeight;}if(ob_maxVideoWidth>1){maxWidth=ob_maxVideoWidth;}else if(ob_maxVideoWidth>0){maxWidth=docWidth*ob_maxVideoWidth;}if(href.indexOf("height=")>=0&&href.indexOf("width=")>=0){getValue(href);if(height>maxHeight){ratio=maxHeight/height;width=width*ratio;height=maxHeight;};if(width>maxWidth){ratio=maxWidth/width;height=height*ratio;width=maxWidth;};}else{width=maxWidth;height=maxHeight;};var paramStart='<div><object width="'+width+'" height="'+height+'"><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><param name="movie" value="';var paramEnd='type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="'+width+'" height="'+height+'"></embed></object></div>';if(contentType=="youtube"){idIndex=href.indexOf("?v=")+3;if(href.indexOf("&")>idIndex){ID=href.substring(idIndex,href.indexOf("&"));}else{ID=href.substring(idIndex);};content=$(paramStart+'http://www.youtube.com/v/'+ID+'?fs=1&hl=en_US&rel=0&autoplay=1"></param><embed src="http://www.youtube.com/v/'+ID+'?fs=1&hl=en_US&rel=0&autoplay=1"'+paramEnd);}else if(contentType=="vimeo"){idIndex=href.indexOf("vimeo.com/")+10;if(href.indexOf("?")>idIndex){ID=href.substring(idIndex,href.indexOf("?"));}else{ID=href.substring(idIndex);};content=$(paramStart+'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"></param><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"'+paramEnd);}else if(contentType=="quicktime"){content=$('<div><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="aspect"></object></div>');}else if(contentType=="flash"){content=$('<div><embed flashVars="playerVars=autoPlay=yes" src="'+href+'" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" allowFullScreen="true" allowScriptAccess="always" width="'+width+'" height="'+height+'" type="application/x-shockwave-flash"></embed></div>');};content.css({"width":width,"height":height});buildit(title,href);}function showImage(href,title){var img=new Image();content=$(img);content.load(function(){var maxHeight=0,maxWidth=0,ratio=0;if(ob_maxImageHeight>1){maxHeight=ob_maxImageHeight;}else if(ob_maxImageHeight>0){maxHeight=docHeight*ob_maxImageHeight;}if(ob_maxImageWidth>1){maxWidth=ob_maxImageWidth;}else if(ob_maxImageWidth>0){maxWidth=docWidth*ob_maxImageWidth;}width=img.width;height=img.height;if(height>maxHeight){ratio=maxHeight/height;width=width*ratio;height=maxHeight;}if(width>maxWidth){ratio=maxWidth/width;height=height*ratio;width=maxWidth;}if(height<ob_contentMinHeight){content.css({"margin-top":(ob_contentMinHeight/2)-(height/2)});}if(width<ob_contentMinWidth){content.css({"margin-left":(ob_contentMinWidth/2)-(width/2)});}content.css({"height":parseInt(height),"width":parseInt(width),"border-width":ob_imageBorderWidth});buildit(title,href);}).error(function(){throwError(2);}).attr({src:href});}var contentType=checkContentType(mainhref);if(contentType==="ob_hidden_set"){mainhref=galleryItems[0];maintitle=titles[0];contentType=checkContentType(mainhref);}if(contentType==="iframe"){showiFrame(mainhref,maintitle);}else 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();})
