/* UE Modal - Janis Skarnelis - http://fancybox.net */
;(function($){var tmp,loading,overlay,wrap,outer,inner,content,close,nav_left,nav_right;var selectedIndex=0,selectedOpts={},selectedArray=[],currentIndex=0,currentOpts={},currentArray=[];var ajaxLoader=null,imgPreloader=new Image,imageRegExp=/\.(jpg|gif|png|bmp|jpeg)(.*)?$/i,swfRegExp=/[^\.]\.(swf)\s*$/i;var loadingTimer,loadingFrame=1;var start_pos,final_pos,busy=false,shadow=20,fx=$.extend($('<div/>')[0],{prop:0}),titleh=0,isIE6=!$.support.opacity&&!window.XMLHttpRequest;$.fn.uemodal=function(options){$(this).data('uemodal',$.extend({},options));$(this).unbind('click.fb').bind('click.fb',function(e){e.preventDefault();if(busy)return;busy=true;$(this).blur();selectedArray=[];selectedIndex=0;var rel=$(this).attr('rel')||'';if(!rel||rel==''||rel==='nofollow'){selectedArray.push(this);}else{selectedArray=$("a[rel="+rel+"], area[rel="+rel+"]");selectedIndex=selectedArray.index(this);}
uemodal_start();return false;});return this;};$.uemodal=function(obj,opts){if(busy)return;busy=true;selectedArray=[];selectedIndex=0;if($.isArray(obj)){for(var i=0,j=obj.length;i<j;i++){if(typeof obj[i]=='object'){$(obj[i]).data('uemodal',$.extend({},opts,obj[i]));}else{obj[i]=$({}).data('uemodal',$.extend({content:obj[i]},opts));}}
selectedArray=jQuery.merge(selectedArray,obj);}else{if(typeof obj=='object'){$(obj).data('uemodal',$.extend({},opts,obj));}else{obj=$({}).data('uemodal',$.extend({content:obj},opts));}
selectedArray.push(obj);}
uemodal_start();};$.uemodal.showActivity=function(){clearInterval(loadingTimer);loading.show();loadingTimer=setInterval(uemodal_animate_loading,66);};$.uemodal.hideActivity=function(){loading.hide();};$.uemodal.next=function(){return $.uemodal.pos(currentIndex+1);};$.uemodal.prev=function(){return $.uemodal.pos(currentIndex-1);};$.uemodal.pos=function(pos){if(busy)return;pos=parseInt(pos);if(pos>-1&&currentArray.length>pos){selectedIndex=pos;uemodal_start();}
if(currentOpts.cyclic&&currentArray.length>1&&pos<0){selectedIndex=currentArray.length-1;uemodal_start();}
if(currentOpts.cyclic&&currentArray.length>1&&pos>=currentArray.length){selectedIndex=0;uemodal_start();}
return;};$.uemodal.cancel=function(){if(busy)return;busy=true;$.event.trigger('uemodal-cancel');uemodal_abort();if(selectedOpts&&$.isFunction(selectedOpts.onCancel)){selectedOpts.onCancel(selectedArray,selectedIndex,selectedOpts);};busy=false;};$.uemodal.close=function(){if(busy||wrap.is(':hidden'))return;busy=true;if(currentOpts&&$.isFunction(currentOpts.onCleanup)){if(currentOpts.onCleanup(currentArray,currentIndex,currentOpts)===false){busy=false;return;}};uemodal_abort();$(close.add(nav_left).add(nav_right)).hide();$('#ue-modal-title').remove();wrap.add(inner).add(overlay).unbind();$(window).unbind("resize.fb scroll.fb");$(document).unbind('keydown.fb');function _cleanup(){overlay.fadeOut('fast');wrap.hide();$.event.trigger('uemodal-cleanup');inner.empty();if($.isFunction(currentOpts.onClosed)){currentOpts.onClosed(currentArray,currentIndex,currentOpts);}
currentArray=selectedOpts=[];currentIndex=selectedIndex=0;currentOpts=selectedOpts={};busy=false;}
inner.css('overflow','hidden');if(currentOpts.transitionOut=='elastic'){start_pos=uemodal_get_zoom_from();var pos=wrap.position();final_pos={top:pos.top,left:pos.left,width:wrap.width(),height:wrap.height()};if(currentOpts.opacity){final_pos.opacity=1;}
fx.prop=1;$(fx).animate({prop:0},{duration:currentOpts.speedOut,easing:currentOpts.easingOut,step:uemodal_draw,complete:_cleanup});}else{wrap.fadeOut(currentOpts.transitionOut=='none'?0:currentOpts.speedOut,_cleanup);}};$.uemodal.resize=function(){if(busy||wrap.is(':hidden'))return;busy=true;var c=inner.wrapInner("<div style='overflow:auto'></div>").children();var h=c.height();wrap.css({height:h+(currentOpts.padding*2)+titleh});inner.css({height:h});c.replaceWith(c.children());$.uemodal.center();};$.uemodal.center=function(){busy=true;var view=uemodal_get_viewport();var margin=currentOpts.margin;var to={};to.top=view[3]+((view[1]-((wrap.height()-titleh)+(shadow*2)))*0.5);to.left=view[2]+((view[0]-(wrap.width()+(shadow*2)))*0.5);to.top=Math.max(view[3]+margin,to.top);to.left=Math.max(view[2]+margin,to.left);wrap.css(to);busy=false;};function uemodal_abort(){loading.hide();imgPreloader.onerror=imgPreloader.onload=null;if(ajaxLoader)ajaxLoader.abort();tmp.empty();};function uemodal_error(){$.uemodal('<p id="ue-modal-error">The requested content cannot be loaded.<br />Please try again later.</p>',{'scrolling':'no','padding':20,'transitionIn':'none','transitionOut':'none'});};function uemodal_start(){uemodal_abort();var obj=selectedArray[selectedIndex];selectedOpts=$.extend({},$.fn.uemodal.defaults,(typeof $(obj).data('uemodal')=='undefined'?selectedOpts:$(obj).data('uemodal')));var href,type,title=obj.title||$(obj).title||selectedOpts.title||'';if(obj.nodeName&&!selectedOpts.orig){selectedOpts.orig=$(obj).children("img:first").length?$(obj).children("img:first"):$(obj);}
if(title==''&&selectedOpts.orig)title=selectedOpts.orig.attr('alt');if(obj.nodeName&&(/^(?:javascript|#)/i).test(obj.href)){href=selectedOpts.href||null;}else{href=selectedOpts.href||obj.href||null;}
if(selectedOpts.type){type=selectedOpts.type;if(!href)href=selectedOpts.content;}else if(selectedOpts.content){type='html';}else if(href){if(href.match(imageRegExp)){type='image';}else if(href.match(swfRegExp)){type='swf';}else if($(obj).hasClass("ue-modal-iframe")){type='iframe';}else if(href.match(/#/)){obj=href.substr(href.indexOf("#"));type=$(obj).length>0?'inline':'ajax';}else{type='ajax';}}else{type='inline';}
selectedOpts.type=type;selectedOpts.href=href;selectedOpts.title=title;if(selectedOpts.autoDimensions&&selectedOpts.type!=='iframe'&&selectedOpts.type!=='swf'){selectedOpts.width='auto';selectedOpts.height='auto';}
if(selectedOpts.modal){selectedOpts.overlayShow=true;selectedOpts.hideOnOverlayClick=false;selectedOpts.hideOnContentClick=false;selectedOpts.enableEscapeButton=false;selectedOpts.showCloseButton=false;}
if($.isFunction(selectedOpts.onStart)){if(selectedOpts.onStart(selectedArray,selectedIndex,selectedOpts)===false){busy=false;return;}};tmp.css('padding',(shadow+selectedOpts.padding+selectedOpts.margin));$('.ue-modal-inline-tmp').unbind('uemodal-cancel').bind('uemodal-change',function(){$(this).replaceWith(inner.children());});switch(type){case'html':tmp.html(selectedOpts.content);uemodal_process_inline();break;case'inline':$('<div class="ue-modal-inline-tmp" />').hide().insertBefore($(obj)).bind('uemodal-cleanup',function(){$(this).replaceWith(inner.children());}).bind('uemodal-cancel',function(){$(this).replaceWith(tmp.children());});$(obj).appendTo(tmp);uemodal_process_inline();break;case'image':busy=false;$.uemodal.showActivity();imgPreloader=new Image;imgPreloader.onerror=function(){uemodal_error();}
imgPreloader.onload=function(){imgPreloader.onerror=null;imgPreloader.onload=null;uemodal_process_image();}
imgPreloader.src=href;break;case'swf':var str='';var emb='';str+='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+selectedOpts.width+'" height="'+selectedOpts.height+'"><param name="movie" value="'+href+'"></param>';$.each(selectedOpts.swf,function(name,val){str+='<param name="'+name+'" value="'+val+'"></param>';emb+=' '+name+'="'+val+'"';});str+='<embed src="'+href+'" type="application/x-shockwave-flash" width="'+selectedOpts.width+'" height="'+selectedOpts.height+'"'+emb+'></embed></object>';tmp.html(str);uemodal_process_inline();break;case'ajax':var selector=href.split('#',2);var data=selectedOpts.ajax.data||{};if(selector.length>1){href=selector[0];typeof data=="string"?data+='&selector='+selector[1]:data['selector']=selector[1];}
busy=false;$.uemodal.showActivity();ajaxLoader=$.ajax($.extend(selectedOpts.ajax,{url:href,data:data,error:uemodal_error,success:function(data,textStatus,XMLHttpRequest){if(ajaxLoader.status==200){tmp.html(data);uemodal_process_inline();}}}));break;case'iframe':$('<iframe id="ue-modal-frame" name="uemodal-frame'+new Date().getTime()+'" frameborder="0" hspace="0" scrolling="'+selectedOpts.scrolling+'" src="'+selectedOpts.href+'"></iframe>').appendTo(tmp);uemodal_show();break;}};function uemodal_process_image(){busy=true;selectedOpts.width=imgPreloader.width;selectedOpts.height=imgPreloader.height;$("<img />").attr({'id':'ue-modal-img','src':imgPreloader.src,'alt':selectedOpts.title}).appendTo(tmp);uemodal_show();};function uemodal_process_inline(){tmp.width(selectedOpts.width);tmp.height(selectedOpts.height);if(selectedOpts.width=='auto')selectedOpts.width=tmp.width();if(selectedOpts.height=='auto')selectedOpts.height=tmp.height();uemodal_show();};function uemodal_show(){loading.hide();if(wrap.is(":visible")&&$.isFunction(currentOpts.onCleanup)){if(currentOpts.onCleanup(currentArray,currentIndex,currentOpts)===false){$.event.trigger('uemodal-cancel');busy=false;return;}};currentArray=selectedArray;currentIndex=selectedIndex;currentOpts=selectedOpts;inner.get(0).scrollTop=0;inner.get(0).scrollLeft=0;if(currentOpts.overlayShow){if(isIE6){$('select:not(#ue-modal-tmp select)').filter(function(){return this.style.visibility!=='hidden';}).css({'visibility':'hidden'}).one('uemodal-cleanup',function(){this.style.visibility='inherit';});}
overlay.css({'background-color':currentOpts.overlayColor,'opacity':currentOpts.overlayOpacity}).unbind().show();}
final_pos=uemodal_get_zoom_to();uemodal_process_title();if(wrap.is(":visible")){$(close.add(nav_left).add(nav_right)).hide();var pos=wrap.position();start_pos={top:pos.top,left:pos.left,width:wrap.width(),height:wrap.height()};var equal=(start_pos.width==final_pos.width&&start_pos.height==final_pos.height);inner.fadeOut(currentOpts.changeFade,function(){$.event.trigger('uemodal-change');inner.css({top:currentOpts.padding,left:currentOpts.padding,width:Math.max(start_pos.width-(currentOpts.padding*2),1),height:Math.max(start_pos.height-(currentOpts.padding*2),1)}).empty().css('overflow','hidden');function finish_resizing(){inner.html(tmp.contents()).fadeIn(currentOpts.changeFade,_finish);}
fx.prop=0;$(fx).animate({prop:1},{duration:equal?0:currentOpts.changeSpeed,easing:currentOpts.easingChange,step:uemodal_draw,complete:finish_resizing});});return;}
wrap.css('opacity',1);if(currentOpts.transitionIn=='elastic'){start_pos=uemodal_get_zoom_from();inner.css({top:currentOpts.padding,left:currentOpts.padding,width:Math.max(start_pos.width-(currentOpts.padding*2),1),height:Math.max(start_pos.height-(currentOpts.padding*2),1)}).html(tmp.contents());wrap.css(start_pos).show();if(currentOpts.opacity)final_pos.opacity=0;fx.prop=0;$(fx).animate({prop:1},{duration:currentOpts.speedIn,easing:currentOpts.easingIn,step:uemodal_draw,complete:_finish});}else{inner.css({top:currentOpts.padding,left:currentOpts.padding,width:Math.max(final_pos.width-(currentOpts.padding*2),1),height:Math.max(final_pos.height-(currentOpts.padding*2)-titleh,1)}).html(tmp.contents());wrap.css(final_pos).fadeIn(currentOpts.transitionIn=='none'?0:currentOpts.speedIn,_finish);}};function uemodal_draw(pos){var width=Math.round(start_pos.width+(final_pos.width-start_pos.width)*pos);var height=Math.round(start_pos.height+(final_pos.height-start_pos.height)*pos);var top=Math.round(start_pos.top+(final_pos.top-start_pos.top)*pos);var left=Math.round(start_pos.left+(final_pos.left-start_pos.left)*pos);wrap.css({'width':width+'px','height':height+'px','top':top+'px','left':left+'px'});width=Math.max(width-currentOpts.padding*2,0);height=Math.max(height-(currentOpts.padding*2+(titleh*pos)),0);inner.css({'width':width+'px','height':height+'px'});if(typeof final_pos.opacity!=='undefined')wrap.css('opacity',(pos<0.5?0.5:pos));};function _finish(){inner.css('overflow',overflow=(currentOpts.scrolling=='auto'?(currentOpts.type=='image'||currentOpts.type=='iframe'||currentOpts.type=='swf'?'hidden':'auto'):(currentOpts.scrolling=='yes'?'auto':'visible')));if(!$.support.opacity){inner.get(0).style.removeAttribute('filter');wrap.get(0).style.removeAttribute('filter');}
$('#ue-modal-title').show();if(currentOpts.hideOnContentClick)inner.one('click',$.uemodal.close);if(currentOpts.hideOnOverlayClick)overlay.one('click',$.uemodal.close);if(currentOpts.showCloseButton)close.show();uemodal_set_navigation();$(window).bind("resize.fb",$.uemodal.center);currentOpts.centerOnScroll?$(window).bind("scroll.fb",$.uemodal.center):$(window).unbind("scroll.fb");if($.isFunction(currentOpts.onComplete))currentOpts.onComplete(currentArray,currentIndex,currentOpts);busy=false;uemodal_preload_images();};function uemodal_get_zoom_to(){var view=uemodal_get_viewport();var to={};var margin=currentOpts.margin;var resize=currentOpts.autoScale;var horizontal_space=(shadow+margin)*2;var vertical_space=(shadow+margin)*2;var double_padding=(currentOpts.padding*2);if(currentOpts.width.toString().indexOf('%')>-1){to.width=((view[0]*parseFloat(currentOpts.width))/100)-(shadow*2);resize=false;}else{to.width=currentOpts.width+double_padding;}
if(currentOpts.height.toString().indexOf('%')>-1){to.height=((view[1]*parseFloat(currentOpts.height))/100)-(shadow*2);resize=false;}else{to.height=currentOpts.height+double_padding;}
if(resize&&(to.width>(view[0]-horizontal_space)||to.height>(view[1]-vertical_space))){if(selectedOpts.type=='image'||selectedOpts.type=='swf'){horizontal_space+=double_padding;vertical_space+=double_padding;var ratio=Math.min(Math.min(view[0]-horizontal_space,currentOpts.width)/currentOpts.width,Math.min(view[1]-vertical_space,currentOpts.height)/currentOpts.height);to.width=Math.round(ratio*(to.width-double_padding))+double_padding;to.height=Math.round(ratio*(to.height-double_padding))+double_padding;}else{to.width=Math.min(to.width,(view[0]-horizontal_space));to.height=Math.min(to.height,(view[1]-vertical_space));}}
to.top=view[3]+((view[1]-(to.height+(shadow*2)))*0.5);to.left=view[2]+((view[0]-(to.width+(shadow*2)))*0.5);if(currentOpts.autoScale==false){to.top=Math.max(view[3]+margin,to.top);to.left=Math.max(view[2]+margin,to.left);}
return to;};function uemodal_get_zoom_from(){var orig=selectedOpts.orig?$(selectedOpts.orig):false;var from={};if(orig&&orig.length){var pos=uemodal_get_obj_pos(orig);from={width:(pos.width+(currentOpts.padding*2)),height:(pos.height+(currentOpts.padding*2)),top:(pos.top-currentOpts.padding-shadow),left:(pos.left-currentOpts.padding-shadow)};}else{var view=uemodal_get_viewport();from={width:1,height:1,top:view[3]+view[1]*0.5,left:view[2]+view[0]*0.5};}
return from;};function uemodal_set_navigation(){$(document).unbind('keydown.fb').bind('keydown.fb',function(e){if(e.keyCode==27&&currentOpts.enableEscapeButton){e.preventDefault();$.uemodal.close();}else if(e.keyCode==37){e.preventDefault();$.uemodal.prev();}else if(e.keyCode==39){e.preventDefault();$.uemodal.next();}});if($.fn.mousewheel){wrap.unbind('mousewheel.fb');if(currentArray.length>1){wrap.bind('mousewheel.fb',function(e,delta){e.preventDefault();if(busy||delta==0)return;delta>0?$.uemodal.prev():$.uemodal.next();});}}
if(!currentOpts.showNavArrows)return;if((currentOpts.cyclic&&currentArray.length>1)||currentIndex!=0){nav_left.show();}
if((currentOpts.cyclic&&currentArray.length>1)||currentIndex!=(currentArray.length-1)){nav_right.show();}};function uemodal_preload_images(){if((currentArray.length-1)>currentIndex){var href=currentArray[currentIndex+1].href;if(typeof href!=='undefined'&&href.match(imageRegExp)){var objNext=new Image();objNext.src=href;}}
if(currentIndex>0){var href=currentArray[currentIndex-1].href;if(typeof href!=='undefined'&&href.match(imageRegExp)){var objNext=new Image();objNext.src=href;}}};function uemodal_animate_loading(){if(!loading.is(':visible')){clearInterval(loadingTimer);return;}
$('div',loading).css('top',(loadingFrame*-40)+'px');loadingFrame=(loadingFrame+1)%12;};function uemodal_get_viewport(){return[$(window).width(),$(window).height(),$(document).scrollLeft(),$(document).scrollTop()];};function uemodal_get_obj_pos(obj){var pos=obj.offset();pos.top+=parseFloat(obj.css('paddingTop'))||0;pos.left+=parseFloat(obj.css('paddingLeft'))||0;pos.top+=parseFloat(obj.css('border-top-width'))||0;pos.left+=parseFloat(obj.css('border-left-width'))||0;pos.width=obj.width();pos.height=obj.height();return pos;};function uemodal_process_title(){$('#ue-modal-title').remove();titleh=0;if(currentOpts.titleShow==false)return;var obj=currentArray[currentIndex];var title=currentOpts.title;title=$.isFunction(currentOpts.titleFormat)?currentOpts.titleFormat(title,currentArray,currentIndex,currentOpts):uemodal_format_title(title);if(!title||title=='')return;var width=final_pos.width-(currentOpts.padding*2);var titlec='ue-modal-title-'+currentOpts.titlePosition;$('<div id="ue-modal-title" class="'+titlec+'" />').css({'width':width,'paddingLeft':currentOpts.padding,'paddingRight':currentOpts.padding}).html(title).appendTo('body');switch(currentOpts.titlePosition){case'inside':titleh=$("#ue-modal-title").outerHeight(true)-currentOpts.padding;final_pos.height+=titleh;break;case'over':$('#ue-modal-title').css('bottom',currentOpts.padding);break;default:$('#ue-modal-title').css('bottom',$("#uemodal-title").outerHeight(true)*-1);break;}
$('#ue-modal-title').appendTo(outer).hide();};function uemodal_format_title(title){if(title&&title.length){switch(currentOpts.titlePosition){case'inside':return title;break;case'over':return'<span id="ue-modal-title-over">'+title+'</span>';break;default:return'<span id="ue-modal-title-wrap"><span id="ue-modal-title-left"></span><span id="ue-modal-title-main">'+title+'</span><span id="ue-modal-title-right"></span></span>';break;}}
return false;};function uemodal_init(){if($("#uemodal-wrap").length)return;$('body').append(tmp=$('<div id="ue-modal-tmp"></div>'),loading=$('<div id="ue-modal-loading"><div> </div></div>'),overlay=$('<div id="ue-modal-overlay"> </div>'),wrap=$('<div id="ue-modal-wrap"></div>'));outer=$('<div id="ue-modal-outer"></div>').append('<div class="ue-modal-bg" id="ue-modal-bg-n"></div><div class="ue-modal-bg" id="ue-modal-bg-ne"></div><div class="ue-modal-bg" id="ue-modal-bg-e"></div><div class="ue-modal-bg" id="ue-modal-bg-se"></div><div class="ue-modal-bg" id="ue-modal-bg-s"></div><div class="ue-modal-bg" id="ue-modal-bg-sw"></div><div class="ue-modal-bg" id="ue-modal-bg-w"></div><div class="ue-modal-bg" id="ue-modal-bg-nw"></div>').appendTo(wrap);outer.append(inner=$('<div id="ue-modal-inner"></div>'),close=$('<a id="ue-modal-close">Close</a>'),nav_left=$('<a id="ue-modal-left"><span class="ue-modal-ico" id="ue-modal-left-ico"></span></a>'),nav_right=$('<a id="ue-modal-right"><span class="ue-modal-ico" id="ue-modal-right-ico"></span></a>'));close.click($.uemodal.close);loading.click($.uemodal.cancel);nav_left.click(function(e){e.preventDefault();$.uemodal.prev();});nav_right.click(function(e){e.preventDefault();$.uemodal.next();});};$.fn.uemodal.defaults={padding:8,margin:5,opacity:false,modal:false,cyclic:false,scrolling:'auto',width:960,height:500,autoScale:true,autoDimensions:true,centerOnScroll:false,ajax:{},swf:{wmode:'transparent'},hideOnOverlayClick:false,hideOnContentClick:false,overlayShow:false,overlayOpacity:0.45,overlayColor:'#000',titleShow:true,titlePosition:'over',titleFormat:null,transitionIn:'fade',transitionOut:'fade',speedIn:200,speedOut:200,changeSpeed:200,changeFade:'fast',easingIn:'swing',easingOut:'swing',showCloseButton:true,showNavArrows:false,enableEscapeButton:true,onStart:null,onCancel:null,onComplete:null,onCleanup:null,onClosed:null};$(document).ready(function(){uemodal_init();});})(jQuery);$(document).ready(function(){$("[rel*=uemodal]").uemodal();$("[rel*=modal-simple]").uemodal();});function uedialog(message,id){$("[rel*=uedialog-"+id+"]").uemodal({content:'<div id="ue-modal-dialog" class="ue-modal-alert"><p>'+message+'</p> <div id="ue-modal-footer"><button class="ue-modal-btn" onclick="$.uemodal.close()">Cancel</button><button class="ue-modal-btn" onclick="$.uemodal.close()">Duh!</button></div></div>',showCloseButton:false,enableEscapeButton:false,overlayShow:true,centerOnScroll:true});}
function uedialogAjax(src,id){$("[rel*=uedialog-"+id+"]").uemodal({type:'ajax',href:src,showCloseButton:false,enableEscapeButton:false,overlayShow:true,centerOnScroll:true});}