/**
 * ------------------------------------------------------------------
 * jQuery.ScrollTo
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 * ------------------------------------------------------------------
 * jQuery.tinycarousel
 * http://www.baijs.nl/tinycarousel/
 * ------------------------------------------------------------------
 * jQuery.ColorBox
 * http://colorpowered.com/colorbox/
 * ------------------------------------------------------------------
**/
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);(function($){$.fn.tinycarousel=function(options){var defaults={start:1,display:1,axis:'x',controls:true,pager:false,interval:false,intervaltime:3000,animation:true,duration:1000,callback:null};var options=$.extend(defaults,options);var oSlider=$(this);var oViewport=$('.viewport',oSlider);var oContent=$('.overview',oSlider);var oPages=oContent.children();var oBtnNext=$('.next',oSlider);var oBtnPrev=$('.prev',oSlider);var oPager=$('.pager',oSlider);var iPageSize,iSteps,iCurrent,oTimer,bForward=true,bAxis=options.axis=='x';return this.each(function(){initialize()});function initialize(){iPageSize=bAxis?$(oPages[0]).outerWidth(true):$(oPages[0]).outerHeight(true);var iLeftover=Math.ceil(((bAxis?oViewport.outerWidth():oViewport.outerHeight())/(iPageSize*options.display))-1);iSteps=Math.max(1,Math.ceil(oPages.length/options.display)-iLeftover);iCurrent=Math.min(iSteps,Math.max(1,options.start))-2;oContent.css(bAxis?'width':'height',(iPageSize*oPages.length));move(1);setEvents()}function setButtons(){if(options.controls){oBtnPrev.toggleClass('disable',!(iCurrent>0));oBtnNext.toggleClass('disable',!(iCurrent+1<iSteps))}}function setEvents(){if(options.controls&&oBtnPrev.length>0&&oBtnNext.length>0){oBtnPrev.click(function(){move(-1);return false});oBtnNext.click(function(){move(1);return false})}if(options.pager&&oPager.length>0){oPager.click(setPager)}}function setPager(oEvent){var oTarget=oEvent.target;if($(oTarget).hasClass('pagenum')){iCurrent=parseInt(oTarget.rel)-1;move(1)}return false}function setPagerActive(){if(options.pager){var oNumbers=$('.pagenum',oPager);oNumbers.removeClass('active');$(oNumbers[iCurrent]).addClass('active')}}function setTimer(bReset){if(options.interval&&!bReset){clearInterval(oTimer);oTimer=window.setInterval(function(){bForward=iCurrent+1==iSteps?false:iCurrent==0?true:bForward;move(bForward?1:-1,true)},options.intervaltime)}}function move(iDirection,bTimerReset){if(iCurrent+iDirection>-1&&iCurrent+iDirection<iSteps){iCurrent+=iDirection;var oPosition={};oPosition[bAxis?'left':'top']=-(iCurrent*(iPageSize*options.display));oContent.animate(oPosition,{queue:false,duration:options.animation?options.duration:0,complete:function(){if(typeof options.callback=='function')options.callback.call(this,oPages[iCurrent],iCurrent)}});setButtons();setPagerActive();setTimer(bTimerReset)}}}})(jQuery);(function($,window){var defaults={transition:"elastic",speed:300,width:false,initialWidth:"600",innerWidth:false,maxWidth:false,height:false,initialHeight:"450",innerHeight:false,maxHeight:false,scalePhotos:true,scrolling:true,inline:false,html:false,iframe:false,photo:false,href:false,title:false,rel:false,opacity:0.9,preloading:true,current:"image {current} of {total}",previous:"previous",next:"next",close:"close",open:false,loop:true,slideshow:false,slideshowAuto:true,slideshowSpeed:2500,slideshowStart:"start slideshow",slideshowStop:"stop slideshow",onOpen:false,onLoad:false,onComplete:false,onCleanup:false,onClosed:false,overlayClose:true,escKey:true,arrowKey:true},colorbox='colorbox',prefix='cbox',event_open=prefix+'_open',event_load=prefix+'_load',event_complete=prefix+'_complete',event_cleanup=prefix+'_cleanup',event_closed=prefix+'_closed',isIE=$.browser.msie&&!$.support.opacity,isIE6=isIE&&$.browser.version<7,event_ie6=prefix+'_IE6',$overlay,$box,$wrap,$content,$topBorder,$leftBorder,$rightBorder,$bottomBorder,$related,$window,$loaded,$loadingBay,$loadingOverlay,$title,$current,$slideshow,$next,$prev,$close,interfaceHeight,interfaceWidth,loadedHeight,loadedWidth,element,bookmark,index,settings,open,active,publicMethod,boxElement=prefix+'Element';function $div(id,css){id=id?' id="'+prefix+id+'"':'';css=css?' style="'+css+'"':'';return $('<div'+id+css+'/>')}function setSize(size,dimension){dimension=dimension==='x'?$window.width():$window.height();return(typeof size==='string')?Math.round((size.match(/%/)?(dimension/100)*parseInt(size,10):parseInt(size,10))):size}function isImage(url){url=$.isFunction(url)?url.call(element):url;return settings.photo||url.match(/\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i)}function process(){for(var i in settings){if($.isFunction(settings[i])&&i.substring(0,2)!=='on'){settings[i]=settings[i].call(element)}}settings.rel=settings.rel||element.rel||'nofollow';settings.href=settings.href||$(element).attr('href');settings.title=settings.title||element.title}function launch(elem){element=elem;settings=$.extend({},$(element).data(colorbox));process();if(settings.rel!=='nofollow'){$related=$('.'+boxElement).filter(function(){var relRelated=$(this).data(colorbox).rel||this.rel;return(relRelated===settings.rel)});index=$related.index(element);if(index===-1){$related=$related.add(element);index=$related.length-1}}else{$related=$(element);index=0}if(!open){open=active=true;bookmark=element;try{bookmark.blur()}catch(e){}$.event.trigger(event_open);if(settings.onOpen){settings.onOpen.call(element)}$overlay.css({"opacity":+settings.opacity,"cursor":settings.overlayClose?"pointer":"auto"}).show();settings.w=setSize(settings.initialWidth,'x');settings.h=setSize(settings.initialHeight,'y');publicMethod.position(0);if(isIE6){$window.bind('resize.'+event_ie6+' scroll.'+event_ie6,function(){$overlay.css({width:$window.width(),height:$window.height(),top:$window.scrollTop(),left:$window.scrollLeft()})}).trigger('scroll.'+event_ie6)}}$current.add($prev).add($next).add($slideshow).add($title).hide();$close.html(settings.close).show();publicMethod.slideshow();publicMethod.load()}publicMethod=$.fn[colorbox]=$[colorbox]=function(options,callback){var $this=this;if(!$this[0]&&$this.selector){return $this}options=options||{};if(callback){options.onComplete=callback}if(!$this[0]||$this.selector===undefined){$this=$('<a/>');options.open=true}$this.each(function(){$(this).data(colorbox,$.extend({},$(this).data(colorbox)||defaults,options)).addClass(boxElement)});if(options.open){launch($this[0])}return $this};publicMethod.init=function(){$window=$(window);$box=$div().attr({id:colorbox,'class':isIE?prefix+'IE':''});$overlay=$div("Overlay",isIE6?'position:absolute':'').hide();$wrap=$div("Wrapper");$content=$div("Content").append($loaded=$div("LoadedContent",'width:0; height:0'),$loadingOverlay=$div("LoadingOverlay").add($div("LoadingGraphic")),$title=$div("Title"),$current=$div("Current"),$next=$div("Next"),$prev=$div("Previous"),$slideshow=$div("Slideshow"),$close=$div("Close"));$wrap.append($div().append($div("TopLeft"),$topBorder=$div("TopCenter"),$div("TopRight")),$div().append($leftBorder=$div("MiddleLeft"),$content,$rightBorder=$div("MiddleRight")),$div().append($div("BottomLeft"),$bottomBorder=$div("BottomCenter"),$div("BottomRight"))).children().children().css({'float':'left'});$loadingBay=$div(false,'position:absolute; width:9999px; visibility:hidden; display:none');$('body').prepend($overlay,$box.append($wrap,$loadingBay));$content.children().hover(function(){$(this).addClass('hover')},function(){$(this).removeClass('hover')}).addClass('hover');interfaceHeight=$topBorder.height()+$bottomBorder.height()+$content.outerHeight(true)-$content.height();interfaceWidth=$leftBorder.width()+$rightBorder.width()+$content.outerWidth(true)-$content.width();loadedHeight=$loaded.outerHeight(true);loadedWidth=$loaded.outerWidth(true);$box.css({"padding-bottom":interfaceHeight,"padding-right":interfaceWidth}).hide();$next.click(publicMethod.next);$prev.click(publicMethod.prev);$close.click(publicMethod.close);$content.children().removeClass('hover');$('.'+boxElement).live('click',function(e){if((e.button!==0&&typeof e.button!=='undefined')||e.ctrlKey||e.shiftKey||e.altKey){return true}else{launch(this);return false}});$overlay.click(function(){if(settings.overlayClose){publicMethod.close()}});$(document).bind("keydown",function(e){if(open&&settings.escKey&&e.keyCode===27){e.preventDefault();publicMethod.close()}if(open&&settings.arrowKey&&!active&&$related[1]){if(e.keyCode===37&&(index||settings.loop)){e.preventDefault();$prev.click()}else if(e.keyCode===39&&(index<$related.length-1||settings.loop)){e.preventDefault();$next.click()}}})};publicMethod.remove=function(){$box.add($overlay).remove();$('.'+boxElement).die('click').removeData(colorbox).removeClass(boxElement)};publicMethod.position=function(speed,loadedCallback){var animate_speed,posTop=Math.max($window.height()-settings.h-loadedHeight-interfaceHeight,0)/2+$window.scrollTop(),posLeft=Math.max($window.width()-settings.w-loadedWidth-interfaceWidth,0)/2+$window.scrollLeft();animate_speed=($box.width()===settings.w+loadedWidth&&$box.height()===settings.h+loadedHeight)?0:speed;$wrap[0].style.width=$wrap[0].style.height="9999px";function modalDimensions(that){$topBorder[0].style.width=$bottomBorder[0].style.width=$content[0].style.width=that.style.width;$loadingOverlay[0].style.height=$loadingOverlay[1].style.height=$content[0].style.height=$leftBorder[0].style.height=$rightBorder[0].style.height=that.style.height}$box.dequeue().animate({width:settings.w+loadedWidth,height:settings.h+loadedHeight,top:posTop,left:posLeft},{duration:animate_speed,complete:function(){modalDimensions(this);active=false;$wrap[0].style.width=(settings.w+loadedWidth+interfaceWidth)+"px";$wrap[0].style.height=(settings.h+loadedHeight+interfaceHeight)+"px";if(loadedCallback){loadedCallback()}},step:function(){modalDimensions(this)}})};publicMethod.resize=function(options){if(open){options=options||{};if(options.width){settings.w=setSize(options.width,'x')-loadedWidth-interfaceWidth}if(options.innerWidth){settings.w=setSize(options.innerWidth,'x')}$loaded.css({width:settings.w});if(options.height){settings.h=setSize(options.height,'y')-loadedHeight-interfaceHeight}if(options.innerHeight){settings.h=setSize(options.innerHeight,'y')}if(!options.innerHeight&&!options.height){var $child=$loaded.wrapInner("<div style='overflow:auto'></div>").children();settings.h=$child.height();$child.replaceWith($child.children())}$loaded.css({height:settings.h});publicMethod.position(settings.transition==="none"?0:settings.speed)}};publicMethod.prep=function(object){if(!open){return}var photo,speed=settings.transition==="none"?0:settings.speed;$window.unbind('resize.'+prefix);$loaded.remove();$loaded=$div('LoadedContent').html(object);function getWidth(){settings.w=settings.w||$loaded.width();settings.w=settings.mw&&settings.mw<settings.w?settings.mw:settings.w;return settings.w}function getHeight(){settings.h=settings.h||$loaded.height();settings.h=settings.mh&&settings.mh<settings.h?settings.mh:settings.h;return settings.h}$loaded.hide().appendTo($loadingBay.show()).css({width:getWidth(),overflow:settings.scrolling?'auto':'hidden'}).css({height:getHeight()}).prependTo($content);$loadingBay.hide();$('#'+prefix+'Photo').css({cssFloat:'none'});if(isIE6){$('select').not($box.find('select')).filter(function(){return this.style.visibility!=='hidden'}).css({'visibility':'hidden'}).one(event_cleanup,function(){this.style.visibility='inherit'})}function setPosition(s){var prev,prevSrc,next,nextSrc,total=$related.length,loop=settings.loop;publicMethod.position(s,function(){function defilter(){if(isIE){$box[0].style.removeAttribute("filter")}}if(!open){return}if(isIE){if(photo){$loaded.fadeIn(100)}}if(settings.iframe){$("<iframe frameborder=0"+(settings.scrolling?"":" scrolling='no'")+(isIE?" allowtransparency='true'":'')+"/>").attr({src:settings.href,name:new Date().getTime()}).appendTo($loaded)}$loaded.show();$title.show().html(settings.title);if(total>1){$current.html(settings.current.replace(/\{current\}/,index+1).replace(/\{total\}/,total)).show();$next[(loop||index<total-1)?"show":"hide"]().html(settings.next);$prev[(loop||index)?"show":"hide"]().html(settings.previous);prev=index?$related[index-1]:$related[total-1];next=index<total-1?$related[index+1]:$related[0];if(settings.slideshow){$slideshow.show();if(index===total-1&&!loop&&$box.is('.'+prefix+'Slideshow_on')){$slideshow.click()}}if(settings.preloading){nextSrc=$(next).data(colorbox).href||next.href;prevSrc=$(prev).data(colorbox).href||prev.href;if(isImage(nextSrc)){$('<img/>')[0].src=nextSrc}if(isImage(prevSrc)){$('<img/>')[0].src=prevSrc}}}$loadingOverlay.hide();if(settings.transition==='fade'){$box.fadeTo(speed,1,function(){defilter()})}else{defilter()}$window.bind('resize.'+prefix,function(){publicMethod.position(0)});$.event.trigger(event_complete);if(settings.onComplete){settings.onComplete.call(element)}})}if(settings.transition==='fade'){$box.fadeTo(speed,0,function(){setPosition(0)})}else{setPosition(speed)}};publicMethod.load=function(){var href,img,setResize,prep=publicMethod.prep;active=true;element=$related[index];settings=$.extend({},$(element).data(colorbox));process();$.event.trigger(event_load);if(settings.onLoad){settings.onLoad.call(element)}settings.h=settings.height?setSize(settings.height,'y')-loadedHeight-interfaceHeight:settings.innerHeight&&setSize(settings.innerHeight,'y');settings.w=settings.width?setSize(settings.width,'x')-loadedWidth-interfaceWidth:settings.innerWidth&&setSize(settings.innerWidth,'x');settings.mw=settings.w;settings.mh=settings.h;if(settings.maxWidth){settings.mw=setSize(settings.maxWidth,'x')-loadedWidth-interfaceWidth;settings.mw=settings.w&&settings.w<settings.mw?settings.w:settings.mw}if(settings.maxHeight){settings.mh=setSize(settings.maxHeight,'y')-loadedHeight-interfaceHeight;settings.mh=settings.h&&settings.h<settings.mh?settings.h:settings.mh}href=settings.href;$loadingOverlay.show();if(settings.inline){$div('InlineTemp').hide().insertBefore($(href)[0]).bind(event_load+' '+event_cleanup,function(){$(this).replaceWith($loaded.children())});prep($(href))}else if(settings.iframe){prep(" ")}else if(settings.html){prep(settings.html)}else if(isImage(href)){img=new Image();img.onload=function(){var percent;img.onload=null;img.id=prefix+'Photo';$(img).css({margin:'auto',border:'none',display:'block',cssFloat:'left'});if(settings.scalePhotos){setResize=function(){img.height-=img.height*percent;img.width-=img.width*percent};if(settings.mw&&img.width>settings.mw){percent=(img.width-settings.mw)/img.width;setResize()}if(settings.mh&&img.height>settings.mh){percent=(img.height-settings.mh)/img.height;setResize()}}if(settings.h){img.style.marginTop=Math.max(settings.h-img.height,0)/2+'px'}setTimeout(function(){prep(img)},1);if($related[1]&&(index<$related.length-1||settings.loop)){$(img).css({cursor:'pointer'}).click(publicMethod.next)}if(isIE){img.style.msInterpolationMode='bicubic'}};img.src=href}else{$div().appendTo($loadingBay).load(href,function(data,status,xhr){prep(status==='error'?'Request unsuccessful: '+xhr.statusText:this)})}};publicMethod.next=function(){if(!active){index=index<$related.length-1?index+1:0;publicMethod.load()}};publicMethod.prev=function(){if(!active){index=index?index-1:$related.length-1;publicMethod.load()}};publicMethod.slideshow=function(){var stop,timeOut,className=prefix+'Slideshow_';$slideshow.bind(event_closed,function(){$slideshow.unbind();clearTimeout(timeOut);$box.removeClass(className+"off "+className+"on")});function start(){$slideshow.text(settings.slideshowStop).bind(event_complete,function(){timeOut=setTimeout(publicMethod.next,settings.slideshowSpeed)}).bind(event_load,function(){clearTimeout(timeOut)}).one("click",function(){stop()});$box.removeClass(className+"off").addClass(className+"on")}stop=function(){clearTimeout(timeOut);$slideshow.text(settings.slideshowStart).unbind(event_complete+' '+event_load).one("click",function(){start();timeOut=setTimeout(publicMethod.next,settings.slideshowSpeed)});$box.removeClass(className+"on").addClass(className+"off")};if(settings.slideshow&&$related[1]){if(settings.slideshowAuto){start()}else{stop()}}};publicMethod.close=function(){if(open){open=false;$.event.trigger(event_cleanup);if(settings.onCleanup){settings.onCleanup.call(element)}$window.unbind('.'+prefix+' .'+event_ie6);$overlay.fadeTo('fast',0);$box.stop().fadeTo('fast',0,function(){$box.find('iframe').attr('src','about:blank');$loaded.remove();$box.add($overlay).css({'opacity':1,cursor:'auto'}).hide();try{bookmark.focus()}catch(e){}setTimeout(function(){$.event.trigger(event_closed);if(settings.onClosed){settings.onClosed.call(element)}},1)})}};publicMethod.element=function(){return $(element)};publicMethod.settings=defaults;$(publicMethod.init)}(jQuery,this));




