//LOCAL SCROLL SCRIPT
/**
 * jQuery.LocalScroll - Animated scrolling navigation, using anchors.
 * Copyright (c) 2007-2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 6/3/2008
 * @author Ariel Flesler
 * @version 1.2.6
 **/
;(function($){var g=location.href.replace(/#.*/,''),h=$.localScroll=function(a){$('body').localScroll(a)};h.defaults={duration:1e3,axis:'y',event:'click',stop:1};h.hash=function(a){a=$.extend({},h.defaults,a);a.hash=0;if(location.hash)setTimeout(function(){i(0,location,a)},0)};$.fn.localScroll=function(b){b=$.extend({},h.defaults,b);return(b.persistent||b.lazy)?this.bind(b.event,function(e){var a=$([e.target,e.target.parentNode]).filter(c)[0];a&&i(e,a,b)}):this.find('a,area').filter(c).bind(b.event,function(e){i(e,this,b)}).end().end();function c(){var a=this;return!!a.href&&!!a.hash&&a.href.replace(a.hash,'')==g&&(!b.filter||$(a).is(b.filter))}};function i(e,a,b){var c=a.hash.slice(1),d=document.getElementById(c)||document.getElementsByName(c)[0],f;if(d){e&&e.preventDefault();f=$(b.target||$.scrollTo.window());if(b.lock&&f.is(':animated')||b.onBefore&&b.onBefore.call(a,e,d,f)===!1)return;if(b.stop)f.queue('fx',[]).stop();f.scrollTo(d,b).trigger('notify.serialScroll',[d]);if(b.hash)f.queue(function(){location=a.hash;$(this).dequeue()})}}})(jQuery);

//SCROLL TO SCRIPT
/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Date: 2/19/2008
 * @author Ariel Flesler
 * @version 1.3.3
 */
;(function($){var o=$.scrollTo=function(a,b,c){o.window().scrollTo(a,b,c)};o.defaults={axis:'y',duration:1};o.window=function(){return $($.browser.safari?'body':'html')};$.fn.scrollTo=function(l,m,n){if(typeof m=='object'){n=m;m=0}n=$.extend({},o.defaults,n);m=m||n.speed||n.duration;n.queue=n.queue&&n.axis.length>1;if(n.queue)m/=2;n.offset=j(n.offset);n.over=j(n.over);return this.each(function(){var a=this,b=$(a),t=l,c,d={},w=b.is('html,body');switch(typeof t){case'number':case'string':if(/^([+-]=)?\d+(px)?$/.test(t)){t=j(t);break}t=$(t,this);case'object':if(t.is||t.style)c=(t=$(t)).offset()}$.each(n.axis.split(''),function(i,f){var P=f=='x'?'Left':'Top',p=P.toLowerCase(),k='scroll'+P,e=a[k],D=f=='x'?'Width':'Height';if(c){d[k]=c[p]+(w?0:e-b.offset()[p]);if(n.margin){d[k]-=parseInt(t.css('margin'+P))||0;d[k]-=parseInt(t.css('border'+P+'Width'))||0}d[k]+=n.offset[p]||0;if(n.over[p])d[k]+=t[D.toLowerCase()]()*n.over[p]}else d[k]=t[p];if(/^\d+$/.test(d[k]))d[k]=d[k]<=0?0:Math.min(d[k],h(D));if(!i&&n.queue){if(e!=d[k])g(n.onAfterFirst);delete d[k]}});g(n.onAfter);function g(a){b.animate(d,m,n.easing,a&&function(){a.call(this,l)})};function h(D){var b=w?$.browser.opera?document.body:document.documentElement:a;return b['scroll'+D]-b['client'+D]}})};function j(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);

/*GENERAL BOOKMARK WINDOW FUNCTION*/
function showwindow(url) {newwindow=window.open(url,'name','height=436,width=626');
if (window.focus) {newwindow.focus()}
} 

/* FACEBOOK */
function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}

/* JQUERY TABS */
$(function () {
  var tabContainers = $('div.tabs > div');tabContainers.hide().filter(':first').hide();$('div.tabs ul.tabnav a').click(function () {tabContainers.hide();tabContainers.filter(this.hash).show();$('div.tabs ul.tabnav a').removeClass('selected');$(this).addClass('selected');return false;}).filter(':first').click();});


//PRETTYPHOTO LIGHTBOX SCRIPT
/* ------------------------------------------------------------------------
	Class: prettyPhoto
	Use: Lightbox clone for jQuery
	Author: Stephane Caron (http://www.no-margin-for-errors.com)
	Version: 2.2.2
------------------------------------------------------------------------- */

eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('$.2L.2M=5(j){E k=F;E l=0;E m=0;E n=0;E o=F;E p=0;E q=V;E r=[];$(B).2N(5(){1w()});$(B).2O(5(){1w();29()});$(1i).2P(5(e){2Q(e.2R){1J 37:8(m==1)L;15(\'R\');1K;1J 39:8(m==l)L;15(\'W\');1K;1J 27:X();1K}});j=2S.2T({A:\'2U\',O:2V,1j:0.35,1L:V,2a:V,1x:\'/\'},j);$(S).2b(5(){r[r.1k]=S;$(S).Y(\'P\',5(){2c(S);L F})});5 2c(a){p=$(a);2d=$(p).w(\'1M\');2e=/\\[(?:.*)\\]/;2f=2e.2W(2d);1N="1O";8($(p).w(\'D\').Z(\'.2X\')>0){o=F;1N=\'2g\'};k=F;l=0;2Y(i=0;i<r.1k;i++){8($(r[i]).w(\'1M\').Z(2f)!=-1){l++;8(l>1)k=V;8($(r[i]).w(\'D\')==$(a).w(\'D\')){m=l;n=i}}};2h(k);$(\'3.4 p.1P\').1Q(m+j.1x+l);1w();$(\'3.4 #1a\').1l();$(\'.1y\').1R();(1N==\'1O\')?1z():2i()};1S=5(a,b,c,d,e,f,g){$(\'.1y\').1l();E h=1T();8($.16.1U){J=B.1V;K=B.1W}H{J=$(B).s();K=$(B).t()};$(\'3.4 .1m\').1A({\'s\':e,\'t\':c},j.A);11=h[\'1b\']+((J/2)-(d/2));8(11<0)11=0+$(\'3.C\').s();$(\'3.4\').1A({\'z\':11,\'I\':((K/2)-(c/2)),\'t\':c},j.A,5(){$(\'#1n\').w({\'t\':a,\'s\':b});$(\'3.4\').t(c);$(\'3.4 .17\').s(b).t(a);2j();$(\'3.4 #1a\').1o(j.A);8(g)$(\'a.12,a.1p\').1o(j.A)})};5 15(a){8(a==\'R\'){n--;m--}H{n++;m++};8(!q)q=V;$(\'3.4 .17,3.4 .y\').18(j.A);$(\'3.4 #1a\').18(j.A,5(){$(\'.1y\').1R();1z()});1X();$(\'a.12,a.1p\').18(j.A,5(){$(S).1q(\'1p\').1r(\'12\')})};5 X(){$(\'3.4,3.C\').18(j.A,5(){$(\'3.1c\').18(j.A,5(){$(\'3.1c,3.4,3.C\').2Z();8($.16.2k&&$.16.2l==6){$(\'2m\').9(\'1d\',\'1Y\')}})})};5 2n(){8(m==l){$(\'3.4 a.W\').9(\'1d\',\'1B\');$(\'3.4 a.1C\').1r(\'1e\').2o(\'P\')}H{$(\'3.4 a.W\').9(\'1d\',\'1Y\');$(\'3.4 a.1C.1e\').1q(\'1e\').Y(\'P\',5(){15(\'W\');L F})};8(m==1){$(\'3.4 a.R\').9(\'1d\',\'1B\');$(\'3.4 a.1D\').1r(\'1e\').2o(\'P\')}H{$(\'3.4 a.R\').9(\'1d\',\'1Y\');$(\'3.4 a.1D.1e\').1q(\'1e\').Y(\'P\',5(){15(\'R\');L F})};$(\'3.4 p.1P\').1Q(m+j.1x+l);(k)?$c=$(r[n]):$c=$(p);8($c.w(\'1Z\')){$(\'3.4 .1s\').1R().2p(2q($c.w(\'1Z\')))}H{$(\'3.4 .1s\').1l().1Q(\'\')};8($c.2r(\'20\').w(\'2s\')&&j.1L){o=V;$(\'3.C .1t\').2p(2q($c.2r(\'20\').w(\'2s\')))}H{o=F}};5 2t(a,b){21=F;$(\'3.4 .y\').t(a);$(\'3.4 .y p.1s\').t(a-u($(\'3.4 a.X\').9(\'t\')));13=b+u($(\'3.4 .y\').s())+u($(\'3.4 .y\').9(\'T-z\'))+u($(\'3.4 .y\').9(\'T-19\'));U=a;M=b+u($(\'3.C\').s())+u($(\'3.4 .z\').s())+u($(\'3.4 .19\').s());N=a+j.O;1f=a;1g=b;8($.16.1U){J=B.1V;K=B.1W}H{J=$(B).s();K=$(B).t()};8(((N>K)||(M>J))&&q&&j.2a){21=V;8((N>K)&&(M>J)){E c=(N+2u)/K;E d=(M+2u)/J}H{E c=K/N;E d=J/M}8(d>c){1f=1E.1F(a*(1/d));1g=1E.1F(b*(1/d))}H{1f=1E.1F(a*(1/c));1g=1E.1F(b*(1/c))};13=1g+u($(\'3.4 .y\').s())+u($(\'3.4 .y\').9(\'T-z\'))+u($(\'3.4 .y\').9(\'T-19\'));U=1f;M=1g+u($(\'3.C\').s())+u($(\'3.4 .z\').s())+u($(\'3.4 .19\').s());N=1f+j.O;$(\'3.4 .y\').t(U);$(\'3.4 .y p.1s\').t(U-u($(\'3.4 a.X\').9(\'t\')))};L{t:1f,s:1g,M:M,N:N,13:13,U:U,2v:21}};5 1w(){8($(\'3.4\').30()>0){E a=1T();8($.16.1U){J=B.1V;K=B.1W}H{J=$(B).s();K=$(B).t()};8(q){11=(J/2)+a[\'1b\']-($(\'3.4\').s()/2);8(11<0)11=0+$(\'3.C\').s();$(\'3.4\').9({\'z\':11,\'I\':(K/2)+a[\'1u\']-($(\'3.4\').t()/2)});$(\'3.C\').9({\'z\':$(\'3.4\').1h().z-$(\'3.C\').s(),\'I\':$(\'3.4\').1h().I+(j.O/2)})}}};5 2j(){8(k)$(\'3.4 .17\').1o(j.A);$(\'3.4 .y\').1o(j.A);2w()};5 2w(){8(j.1L&&o){$(\'3.C\').9({\'z\':$(\'3.4\').1h().z,\'I\':$(\'3.4\').1h().I+(j.O/2),\'2x\':\'31\'});$(\'3.C 3.1t\').9(\'t\',\'32\');8($(\'3.C\').t()>$(\'3.4\').t()){$(\'3.C 3.1t\').9(\'t\',$(\'3.4\').t()-(j.O*2))}H{$(\'3.C 3.1t\').9(\'t\',\'\')};$(\'3.C\').1A({\'z\':($(\'3.4\').1h().z-22)},j.A)}};5 1X(){$(\'3.C\').1A({\'z\':($(\'3.4\').1h().z)},j.A,5(){$(S).9(\'2x\',\'33\')})};5 1z(){2n();Q=23 24();2y=23 24();8(k)2y.14=$(r[n+1]).w(\'D\');2z=23 24();8(k&&r[n-1])2z.14=$(r[n-1]).w(\'D\');$(\'3.4 .1m\').9(\'34\',\'1B\');8(k){$(\'3.4 #1n\').w(\'14\',$(r[n]).w(\'D\'))}H{$(\'3.4 #1n\').w(\'14\',$(p).w(\'D\'))};Q.36=5(){E a=2t(Q.t,Q.s);Q.t=a[\'t\'];Q.s=a[\'s\'];2A(\'1S(Q.t,Q.s,\'+a["N"]+\',\'+a["M"]+\',\'+a["13"]+\',\'+a["U"]+\',\'+a["2v"]+\')\',2B)};(k)?Q.14=$(r[n]).w(\'D\'):Q.14=$(p).w(\'D\')};5 1T(){1b=B.38||1i.2C.1b||0;1u=B.3a||1i.2C.1u||0;L{1b:1b,1u:1u}};5 29(){$(\'3.1c\').9({\'s\':$(1i).s(),\'t\':$(B).t()})};5 2i(){G=$(p).w(\'1M\').3b(\';\');$(G).2b(5(i){8(G[i].Z(\'t\')>=0)1v=G[i].25(G[i].Z(\'t\')+6,G[i].1k);8(G[i].Z(\'s\')>=0)1G=G[i].25(G[i].Z(\'s\')+7,G[i].1k);8(G[i].Z(\'26\')>=0)2D=G[i].25(G[i].Z(\'26\')+10,G[i].1k)});$(\'.4 #1a\').1H(\'<3c t="\'+1v+\'" s="\'+1G+\'" 3d="3e://3f.3g.3h/2E/3i/3j.3k?3l=3m" 3n="3o/x-2E-2g" 3p="3q" 3r="3s" 26="\'+2D+\'" 3t="3u" 3v="#3w" 3x="3y" 14="\'+$(p).w(\'D\')+\'"/>\');$(\'#1n\').1l();13=u(1G)+u($(\'3.4 .y\').s())+u($(\'3.4 .y\').9(\'T-z\'))+u($(\'3.4 .y\').9(\'T-19\'));U=u(1v)+u($(\'3.4 .y\').t())+u($(\'3.4 .y\').9(\'T-I\'))+u($(\'3.4 .y\').9(\'T-1I\'));M=13+u($(\'3.4 .z\').s())+u($(\'3.4 .19\').s());N=u(1v)+u($(\'3.4 .1m\').9("O-I"))+u($(\'3.4 .1m\').9("O-1I"))+j.O;2A(\'1S(\'+1v+\',\'+1G+\',\'+N+\',\'+M+\',\'+13+\',\'+U+\')\',2B)};5 2h(){2F="<3 v=\'1c\'></3>";$(\'2G\').1H(2F);$(\'3.1c\').9(\'s\',$(1i).s()).Y(\'P\',5(){X()});4=\'<3 v="4"><3 v="z"><3 v="I"></3><3 v="2H"></3><3 v="1I"></3></3><3 v="1m"><a D="#" v="12" 1Z="2I 3z 1O">2I</a><3 v="1y"></3><3 v="17"><a v="W" D="#">W</a><a v="R" D="#">R</a></3><3 2J="1a"><20 2J="1n" 14="" /></3><3 v="y 3A"><a v="X" D="#">3B</a><p v="1s"></p><3 v="2K"><a D="#" v="1D">3C</a><p v="1P">0\'+j.1x+\'0</p><a D="#" v="1C">3D</a></3></3></3><3 v="19"><3 v="I"></3><3 v="2H"></3><3 v="1I"></3></3></3>\';28=\'<3 v="C"><3 v="3E"></3><3 v="1t"></3><3 v="3F"></3></3>\';$(\'2G\').1H(4).1H(28);$(\'.4,.28\').9({\'1j\':0});$(\'a.X\').Y(\'P\',5(){X();L F});$(\'a.12\').Y(\'P\',5(){8($(S).3G(\'12\')){$(S).1q(\'12\').1r(\'1p\');q=F}H{$(S).1q(\'1p\').1r(\'12\');q=V};1X();$(\'3.4 .17,3.4 #1a\').18(j.A);$(\'3.4 .y\').18(j.A,5(){1z()});L F});$(\'.4 .R,.4 .1D\').Y(\'P\',5(){15(\'R\');L F});$(\'.4 .W,.4 .1C\').Y(\'P\',5(){15(\'W\');L F});$(\'.17\').9({\'T-I\':j.O/2});8(!k){$(\'.17,.2K\').1l()};8($.16.2k&&$.16.2l==6){$(\'2m\').9(\'1d\',\'1B\')};$(\'3.1c\').9(\'1j\',0).3H(j.A,j.1j,5(){$(\'3.4\').9(\'1j\',0).1o(j.A,5(){$(\'3.4\').w(\'3I\',\'I:\'+$(\'3.4\').9(\'I\')+\';z:\'+$(\'3.4\').9(\'z\')+\';\')})})}};',62,231,'|||div|pictureHolder|function|||if|css|||||||||||||||||||height|width|parseFloat|class|attr||details|top|animationSpeed|window|prettyPhotoTitle|href|var|false|flashParams|else|left|windowHeight|windowWidth|return|containerHeight|containerWidth|padding|click|imgPreloader|previous|this|margin|contentWidth|true|next|close|bind|indexOf||projectedTop|expand|contentHeight|src|changePicture|browser|hoverContainer|fadeOut|bottom|fullResImageContainer|scrollTop|prettyPhotoOverlay|visibility|disabled|imageWidth|imageHeight|offset|document|opacity|length|hide|content|fullResImage|fadeIn|contract|removeClass|addClass|description|prettyPhotoTitleContent|scrollLeft|flashWidth|_centerPicture|counter_separator_label|loaderIcon|_preload|animate|hidden|arrow-next|arrow-previous|Math|round|flashHeight|append|right|case|break|showTitle|rel|contentType|image|currentTextHolder|text|show|showimage|_getScroll|opera|innerHeight|innerWidth|_hideTitle|visible|title|img|hasBeenResized||new|Image|substring|flashvars||titleHolder|_resizeOverlay|allowresize|each|open|theRel|galleryRegExp|theGallery|flash|_buildOverlay|_writeFlash|_shownav|msie|version|select|_checkPosition|unbind|html|unescape|find|alt|_fitToViewport|200|resized|_showTitle|display|nextImage|prevImage|setTimeout|500|documentElement|flashVars|shockwave|backgroundDiv|body|middle|Expand|id|nav|fn|prettyPhoto|scroll|resize|keyup|switch|keyCode|jQuery|extend|normal|40|exec|swf|for|remove|size|block|auto|none|overflow||onload||pageYOffset||pageXOffset|split|embed|pluginspage|http|www|macromedia|com|download|index|cgi|P1_Prod_Version|ShockwaveFlash|type|application|wmode|opaque|name|prettyFlash|allowscriptaccess|always|bgcolor|FFFFFF|quality|high|the|clearfix|Close|Previous|Next|prettyPhotoTitleLeft|prettyPhotoTitleRight|hasClass|fadeTo|style'.split('|'),0,{}));
/*
 * 	Easy Slider 1.5 - jQuery plugin
 *	written by Alen Grakalic	
 *	http://cssglobe.com/post/4004/easy-slider-15-the-easiest-jquery-plugin-for-sliding
 *
 *	Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
 *	Dual licensed under the MIT (MIT-LICENSE.txt)
 *	and GPL (GPL-LICENSE.txt) licenses.
 *
 *	Built for jQuery library
 *	http://jquery.com
 *
 */
(function($) {

	$.fn.easySlider = function(options){
	  
		// default configuration properties
		var defaults = {			
			prevId: 		'prevBtn',
			prevText: 		'Previous',
			nextId: 		'nextBtn',	
			nextText: 		'Next',
			controlsShow:	true,
			controlsBefore:	'',
			controlsAfter:	'',	
			controlsFade:	true,
			firstId: 		'firstBtn',
			firstText: 		'First',
			firstShow:		false,
			lastId: 		'lastBtn',	
			lastText: 		'Last',
			lastShow:		false,				
			vertical:		false,
			speed: 			800,
			auto:			false,
			pause:			2000,
			continuous:		false
		}; 
		
		var options = $.extend(defaults, options);  
				
		this.each(function() {  
			var obj = $(this); 				
			var s = $("li", obj).length;
			var w = $("li", obj).width(); 
			var h = $("li", obj).height(); 
			obj.width(w); 
			obj.height(h); 
			obj.css("overflow","hidden");
			var ts = s-1;
			var t = 0;
			$("ul", obj).css('width',s*w);			
			if(!options.vertical) $("li", obj).css('float','left');
			
			if(options.controlsShow){
				var html = options.controlsBefore;
				if(options.firstShow) html += '<span id="'+ options.firstId +'"><a href=\"javascript:void(0);\">'+ options.firstText +'</a></span>';
				html += ' <span id="'+ options.prevId +'"><a href=\"javascript:void(0);\">'+ options.prevText +'</a></span>';
				html += ' <span id="'+ options.nextId +'"><a href=\"javascript:void(0);\">'+ options.nextText +'</a></span>';
				if(options.lastShow) html += ' <span id="'+ options.lastId +'"><a href=\"javascript:void(0);\">'+ options.lastText +'</a></span>';
				html += options.controlsAfter;						
				$(obj).after(html);										
			};
	
			$("a","#"+options.nextId).click(function(){		
				animate("next",true);
			});
			$("a","#"+options.prevId).click(function(){		
				animate("prev",true);				
			});	
			$("a","#"+options.firstId).click(function(){		
				animate("first",true);
			});				
			$("a","#"+options.lastId).click(function(){		
				animate("last",true);				
			});		
			
			function animate(dir,clicked){
				var ot = t;				
				switch(dir){
					case "next":
						t = (ot>=ts) ? (options.continuous ? 0 : ts) : t+1;						
						break; 
					case "prev":
						t = (t<=0) ? (options.continuous ? ts : 0) : t-1;
						break; 
					case "first":
						t = 0;
						break; 
					case "last":
						t = ts;
						break; 
					default:
						break; 
				};	
				
				var diff = Math.abs(ot-t);
				var speed = diff*options.speed;						
				if(!options.vertical) {
					p = (t*w*-1);
					$("ul",obj).animate(
						{ marginLeft: p }, 
						speed
					);				
				} else {
					p = (t*h*-1);
					$("ul",obj).animate(
						{ marginTop: p }, 
						speed
					);					
				};
				
				if(!options.continuous && options.controlsFade){					
					if(t==ts){
						$("a","#"+options.nextId).hide();
						$("a","#"+options.lastId).hide();
					} else {
						$("a","#"+options.nextId).show();
						$("a","#"+options.lastId).show();					
					};
					if(t==0){
						$("a","#"+options.prevId).hide();
						$("a","#"+options.firstId).hide();
					} else {
						$("a","#"+options.prevId).show();
						$("a","#"+options.firstId).show();
					};					
				};				
				
				if(clicked) clearTimeout(timeout);
				if(options.auto && dir=="next" && !clicked){;
					timeout = setTimeout(function(){
						animate("next",false);
					},diff*options.speed+options.pause);
				};
				
			};
			// init
			var timeout;
			if(options.auto){;
				timeout = setTimeout(function(){
					animate("next",false);
				},options.pause);
			};		
		
			if(!options.continuous && options.controlsFade){					
				$("a","#"+options.prevId).hide();
				$("a","#"+options.firstId).hide();				
			};				
			
		});
	  
	};

})(jQuery);

/*
	ColorBox v1.1.1 - a full featured, light-weight, customizable lightbox based on jQuery 1.3
	(c) 2009 Jack Moore - www.colorpowered.com - jack@colorpowered.com
	Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
*/

(function($){
var clone, loadedWidth, loadedHeight, interfaceHeight, interfaceWidth, index, related, closeModal, loadingElement, modal, modalWrap, modalOverlay, modalLoadingOverlay, modalContent, loaded, modalClose, btc, bml, bmr, bbc;
function setModalOverlay(){
	$([modalOverlay]).css({"position":"absolute", width:$(window).width(), height:$(window).height(), top:$(window).scrollTop(), left:$(window).scrollLeft()});
}
function keypressEvents(e){
	if(e.keyCode == 37){
		$(document).unbind('keydown', keypressEvents);
		$("a#content-previous").click();
	}
	else if(e.keyCode == 39){
		$(document).unbind('keydown', keypressEvents);
		$("a#content-next").click();
	}
}
closeModal = function(){
	if($("#colorboxInlineTemp").length > 0){
		$(loaded).children().insertAfter("#colorboxInlineTemp");
	}
	$([modalOverlay, modal]).css({cursor:"auto"}).fadeOut("fast", function(){
		$(loaded).remove();
		$(modal).removeData("open");
	});
	if(loadingElement){$(loadingElement).remove();}
	$(document).unbind('keydown', keypressEvents);
	$(window).unbind('resize scroll', setModalOverlay);
};
// Convert % values to pixels
function setSize(size, dimension){
	return (typeof size == 'string') ? (size.match(/%/) ? (dimension/100)*parseInt(size, 10) : parseInt(size, 10)) : size;
}

//Initialize the modal: store common calculations, preload the interface graphics, append the html.
$(function(){
	$("body").append(
		$([
			modalOverlay = $('<div id="modal-background-overlay" />')[0], 
			modal = $('<div id="colorbox" />')[0]
		]).hide()
	);
	$(modal).append(
		$([
			modalWrap = $('<div id="modal-wrap" />')[0]
		])
	);
	$(modalWrap).append(
		$([
			$('<div><div id="border-top-left"></div><div id="border-top-center"></div><div id="border-top-right"></div></div>')[0],
			bml = $('<div id="border-middle-left" />')[0],
			modalContent = $('<div id="modal-content" />')[0],
			bmr = $('<div id="border-middle-right" />')[0],
			$('<div><div id="border-bottom-left"></div><div id="border-bottom-center"></div><div id="border-bottom-right"></div></div>')[0]
		])
	);
	$(modalContent).append(
		$([
			loaded = $('<div id="modal-loaded-content"><a id="content-previous" href="#"></a><a id="content-next" href="#"></a><span id="content-current"></span><br id="modalInfoBr"/><span id="content-title"></span><div id="preloadPrevious"></div><div id="preloadNext"></div><div id="preloadClose"></div></div>')[0], 
			modalLoadingOverlay = $('<div id="modal-loading-overlay" />')[0],
			modalClose = $('<a id="modal-close" href="#"></a>')[0]
		])
	);
	$(modalClose).click(function(){
		closeModal();
		return false;
	});
	
	btc = $("#border-top-center")[0];
	bbc = $("#border-bottom-center")[0];
	
	$(document).bind('keydown', function(e){if(e.keyCode == 27){closeModal();}});

	$(modal).css("opacity", 0).show();

	interfaceHeight = $(btc).height()+$(bbc).height()+$(modalContent).outerHeight(true) - $(modalContent).height();//Subtraction needed for IE6
	interfaceWidth = $(bml).width()+$(bmr).width()+$(modalContent).outerWidth(true) - $(modalContent).width();

	loadedHeight = $(loaded).outerHeight(true);
	loadedWidth = $(loaded).outerWidth(true);
	$(loaded).empty();
	$(modal).css({"padding-bottom":interfaceHeight,"padding-right":interfaceWidth}).hide();//the padding removes the need to do size conversions during the animation step.
});

$.fn.colorbox = function(settings, callback) {
	settings = $.extend({}, $.fn.colorbox.settings, settings);
	//sets the position of the modal on screen.  A transition speed of 0 will result in no animation.
	function modalPosition(mWidth, mHeight, speed, loadedCallback){

		var winHeight = document.documentElement.clientHeight;
		var posTop = winHeight/2 - mHeight/2 + $(window).scrollTop();
		var posLeft = document.documentElement.clientWidth/2 - mWidth/2 + $(window).scrollLeft();
		//keeps the box from expanding to an inaccessible area offscreen.
		if(mHeight > winHeight){posTop -=(mHeight - winHeight);}
		if(posTop < 0){posTop = 0;} 
		if(posLeft < 0){posLeft = 0;}

		mWidth = mWidth - interfaceWidth;
		mHeight = mHeight - interfaceHeight;

		function modalDimensions(that){
			modalContent.style.width = btc.style.width = bbc.style.width = that.style.width;
			modalContent.style.height = bml.style.height = bmr.style.height = that.style.height;
		}
		$(modal).animate({height:mHeight, width:mWidth, top:posTop, left:posLeft}, {duration: speed,
			complete: function(){
				if (loadedCallback) {loadedCallback();}
				modalDimensions(this);
				$(document).bind('keydown', keypressEvents);
				if ($.browser.msie && $.browser.version < 7) {setModalOverlay();}
			},
			step: function(){
				modalDimensions(this);		
			}
		});
	}
	var preloads = [];
	function preload(){
		if(settings.preloading !== false && related.length>1){
			var previous, next;
			previous = index > 0 ? related[index-1].href : related[related.length-1].href;
			next = index < related.length-1 ? related[index+1].href : related[0].href;
			return [$("<img />").attr("src", next), $("<img />").attr("src", previous)];
		}
	}
	function centerModal(object, contentInfo){
		var speed = settings.transition=="none" ? 0 : settings.transitionSpeed;
		$(loaded).remove();
		loaded = $(object)[0];
		$(loaded).hide().appendTo('body').css({width:(settings.fixedWidth)?settings.fixedWidth - loadedWidth - interfaceWidth:$(loaded).width()}).css({height:(settings.fixedHeight)?settings.fixedHeight - loadedHeight - interfaceHeight:$(loaded).height()})
		.attr({id:"modal-loaded-content"}).append(contentInfo).prependTo($(modalContent));

		function setPosition(s){
			modalPosition(parseInt(loaded.style.width, 10)+loadedWidth+interfaceWidth, parseInt(loaded.style.height, 10)+loadedHeight+interfaceHeight, s, function(){
				$(loaded).show();
				$(modalLoadingOverlay).hide();
				if (callback) {callback();}
				if (settings.transition == "fade"){$(modal).animate({"opacity":1}, speed);}
			});
		}
		if (settings.transition == "fade") {
			$(modal).animate({"opacity":0}, speed, function(){setPosition(0);});
		} else {
			setPosition(speed);
		}
		//var preloads = preload();
	}

	function buildGallery(that){
		var href = settings.href ? settings.href : that.href;
		var contentInfo = "<p id='content-title'>"+that.title+"</p>";
		if(related.length>1){
			contentInfo += "<span id='content-current'> " + settings.contentCurrent + "</span>";
			contentInfo = contentInfo.replace(/\{current\}/, index+1).replace(/\{total\}/, related.length);
			contentInfo += "<a id='content-previous' href='#'>"+settings.contentPrevious+"</a><a id='content-next' href='#'>"+settings.contentNext+"</a> ";
		}
		if (settings.inline) {
			loadingElement = $('<div id="colorboxInlineTemp" />').hide().insertBefore($(href)[0]);
			clone = $(href).clone(true);
			centerModal($(href).wrapAll("<div></div>").parent(), contentInfo);
		} else if (settings.iframe) {
			centerModal($("<div><iframe name='iframe_"+new Date().getTime()+" 'frameborder=0 src =" + href + "></iframe></div>"), contentInfo);//timestamp to prevent caching.
		} else if (href.match(/\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(.*))?$/i)){
			loadingElement = $("<img id='modalPhoto' "+((related.length > 1)?"style='cursor:pointer;' class='modalPhoto'":"")+" alt='' />").load(function(){
				centerModal($("<div style='display: table-cell; vertical-align: middle; position: static;' />").append($(this)), contentInfo);
			}).attr("src",href);
		}else {
			loadingElement = $('<div></div>').load(href, function(data, textStatus){
				if(textStatus == "success"){
					centerModal($(this), contentInfo);
				} else {
					centerModal($("<p>Request unsuccessful.</p>"));
				}
			});
		}
	}

	function contentNav(){
		$(modalLoadingOverlay).show();
		if($(this).attr("id") == "content-previous"){
			index = index > 0 ? index-1 : related.length-1;
		} else {
			index = index < related.length-1 ? index+1 : 0;
		}
		buildGallery(related[index]);
		return false;	
	}

	$(this).bind("click.colorbox", function () {
		if ($(modal).data("open") !== true) {
			$(modal).data("open", true);

			if(settings.fixedWidth){ settings.fixedWidth = setSize(settings.fixedWidth, document.documentElement.clientWidth);}
			if(settings.fixedHeight){ settings.fixedHeight = setSize(settings.fixedHeight, document.documentElement.clientHeight);}
			$(modalClose).html(settings.modalClose);
			$(modalOverlay).css({"opacity": settings.bgOpacity});
			$([modal, modalLoadingOverlay, modalOverlay]).show();
			modalPosition(setSize(settings.initialWidth, document.documentElement.clientWidth), setSize(settings.initialHeight, document.documentElement.clientHeight), 0);
			if (this.rel && 'nofollow' != this.rel) {
				related = $("a[rel='" + this.rel + "']");
				index = $(related).index(this);
			}
			else {
				related = $(this);
				index = 0;
			}
			$(modal).css({"opacity":1});
			buildGallery(related[index]);
			$("a#content-previous, a#content-next, .modalPhoto").die().live("click", contentNav);
			$(document).bind('keydown', keypressEvents);
			if ($.browser.msie && $.browser.version < 7) {
				$(window).bind("resize scroll", setModalOverlay);
			}
		}
		if(settings.overlayClose!==false){
			$(modalOverlay).css({"cursor":"pointer"}).click(function(){closeModal();});
		}
		return false;
	});


	if(settings.open!==false && $(modal).data("open")!==true){
		$(this).triggerHandler('click.colorbox');
	}

	return this.each(function() { 
	});
};

/*
	ColorBox Default Settings.
	
	The colorbox() function takes one argument, an object of key/value pairs, that are used to initialize the modal.
	
	Please do not change these settings here, instead overwrite these settings when attaching the colorbox() event to your anchors.
	Example (Global)	: $.fn.colorbox.settings.transition = "fade"; //changes the transition to fade for all colorBox() events proceeding it's declaration.
	Example (Specific)	: $("a[href='http://www.google.com']").colorbox({fixedWidth:"90%", fixedHeight:"450px", iframe:true});
*/
$.fn.colorbox.settings = {
	transition : "elastic", // Transition types: "elastic", "fade", or "none".
	transitionSpeed : 350, // Sets the speed of the fade and elastic transitions, in milliseconds.
	initialWidth : "400", // Set the initial width of the modal, prior to any content being loaded.
	initialHeight : "400", // Set the initial height of the modal, prior to any content being loaded.
	fixedWidth : false, // Set a fixed width for div#loaded.  Example: "500px"
	fixedHeight : false, // Set a fixed height for div#modal-loaded-content.  Example: "500px"
	inline : false, // Set this to the selector of inline content to be displayed.  Example "#myHiddenDiv" or "body p".
	iframe : false, // If 'true' specifies that content should be displayed in an iFrame.
	href : false, // This can be used as an alternate anchor URL for ColorBox to use, or can be used to assign a URL for non-anchor elments such as images or form buttons.
	bgOpacity : 0.85, // The modal-background-overlay opacity level. Range: 0 to 1.
	preloading : true, // Allows for preloading of 'Next' and 'Previous' content in a shared relation group (same values for the 'rel' attribute), after the current content has finished loading.  Set to 'false' to disable.
	contentCurrent : "image {current} of {total}", // the format of the contentCurrent information
	contentPrevious : "previous", // the anchor text for the previous link in a shared relation group (same values for 'rel').
	contentNext : "next", // the anchor text for the next link in a shared relation group (same 'rel' attribute').
	modalClose : "close", // the anchor text for the close link.  Esc will also close the modal.
	open : false, //Automatically opens ColorBox. (fires the click.colorbox event without waiting for user input).
	overlayClose : true  //If true, enables closing ColorBox by clicking on the background overlay.
};

})(jQuery);