/**
 * ------------------------------------------------------------------
 * Use this tool to unpack it:
 *  http://jsbeautifier.org/
 * Use this tool pack it back:
 *  http://dean.edwards.name/packer/
 * ------------------------------------------------------------------
 * REMEMBER: Don't copy, just learn :) Good luck :D
 * ------------------------------------------------------------------
 * (C) 2009 Manmohanjit Singh. blah blah blah
 * ------------------------------------------------------------------
**/
function validEmail(email) {
	// Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
	return /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(email);
}
function validURL(url) {
	// Scott Gonzalez: http://projects.scottsplayground.com/iri/
	return /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(url);
}
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


$(document).ready(function(){
	var	site_url = $('div#js-details input#df_site_url').val(),
		template_url = $('div#js-details input#df_template_url').val(),
		logged_in = $('div#js-details input#df_logged_in').val(),
		post_url = $('div#js-details input#df_post_url').val(),
		post_title = $('div#js-details input#df_post_title').val(),
		thread_comments = $('div#js-details input#df_thread_comments').val(),
		thread_comments_depth = $('div#js-details input#df_thread_comments_depth').val(),
		comments_per_page = $('div#js-details input#df_comments_per_page').val(),
		admin_url = $('div#js-details input#df_admin_url').val(),
		comment_order = $('div#js-details input#df_comment_order').val(),
		current_user_can_moderate_comments = $('div#js-details input#df_current_user_can_moderate_comments').val();

	$('.picasa-album').each(function(index, slider) {
		$(this).children('div.viewport').children('ul.overview').children('li').hover(function() {
			$(this).children('a.picasa-image-link').stop(true, true).css('display', 'none').slideDown();
		}, function() {
			$(this).children('a.picasa-image-link').stop(true, true).css('display', 'block').slideUp();
		});

		$(this).tinycarousel({ display: 4 });

		$(this).children('div.viewport').children('ul.overview').children('li').children('a.direct-image-link').colorbox({transition:"fade",opacity:'.6'});

	});



	$('ul.social-icons li a').hover(function() {
		$(this).stop(true,true).css('opacity', '.75').css('margin-top', '0').animate({ marginTop: "-5px"}, '500').fadeTo('250', '1');
	},function() {
		$(this).stop(true,true).css('opacity', '1').css('margin-top', '-5px').animate({ marginTop: "0px"}, '500').fadeTo('500', '.75');
	});
	$.getJSON(
		"http://twitter.com/status/user_timeline/manmohanjit.json?count=5&callback=?",
		function(data){
			$('ul#twitter-tweets').html('').hide();
			$.each(
				data,
				function(i, item) {
					var tweet =
						item.text
							.replace(/(https?:\/\/[-a-z0-9._~:\/?#@!$&\'()*+,;=%]+)/ig,'<a href="$1">$1</a>')
							.replace(/@+([_A-Za-z0-9-]+)/ig, '<a href="http://twitter.com/$1">@$1</a>')
							.replace(/#+([_A-Za-z0-9-]+)/ig, '<a href="http://search.twitter.com/search?q=$1">#$1</a>')
					;
					$('<li></li>').html(tweet).appendTo('ul#twitter-tweets');
				}
			);
                        $('ul#twitter-tweets').slideDown();
		}
	);
	$.getJSON(
		"http://twitter.com/status/user_timeline/mynowplaying.json?count=5&callback=?",
		function(data){
			$('ul#twitter-music').html('').hide();
			$.each(
				data,
				function(i, item) {
					var tweet =
						item.text
							.replace(/(https?:\/\/[-a-z0-9._~:\/?#@!$&\'()*+,;=%]+)/ig,'<a href="$1">$1</a>')
							.replace(/@+([_A-Za-z0-9-]+)/ig, '<a href="http://twitter.com/$1">@$1</a>')
							.replace('#nowplaying ', '')
					;
					$('<li></li>').html(tweet).appendTo('ul#twitter-music');
				}
			);
                        $('ul#twitter-music').slideDown();
		}
	);

	$('#content #main .article .entry table tr:odd').css('background', '#f2f2f2');
	$('#content #main .article .entry pre').hover(function() {
		$(this).stop(true, true).animate({width: '110%'}).css('overflow-x', 'visible');
	},function() {
		$(this).animate({width: '100%'}).css('overflow-x', 'visible');
	});
	if($.browser.msie && parseInt($.browser.version) < 7) {
		$('#navigation ul li ul').hide();
	}
	else {
		$('#navigation > ul > li').hover(function() {
			$('ul', this).stop(true,true).hide().slideDown('slow');
		},function(){
			$('ul', this).stop(true,true).slideUp('normal').hide();
		});
	}
	$('.searchform p input').focus(function() {
		$(this).parent().addClass('focus');
	}).blur(function() {
		$(this).parent().removeClass('focus');
	}).hover(function() {
		$(this).parent().addClass('hover');
	},function() {
		$(this).parent().removeClass('hover');
	});
	$('form.searchform p input.search-submit').live('click', function() {
		if($('input.search-input', $(this).parent()).val() == "") {
			$('input.search-input', $(this).parent()).focus();
			return false;
		}
	});
	$('form#emailMe_form p input#emailMe_submit').live('click', function(event) {
		var form = $(this).parent().parent(), input = form.children('p'), contact = [];
		contact['name']		= input.children('input#emailMe_fullname');
		contact['email']	= input.children('input#emailMe_email');
		contact['url']		= input.children('input#emailMe_url');
		contact['title']	= input.children('input#emailMe_title');
		contact['data']		= input.children('textarea#emailMe_message');
		contact['post-id']	= input.children('input#emailMe_postid');
		contact['submit']	= input.children('input#emailMe_submit');
		if($.trim(contact['name'].val()).length < 3) {
			contact['name'].stop('true', 'true').focus();
		}
		else if($.trim(contact['email'].val()).length < 3 || !validEmail(contact['email'].val())) {
			contact['email'].stop('true', 'true').focus();
		}
		else if($.trim(contact['title'].val()).length < 3) {
			contact['title'].stop('true', 'true').focus();
		}
		else if($.trim(contact['data'].val()).length < 7) {
			contact['data'].stop('true', 'true').focus();
		}
		else if(contact['post-id'].val() == '') {
			alert('No Post ID!');
		}
		else {
			$.ajax({
				url: form.attr('action'),
				type: 'post',
				data: form.serialize()+'&emailMe_submit=true&ajax=true',
				dataType: 'json',
				beforeSend: function() {
					contact['submit'].attr('disabled', 'disabled');
				},
				error: function(XMLHttpRequest, textStatus, errorThrown) {
					$('div#emailMe_ajaxMessage').hide().html('<div class="error-note"><p>Error while sending the email!</p></div>').slideDown();
					contact['submit'].attr('disabled', '');
				},
				success: function(data, textStatus, XMLHttpRequest) {
					if(data.posted == 'true') {
						form.slideUp();
						$('div#emailMe_ajaxMessage').hide().html('<div class="info-note"><p>Thank you '+data.details.fullname+'! Your email has been sent.</p></div>').slideDown();
					}
					else {
						$('div#emailMe_ajaxMessage').hide().html('<div class="error-note"><p>Please try again later.</p></div>').slideDown();
						contact['submit'].attr('disabled', '');
					}
				}
			});
		}
		return false;
	});

	$('div#respond form p input#submit').live('click', function(event) {
		var commentsList = $('#comments-list'), form = $(this).parent().parent(), input = form.children('p'), comment = [], error = 0;
		comment['name']			= input.children('input#author');
		comment['email']		= input.children('input#email');
		comment['url']			= input.children('input#url');
		comment['data']			= input.children('textarea#comment');
		comment['comment_parent']	= input.children('input#comment_parent');
		comment['submit']		= input.children('input#submit');
		if(logged_in != 1) {
			if($.trim(comment['name'].val()).length < 3) {
				comment['name'].stop('true', 'true').focus();
				return false;
			}
			if($.trim(comment['email'].val()).length < 3 || !validEmail(comment['email'].val())) {
				comment['email'].stop('true', 'true').focus();
				return false;
			}
			if($.trim(comment['data'].val()).length < 7) {
				comment['data'].stop('true', 'true').focus();
				return false;
			}
		}
		if($.trim(comment['data'].val()).length < 7) {
			comment['data'].stop('true', 'true').focus();
			return false;
		}
		$.ajax({
			url: form.attr('action'),
			type: 'post',
			data: form.serialize()+'&ajax=true',
			dataType: 'json',
			beforeSend: function() {
				comment['submit'].attr('disabled', 'disabled');
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				$('div#comments-ajax-message').hide().html('<div class="error-note"><p>Error while posting your comment!</p></div>').slideDown();
				comment['submit'].attr('disabled', '');
			},
			success: function(data, textStatus, XMLHttpRequest) {
				if(data.posted == 'true') {
					$('#comments-ajax-message').hide().html('<div class="info-note"><p>'+data.message+'</p></div>').slideDown();
					//if(data.comment_approved == 1) {
						var theAuthor = '';
						var theComment = '';
						theComment += '<li class="comment hidden" id="comment-'+data.comment_ID+'">';
						theComment += '	<input type="hidden" class="comment-author-details-name" value="'+data.comment_author+'" />';
						theComment += '	<input type="hidden" class="comment-id" value="'+data.comment_ID+'" />';
						theComment += '	<div class="comment-details">';
						theComment += '		'+data.gravatar+'';
						theComment += '		<div class="comment-meta">';
						if(data.comment_author_url == "") {
							theComment += '			<p>By '+data.comment_author;
						}
						else {
							theComment += '			<p>By <a href="'+data.comment_author_url+'">'+data.comment_author+'</a>';
						}
						if(data.comment_approved != 1) {
							theComment += ' <em>[Pending]</em></p>';
						}
						else {
							theComment += '</p>';
						}
						theComment += '			<p>'+data.formatted_date+'</p>';
						theComment += '		</div>';
						theComment += '		<div class="clear"></div>';
						theComment += '	</div>';
						theComment += '	<div class="comment-actions">';
						theComment += '		<p class="reply-to normal"><a href="'+data.reply_to+'#respond">Reply</a></p>';
						if(logged_in == 1) {
							theComment += '		<p class="edit-comment normal"><a href="'+admin_url+'comment.php?action=editcomment&amp;c='+data.comment_ID+'">Edit</a></p>';
							theComment += '		<p class="delete-comment normal"><a href="'+admin_url+'comment.php?action=cdc&amp;c='+data.comment_ID+'">Delete</a></p>';
						}
						theComment += '	</div>';
						theComment += '	<div class="clear"></div>';
						theComment += '	<div class="comment-text">'+data.comment_content+'</div>';
						theComment += '</li>';
						commentsList.children('li').children('h3#no-comments').hide().parent().remove();
						if(data.comment_parent != 0 && thread_comments == 1) {
							if(data.depth > thread_comments_depth) {
								$('#comment-'+data.comment_parent).parent().append(theComment);
							}
							else {
								$('#comment-'+data.comment_parent).append('<ul class="children">'+theComment+'</ul>');
							}
							$('#comment-'+data.comment_ID).show();
							$(window).scrollTo('#comment-'+data.comment_ID, 2500, function() {
								$('#comment-'+data.comment_ID).effect("highlight", {mode:'show', color:'#bee0ff'}, 3000);
							});
						}
						else {
							if(comment_order == 'asc') {
								commentsList.append(theComment);
							}
							else {
								commentsList.prepend(theComment);
							}
							$('#comment-'+data.comment_ID).show("fold", {}, 500, function() {
								$(window).scrollTo('#comment-'+data.comment_ID, 2500, function() {
									$('#comment-'+data.comment_ID).effect("highlight", {mode:'show', color:'#bee0ff'}, 3000);
								});
							});
						}
					//}
					input.children('#wait-for-15').fadeIn();
					var theInterval = setInterval(
						function() {
							var curSecHTML = input.children('#wait-for-15').children('span').html();
							input.children('#wait-for-15').children('span').html(parseInt(curSecHTML) - 1);
						},1000
					);
					comment['data'].val('');
					setTimeout(
						function() {
							comment['submit'].attr('disabled', '');
							input.children('#wait-for-15').fadeOut(function() { $('span', this).html('15'); });
							clearInterval(theInterval); 
							$('#comments-ajax-message').slideUp().html('');
						},
						15000
					);
				}
				else {
					comment['submit'].attr('disabled', '');
					if(data.message != "") {
						$('#comments-ajax-message').html('<div class="error-note"><p>'+data.message+'</p></div>').slideDown();
					}
					else {
						$('#comments-ajax-message').html('<div class="error-note"><p>Error while posting your comment!</p></div>').slideDown();
					}
				}
				$('#comments #respond h2.comments-heading-title.post-a-comment-title a.undo-reply-to').parent().html('Leave A Comment').parent().children('form').children('p').children('input#comment_parent').val('');
			}
		});
		return false;
	});
	$('#comments #comments-list li.comment p.reply-to a').live('click', function(event) {
		var comment_id = $(this).parent().parent().parent().children('.comment-id').val();
		$.ajax({
			url: site_url+'/index.php',
			type: 'post',
			data: 'ajax=true&do=getcomment&format=true&id='+comment_id,
			dataType: 'json',
			success: function(data) {
				if(data.error == 'no') {
					$('#comments #respond h2.comments-heading-title.post-a-comment-title').html('Reply to <a href="#comment-'+data.comment_ID+'">'+data.comment_author+'</a> (<a href="'+post_url+'" class="undo-reply-to">Cancel</a>)').parent().children('form').children('p').children('input#comment_parent').val(data.comment_ID);
					$(window).scrollTo('#respond', 2500);
				}
				else {
					alert(data.error_text);
				}
			}
		});
		return false;
	});
	$('#comments #respond h2.comments-heading-title.post-a-comment-title a.undo-reply-to').live('click', function(event) {
		$('#comments #respond h2.comments-heading-title.post-a-comment-title a.undo-reply-to').parent().html('Leave A Comment').parent().children('form').children('p').children('input#comment_parent').val('');
		return false;
	});
	if(logged_in == 1 && current_user_can_moderate_comments == 1) {
		$('#comments #comments-list li.comment p.edit-comment a').live('click', function(event) {
			var comment = $(this).parent().parent().parent();
			var comment_id = $(this).parent().parent().parent().children('.comment-id').val();
			$.ajax({
				url: site_url+'/index.php',
				type: 'post',
				data: 'ajax=true&do=getcomment&id='+comment_id,
				dataType: 'json',
				success: function(data) {
					if(data.error == 'no') {
						var form_template = '';
						form_template += '<form action="'+site_url+'/index.php" method="post">';
						form_template += '	<p>';
						form_template += '		<textarea class="span-17" rows="5" cols="64">'+data.comment_content+'</textarea>';
						form_template += '	</p>';
						form_template += '	<p>';
						form_template += '		<input type="submit" name="update_comment" class="update-comment" value="Update Comment" />';
						form_template += '		<input type="submit" name="cancel-update" class="cancel-update" value="Cancel" />';
						form_template += '	</p>';
						form_template += '</form>';
						comment.children('.comment-text').html(form_template).children('form').fadeIn();
					}
					else {
						alert(data.error_text);
					}
				}
			});
			return false;
		});
		$('#comments #comments-list li.comment div.comment-text form p .cancel-update').live('click', function(event) {
			var comment = $(this).parent().parent().parent().parent();
			var comment_id = $(this).parent().parent().parent().parent().children('.comment-id').val();
			$.ajax({
				url: site_url+'/index.php',
				type: 'post',
				data: 'ajax=true&do=getcomment&id='+comment_id+'&format=true',
				dataType: 'json',
				success: function(data) {
					if(data.error == 'no') {
						comment.children('.comment-text').html(data.comment_content);
					}
					else {
						comment.fadeOut().remove();
						alert(data.error_text);
					}
				}
			});
			return false;
		});
		$('#comments #comments-list li.comment div.comment-text form p .update-comment').live('click', function(event) {
			var error = 0;
			var comment = $(this).parent().parent().parent().parent();
			var comment_id = $(this).parent().parent().parent().parent().children('.comment-id').val();
			var update_form = comment.children('.comment-text').children('form');
			if($.trim(update_form.children('p').children('textarea').val()).length < 7) {
				update_form.children('p').children('textarea').focus();
				error = 1;
			}
			if(error != 1) {
				$.ajax({
					url: site_url+'/index.php',
					type: 'post',
					data: 'ajax=true&do=updatecomment&id='+comment_id+'&format=true&comment_content='+update_form.children('p').children('textarea').val(),
					dataType: 'json',
					success: function(data) {
						if(data.error == 'no') {
							comment.children('.comment-text').html(data.comment_content).parent().effect("highlight", {mode:'show', color:'#bee0ff'}, 3000);;
						}
						else {
							comment.fadeOut().remove();
							alert(data.error_text);
						}
					}
				});
			}
			return false;
		});
	}
	$('#ajax-load').ajaxStart(function(){
		$(this).stop(true, true).fadeIn();
	}).ajaxComplete(function(){
		$(this).fadeOut();
	});
	if(logged_in == 1) {
		var keys = [];
		$(this).keydown(function(e) {
			keys.push(e.keyCode);
			if(keys.toString().indexOf('79,80,69,78') >= 0 && readCookie('admin-menu') != 'open'){
				$('#admin-background').fadeIn();

				$('#admin-slider a').html('&larr; Close').animate({ left: '60px' });
				$('#admin-menu').stop(true, true).css('left', '97%').animate({left: '20%'});
				$('#admin-comments').animate({left: '-2px'});
				$('#admin-server').animate({top: '-3px'});
				createCookie('admin-menu', 'open', 365);
				keys = [];
			}
			else if(keys.toString().indexOf('67,76,79,83,69') >= 0 && readCookie('admin-menu') != 'close'){
				$('#admin-background').fadeOut();

				$('#admin-slider a').html('Open &rarr;').animate({ left: '0px' });
				$('#admin-menu').animate({left: '97%'});
				$('#admin-comments').animate({left: '-425px'});
				$('#admin-server').animate({top: '-89px'});
				createCookie('admin-menu', 'close', 365)
				keys = [];
			}
		});
		if(readCookie('admin-menu') == 'open') {
			$('#admin-background').css('display', 'block');

			$('#admin-slider a').html('&larr; Close').css({ left: '60px' });
			$('#admin-menu').css({left: '20%'});
			$('#admin-comments').css({left: '-2px'});
			$('#admin-server').css({top: '-3px'});
		}
		else if(readCookie('admin-menu') == 'close') {
			$('#admin-background').css('display', 'none');

			$('#admin-slider a').html('Open &rarr;').css({ left: '0px' });
			$('#admin-menu').css({left: '97%'});
			$('#admin-comments').css({left: '-425px'});
			$('#admin-server').css({top: '-89px'});
		}
		$('#admin-background').click(function(event) {
			if(readCookie('admin-menu') == 'open') {
				$('#admin-background').fadeOut();

				$('#admin-slider a').html('Open &rarr;').animate({ left: 0 });
				$('#admin-menu').animate({left: '97%'});
				$('#admin-comments').animate({left: '-425px'});
				$('#admin-server').animate({top: '-89px'});
				createCookie('admin-menu', 'close', 365)
			}
		});
		$('#admin-slider a').draggable({ axis: 'x', containment: 'parent', stop: function(event, ui) {
			if(ui.position.left == 60  && readCookie('admin-menu') != 'open') {
				$('#admin-background').fadeIn();

				$('#admin-slider a').html('&larr; Close');
				$('#admin-menu').stop(true, true).css('left', '97%').animate({left: '20%'});
				$('#admin-comments').animate({left: '-2px'});
				$('#admin-server').animate({top: '-3px'});
				createCookie('admin-menu', 'open', 365);
			}
			else if(ui.position.left == 0  && readCookie('admin-menu') != 'close') {
				$('#admin-background').fadeOut();

				$('#admin-slider a').html('Open &rarr;');
				$('#admin-menu').animate({left: '97%'});
				$('#admin-comments').animate({left: '-425px'});
				$('#admin-server').animate({top: '-89px'});
				createCookie('admin-menu', 'close', 365)
			}
			else {
				if(readCookie('admin-menu') == 'open') {
					$('#admin-slider a').animate({ left: '60px' });
				}
				else {
					$('#admin-slider a').animate({ left: 0 });
				}
			}
		}}).click(function(event) {
			if(readCookie('admin-menu') == 'open') {
				$('#admin-slider a').animate({ left: 0 });

				$('#admin-background').fadeOut();

				$('#admin-slider a').html('Open &rarr;');
				$('#admin-menu').animate({left: '97%'});
				$('#admin-comments').animate({left: '-425px'});
				$('#admin-server').animate({top: '-89px'});
				createCookie('admin-menu', 'close', 365)
			}
			else {
				$('#admin-slider a').animate({ left: '60px' });

				$('#admin-background').fadeIn();

				$('#admin-slider a').html('&larr; Close');
				$('#admin-menu').stop(true, true).css('left', '97%').animate({left: '20%'});
				$('#admin-comments').animate({left: '-2px'});
				$('#admin-server').animate({top: '-3px'});
				createCookie('admin-menu', 'open', 365);
			}
			return false;
		});
	}
});