/*
 * jquery.tools 1.0.2 - The missing UI library for the Web
 * 
 * [tools.tabs-1.0.1, tools.tooltip-1.0.2, tools.scrollable-1.0.5, tools.overlay-1.0.4, tools.expose-1.0.3]
 * 
 * Copyright (c) 2009 Tero Piirainen
 * http://flowplayer.org/tools/
 *
 * Dual licensed under MIT and GPL 2+ licenses
 * http://www.opensource.org/licenses
 * */

(function(c){c.tools=c.tools||{version:{}};c.tools.version.tabs="1.0.1";c.tools.addTabEffect=function(d,e){b[d]=e};var b={"default":function(d){this.getPanes().hide().eq(d).show()},fade:function(d){this.getPanes().hide().eq(d).fadeIn(this.getConf().fadeInSpeed)},slide:function(d){this.getCurrentPane().slideUp("fast");this.getPanes().eq(d).slideDown()},horizontal:function(d){if(!c._hW){c._hW=this.getPanes().eq(0).width()}this.getCurrentPane().animate({width:0},function(){c(this).hide()});this.getPanes().eq(d).animate({width:c._hW},function(){c(this).show()})}};function a(e,f,g){var d=this;var h;function i(j,k){c(d).bind(j,function(m,l){if(k&&k.call(this,l.index)===false&&l){l.proceed=false}});return d}c.each(g,function(j,k){if(c.isFunction(k)){i(j,k)}});c.extend(this,{click:function(k){if(k===h){return d}var m=d.getCurrentPane();var l=e.eq(k);if(typeof k=="string"){l=e.filter("[href="+k+"]");k=e.index(l)}if(!l.length){if(h>=0){return d}k=g.initialIndex;l=e.eq(k)}var j={index:k,proceed:true};c(d).triggerHandler("onBeforeClick",j);if(!j.proceed){return d}l.addClass(g.current);b[g.effect].call(d,k);c(d).triggerHandler("onClick",j);e.removeClass(g.current);l.addClass(g.current);h=k;return d},getConf:function(){return g},getTabs:function(){return e},getPanes:function(){return f},getCurrentPane:function(){return f.eq(h)},getCurrentTab:function(){return e.eq(h)},getIndex:function(){return h},next:function(){return d.click(h+1)},prev:function(){return d.click(h-1)},onBeforeClick:function(j){return i("onBeforeClick",j)},onClick:function(j){return i("onClick",j)}});e.each(function(j){c(this).bind(g.event,function(k){d.click(j);if(!g.history){return k.preventDefault()}})});if(g.history){e.history(function(j,k){d.click(k||0)})}if(location.hash){d.click(location.hash)}else{d.click(g.initialIndex)}f.find("a[href^=#]").click(function(){d.click(c(this).attr("href"))})}c.fn.tabs=function(g,d){var e=this.eq(typeof conf=="number"?conf:0).data("tabs");if(e){return e}var f={tabs:"a",current:"current",onBeforeClick:null,onClick:null,effect:"default",history:false,initialIndex:0,event:"click",api:false};if(c.isFunction(d)){d={onBeforeClick:d}}c.extend(f,d);this.each(function(){var h=c(this).find(f.tabs);if(!h.length){h=c(this).children()}var i=g.jquery?g:c(g);e=new a(h,i,f);c(this).data("tabs",e)});return f.api?e:this}})(jQuery);(function(b){var c,a;b.prototype.history=function(e){var d=this;if(b.browser.msie){if(!a){a=b("<iframe />").hide().get(0);b("body").append(a);setInterval(function(){var f=a.contentWindow.document;var g=f.location.hash;if(c!==g){b.event.trigger("hash",g);c=g}},100)}d.bind("click.hash",function(g){var f=a.contentWindow.document;f.open().close();f.location.hash=b(this).attr("href")});d.eq(0).triggerHandler("click.hash")}else{setInterval(function(){var f=location.hash;if(d.filter("[href*="+f+"]").length&&f!==c){c=f;b.event.trigger("hash",f)}},100)}b(window).bind("hash",e);return this}})(jQuery);
/*
 * jQuery UI 1.7.2
 *
 * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * http://docs.jquery.com/UI
 */
jQuery.ui||(function(c){var i=c.fn.remove,d=c.browser.mozilla&&(parseFloat(c.browser.version)<1.9);c.ui={version:"1.7.2",plugin:{add:function(k,l,n){var m=c.ui[k].prototype;for(var j in n){m.plugins[j]=m.plugins[j]||[];m.plugins[j].push([l,n[j]])}},call:function(j,l,k){var n=j.plugins[l];if(!n||!j.element[0].parentNode){return}for(var m=0;m<n.length;m++){if(j.options[n[m][0]]){n[m][1].apply(j.element,k)}}}},contains:function(k,j){return document.compareDocumentPosition?k.compareDocumentPosition(j)&16:k!==j&&k.contains(j)},hasScroll:function(m,k){if(c(m).css("overflow")=="hidden"){return false}var j=(k&&k=="left")?"scrollLeft":"scrollTop",l=false;if(m[j]>0){return true}m[j]=1;l=(m[j]>0);m[j]=0;return l},isOverAxis:function(k,j,l){return(k>j)&&(k<(j+l))},isOver:function(o,k,n,m,j,l){return c.ui.isOverAxis(o,n,j)&&c.ui.isOverAxis(k,m,l)},keyCode:{BACKSPACE:8,CAPS_LOCK:20,COMMA:188,CONTROL:17,DELETE:46,DOWN:40,END:35,ENTER:13,ESCAPE:27,HOME:36,INSERT:45,LEFT:37,NUMPAD_ADD:107,NUMPAD_DECIMAL:110,NUMPAD_DIVIDE:111,NUMPAD_ENTER:108,NUMPAD_MULTIPLY:106,NUMPAD_SUBTRACT:109,PAGE_DOWN:34,PAGE_UP:33,PERIOD:190,RIGHT:39,SHIFT:16,SPACE:32,TAB:9,UP:38}};if(d){var f=c.attr,e=c.fn.removeAttr,h="http://www.w3.org/2005/07/aaa",a=/^aria-/,b=/^wairole:/;c.attr=function(k,j,l){var m=l!==undefined;return(j=="role"?(m?f.call(this,k,j,"wairole:"+l):(f.apply(this,arguments)||"").replace(b,"")):(a.test(j)?(m?k.setAttributeNS(h,j.replace(a,"aaa:"),l):f.call(this,k,j.replace(a,"aaa:"))):f.apply(this,arguments)))};c.fn.removeAttr=function(j){return(a.test(j)?this.each(function(){this.removeAttributeNS(h,j.replace(a,""))}):e.call(this,j))}}c.fn.extend({remove:function(){c("*",this).add(this).each(function(){c(this).triggerHandler("remove")});return i.apply(this,arguments)},enableSelection:function(){return this.attr("unselectable","off").css("MozUserSelect","").unbind("selectstart.ui")},disableSelection:function(){return this.attr("unselectable","on").css("MozUserSelect","none").bind("selectstart.ui",function(){return false})},scrollParent:function(){var j;if((c.browser.msie&&(/(static|relative)/).test(this.css("position")))||(/absolute/).test(this.css("position"))){j=this.parents().filter(function(){return(/(relative|absolute|fixed)/).test(c.curCSS(this,"position",1))&&(/(auto|scroll)/).test(c.curCSS(this,"overflow",1)+c.curCSS(this,"overflow-y",1)+c.curCSS(this,"overflow-x",1))}).eq(0)}else{j=this.parents().filter(function(){return(/(auto|scroll)/).test(c.curCSS(this,"overflow",1)+c.curCSS(this,"overflow-y",1)+c.curCSS(this,"overflow-x",1))}).eq(0)}return(/fixed/).test(this.css("position"))||!j.length?c(document):j}});c.extend(c.expr[":"],{data:function(l,k,j){return !!c.data(l,j[3])},focusable:function(k){var l=k.nodeName.toLowerCase(),j=c.attr(k,"tabindex");return(/input|select|textarea|button|object/.test(l)?!k.disabled:"a"==l||"area"==l?k.href||!isNaN(j):!isNaN(j))&&!c(k)["area"==l?"parents":"closest"](":hidden").length},tabbable:function(k){var j=c.attr(k,"tabindex");return(isNaN(j)||j>=0)&&c(k).is(":focusable")}});function g(m,n,o,l){function k(q){var p=c[m][n][q]||[];return(typeof p=="string"?p.split(/,?\s+/):p)}var j=k("getter");if(l.length==1&&typeof l[0]=="string"){j=j.concat(k("getterSetter"))}return(c.inArray(o,j)!=-1)}c.widget=function(k,j){var l=k.split(".")[0];k=k.split(".")[1];c.fn[k]=function(p){var n=(typeof p=="string"),o=Array.prototype.slice.call(arguments,1);if(n&&p.substring(0,1)=="_"){return this}if(n&&g(l,k,p,o)){var m=c.data(this[0],k);return(m?m[p].apply(m,o):undefined)}return this.each(function(){var q=c.data(this,k);(!q&&!n&&c.data(this,k,new c[l][k](this,p))._init());(q&&n&&c.isFunction(q[p])&&q[p].apply(q,o))})};c[l]=c[l]||{};c[l][k]=function(o,n){var m=this;this.namespace=l;this.widgetName=k;this.widgetEventPrefix=c[l][k].eventPrefix||k;this.widgetBaseClass=l+"-"+k;this.options=c.extend({},c.widget.defaults,c[l][k].defaults,c.metadata&&c.metadata.get(o)[k],n);this.element=c(o).bind("setData."+k,function(q,p,r){if(q.target==o){return m._setData(p,r)}}).bind("getData."+k,function(q,p){if(q.target==o){return m._getData(p)}}).bind("remove",function(){return m.destroy()})};c[l][k].prototype=c.extend({},c.widget.prototype,j);c[l][k].getterSetter="option"};c.widget.prototype={_init:function(){},destroy:function(){this.element.removeData(this.widgetName).removeClass(this.widgetBaseClass+"-disabled "+this.namespace+"-state-disabled").removeAttr("aria-disabled")},option:function(l,m){var k=l,j=this;if(typeof l=="string"){if(m===undefined){return this._getData(l)}k={};k[l]=m}c.each(k,function(n,o){j._setData(n,o)})},_getData:function(j){return this.options[j]},_setData:function(j,k){this.options[j]=k;if(j=="disabled"){this.element[k?"addClass":"removeClass"](this.widgetBaseClass+"-disabled "+this.namespace+"-state-disabled").attr("aria-disabled",k)}},enable:function(){this._setData("disabled",false)},disable:function(){this._setData("disabled",true)},_trigger:function(l,m,n){var p=this.options[l],j=(l==this.widgetEventPrefix?l:this.widgetEventPrefix+l);m=c.Event(m);m.type=j;if(m.originalEvent){for(var k=c.event.props.length,o;k;){o=c.event.props[--k];m[o]=m.originalEvent[o]}}this.element.trigger(m,n);return !(c.isFunction(p)&&p.call(this.element[0],m,n)===false||m.isDefaultPrevented())}};c.widget.defaults={disabled:false};c.ui.mouse={_mouseInit:function(){var j=this;this.element.bind("mousedown."+this.widgetName,function(k){return j._mouseDown(k)}).bind("click."+this.widgetName,function(k){if(j._preventClickEvent){j._preventClickEvent=false;k.stopImmediatePropagation();return false}});if(c.browser.msie){this._mouseUnselectable=this.element.attr("unselectable");this.element.attr("unselectable","on")}this.started=false},_mouseDestroy:function(){this.element.unbind("."+this.widgetName);(c.browser.msie&&this.element.attr("unselectable",this._mouseUnselectable))},_mouseDown:function(l){l.originalEvent=l.originalEvent||{};if(l.originalEvent.mouseHandled){return}(this._mouseStarted&&this._mouseUp(l));this._mouseDownEvent=l;var k=this,m=(l.which==1),j=(typeof this.options.cancel=="string"?c(l.target).parents().add(l.target).filter(this.options.cancel).length:false);if(!m||j||!this._mouseCapture(l)){return true}this.mouseDelayMet=!this.options.delay;if(!this.mouseDelayMet){this._mouseDelayTimer=setTimeout(function(){k.mouseDelayMet=true},this.options.delay)}if(this._mouseDistanceMet(l)&&this._mouseDelayMet(l)){this._mouseStarted=(this._mouseStart(l)!==false);if(!this._mouseStarted){l.preventDefault();return true}}this._mouseMoveDelegate=function(n){return k._mouseMove(n)};this._mouseUpDelegate=function(n){return k._mouseUp(n)};c(document).bind("mousemove."+this.widgetName,this._mouseMoveDelegate).bind("mouseup."+this.widgetName,this._mouseUpDelegate);(c.browser.safari||l.preventDefault());l.originalEvent.mouseHandled=true;return true},_mouseMove:function(j){if(c.browser.msie&&!j.button){return this._mouseUp(j)}if(this._mouseStarted){this._mouseDrag(j);return j.preventDefault()}if(this._mouseDistanceMet(j)&&this._mouseDelayMet(j)){this._mouseStarted=(this._mouseStart(this._mouseDownEvent,j)!==false);(this._mouseStarted?this._mouseDrag(j):this._mouseUp(j))}return !this._mouseStarted},_mouseUp:function(j){c(document).unbind("mousemove."+this.widgetName,this._mouseMoveDelegate).unbind("mouseup."+this.widgetName,this._mouseUpDelegate);if(this._mouseStarted){this._mouseStarted=false;this._preventClickEvent=(j.target==this._mouseDownEvent.target);this._mouseStop(j)}return false},_mouseDistanceMet:function(j){return(Math.max(Math.abs(this._mouseDownEvent.pageX-j.pageX),Math.abs(this._mouseDownEvent.pageY-j.pageY))>=this.options.distance)},_mouseDelayMet:function(j){return this.mouseDelayMet},_mouseStart:function(j){},_mouseDrag:function(j){},_mouseStop:function(j){},_mouseCapture:function(j){return true}};c.ui.mouse.defaults={cancel:null,distance:1,delay:0}})(jQuery);;/*
 * jQuery UI Accordion 1.7.2
 *
 * Copyright (c) 2009 AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * http://docs.jquery.com/UI/Accordion
 *
 * Depends:
 *	ui.core.js
 */
(function(a){a.widget("ui.accordion",{_init:function(){var d=this.options,b=this;this.running=0;if(d.collapsible==a.ui.accordion.defaults.collapsible&&d.alwaysOpen!=a.ui.accordion.defaults.alwaysOpen){d.collapsible=!d.alwaysOpen}if(d.navigation){var c=this.element.find("a").filter(d.navigationFilter);if(c.length){if(c.filter(d.header).length){this.active=c}else{this.active=c.parent().parent().prev();c.addClass("ui-accordion-content-active")}}}this.element.addClass("ui-accordion ui-widget ui-helper-reset");if(this.element[0].nodeName=="UL"){this.element.children("li").addClass("ui-accordion-li-fix")}this.headers=this.element.find(d.header).addClass("ui-accordion-header ui-helper-reset ui-state-default ui-corner-all").bind("mouseenter.accordion",function(){a(this).addClass("ui-state-hover")}).bind("mouseleave.accordion",function(){a(this).removeClass("ui-state-hover")}).bind("focus.accordion",function(){a(this).addClass("ui-state-focus")}).bind("blur.accordion",function(){a(this).removeClass("ui-state-focus")});this.headers.next().addClass("ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom");this.active=this._findActive(this.active||d.active).toggleClass("ui-state-default").toggleClass("ui-state-active").toggleClass("ui-corner-all").toggleClass("ui-corner-top");this.active.next().addClass("ui-accordion-content-active");a("<span/>").addClass("ui-icon "+d.icons.header).prependTo(this.headers);this.active.find(".ui-icon").toggleClass(d.icons.header).toggleClass(d.icons.headerSelected);if(a.browser.msie){this.element.find("a").css("zoom","1")}this.resize();this.element.attr("role","tablist");this.headers.attr("role","tab").bind("keydown",function(e){return b._keydown(e)}).next().attr("role","tabpanel");this.headers.not(this.active||"").attr("aria-expanded","false").attr("tabIndex","-1").next().hide();if(!this.active.length){this.headers.eq(0).attr("tabIndex","0")}else{this.active.attr("aria-expanded","true").attr("tabIndex","0")}if(!a.browser.safari){this.headers.find("a").attr("tabIndex","-1")}if(d.event){this.headers.bind((d.event)+".accordion",function(e){return b._clickHandler.call(b,e,this)})}},destroy:function(){var c=this.options;this.element.removeClass("ui-accordion ui-widget ui-helper-reset").removeAttr("role").unbind(".accordion").removeData("accordion");this.headers.unbind(".accordion").removeClass("ui-accordion-header ui-helper-reset ui-state-default ui-corner-all ui-state-active ui-corner-top").removeAttr("role").removeAttr("aria-expanded").removeAttr("tabindex");this.headers.find("a").removeAttr("tabindex");this.headers.children(".ui-icon").remove();var b=this.headers.next().css("display","").removeAttr("role").removeClass("ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content ui-accordion-content-active");if(c.autoHeight||c.fillHeight){b.css("height","")}},_setData:function(b,c){if(b=="alwaysOpen"){b="collapsible";c=!c}a.widget.prototype._setData.apply(this,arguments)},_keydown:function(e){var g=this.options,f=a.ui.keyCode;if(g.disabled||e.altKey||e.ctrlKey){return}var d=this.headers.length;var b=this.headers.index(e.target);var c=false;switch(e.keyCode){case f.RIGHT:case f.DOWN:c=this.headers[(b+1)%d];break;case f.LEFT:case f.UP:c=this.headers[(b-1+d)%d];break;case f.SPACE:case f.ENTER:return this._clickHandler({target:e.target},e.target)}if(c){a(e.target).attr("tabIndex","-1");a(c).attr("tabIndex","0");c.focus();return false}return true},resize:function(){var e=this.options,d;if(e.fillSpace){if(a.browser.msie){var b=this.element.parent().css("overflow");this.element.parent().css("overflow","hidden")}d=this.element.parent().height();if(a.browser.msie){this.element.parent().css("overflow",b)}this.headers.each(function(){d-=a(this).outerHeight()});var c=0;this.headers.next().each(function(){c=Math.max(c,a(this).innerHeight()-a(this).height())}).height(Math.max(0,d-c)).css("overflow","auto")}else{if(e.autoHeight){d=0;this.headers.next().each(function(){d=Math.max(d,a(this).outerHeight())}).height(d)}}},activate:function(b){var c=this._findActive(b)[0];this._clickHandler({target:c},c)},_findActive:function(b){return b?typeof b=="number"?this.headers.filter(":eq("+b+")"):this.headers.not(this.headers.not(b)):b===false?a([]):this.headers.filter(":eq(0)")},_clickHandler:function(b,f){var d=this.options;if(d.disabled){return false}if(!b.target&&d.collapsible){this.active.removeClass("ui-state-active ui-corner-top").addClass("ui-state-default ui-corner-all").find(".ui-icon").removeClass(d.icons.headerSelected).addClass(d.icons.header);this.active.next().addClass("ui-accordion-content-active");var h=this.active.next(),e={options:d,newHeader:a([]),oldHeader:d.active,newContent:a([]),oldContent:h},c=(this.active=a([]));this._toggle(c,h,e);return false}var g=a(b.currentTarget||f);var i=g[0]==this.active[0];if(this.running||(!d.collapsible&&i)){return false}this.active.removeClass("ui-state-active ui-corner-top").addClass("ui-state-default ui-corner-all").find(".ui-icon").removeClass(d.icons.headerSelected).addClass(d.icons.header);this.active.next().addClass("ui-accordion-content-active");if(!i){g.removeClass("ui-state-default ui-corner-all").addClass("ui-state-active ui-corner-top").find(".ui-icon").removeClass(d.icons.header).addClass(d.icons.headerSelected);g.next().addClass("ui-accordion-content-active")}var c=g.next(),h=this.active.next(),e={options:d,newHeader:i&&d.collapsible?a([]):g,oldHeader:this.active,newContent:i&&d.collapsible?a([]):c.find("> *"),oldContent:h.find("> *")},j=this.headers.index(this.active[0])>this.headers.index(g[0]);this.active=i?a([]):g;this._toggle(c,h,e,i,j);return false},_toggle:function(b,i,g,j,k){var d=this.options,m=this;this.toShow=b;this.toHide=i;this.data=g;var c=function(){if(!m){return}return m._completed.apply(m,arguments)};this._trigger("changestart",null,this.data);this.running=i.size()===0?b.size():i.size();if(d.animated){var f={};if(d.collapsible&&j){f={toShow:a([]),toHide:i,complete:c,down:k,autoHeight:d.autoHeight||d.fillSpace}}else{f={toShow:b,toHide:i,complete:c,down:k,autoHeight:d.autoHeight||d.fillSpace}}if(!d.proxied){d.proxied=d.animated}if(!d.proxiedDuration){d.proxiedDuration=d.duration}d.animated=a.isFunction(d.proxied)?d.proxied(f):d.proxied;d.duration=a.isFunction(d.proxiedDuration)?d.proxiedDuration(f):d.proxiedDuration;var l=a.ui.accordion.animations,e=d.duration,h=d.animated;if(!l[h]){l[h]=function(n){this.slide(n,{easing:h,duration:e||700})}}l[h](f)}else{if(d.collapsible&&j){b.toggle()}else{i.hide();b.show()}c(true)}i.prev().attr("aria-expanded","false").attr("tabIndex","-1").blur();b.prev().attr("aria-expanded","true").attr("tabIndex","0").focus()},_completed:function(b){var c=this.options;this.running=b?0:--this.running;if(this.running){return}if(c.clearStyle){this.toShow.add(this.toHide).css({height:"",overflow:""})}this._trigger("change",null,this.data)}});a.extend(a.ui.accordion,{version:"1.7.2",defaults:{active:null,alwaysOpen:true,animated:"slide",autoHeight:true,clearStyle:false,collapsible:false,event:"click",fillSpace:false,header:"> li > :first-child,> :not(li):even",icons:{header:"ui-icon-triangle-1-e",headerSelected:"ui-icon-triangle-1-s"},navigation:false,navigationFilter:function(){return this.href.toLowerCase()==location.href.toLowerCase()}},animations:{slide:function(j,h){j=a.extend({easing:"swing",duration:300},j,h);if(!j.toHide.size()){j.toShow.animate({height:"show"},j);return}if(!j.toShow.size()){j.toHide.animate({height:"hide"},j);return}var c=j.toShow.css("overflow"),g,d={},f={},e=["height","paddingTop","paddingBottom"],b;var i=j.toShow;b=i[0].style.width;i.width(parseInt(i.parent().width(),10)-parseInt(i.css("paddingLeft"),10)-parseInt(i.css("paddingRight"),10)-(parseInt(i.css("borderLeftWidth"),10)||0)-(parseInt(i.css("borderRightWidth"),10)||0));a.each(e,function(k,m){f[m]="hide";var l=(""+a.css(j.toShow[0],m)).match(/^([\d+-.]+)(.*)$/);d[m]={value:l[1],unit:l[2]||"px"}});j.toShow.css({height:0,overflow:"hidden"}).show();j.toHide.filter(":hidden").each(j.complete).end().filter(":visible").animate(f,{step:function(k,l){if(l.prop=="height"){g=(l.now-l.start)/(l.end-l.start)}j.toShow[0].style[l.prop]=(g*d[l.prop].value)+d[l.prop].unit},duration:j.duration,easing:j.easing,complete:function(){if(!j.autoHeight){j.toShow.css("height","")}j.toShow.css("width",b);j.toShow.css({overflow:c});j.complete()}})},bounceslide:function(b){this.slide(b,{easing:b.down?"easeOutBounce":"swing",duration:b.down?1000:200})},easeslide:function(b){this.slide(b,{easing:"easeinout",duration:700})}}})})(jQuery);;

/*!
* jCarousel - Riding carousels with jQuery
* http://sorgalla.com/jcarousel/
*
* Copyright (c) 2006 Jan Sorgalla (http://sorgalla.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.
*
* Built on top of the jQuery library
* http://jquery.com
*
* Inspired by the "Carousel Component" by Bill Scott
* http://billwscott.com/carousel/
*/ 
(function(i){i.fn.jcarousel=function(a){if(typeof a=="string"){var c=i(this).data("jcarousel"),b=Array.prototype.slice.call(arguments,1);return c[a].apply(c,b)}else return this.each(function(){i(this).data("jcarousel",new h(this,a))})};var p={vertical:false,rtl:false,start:1,offset:1,size:null,scroll:3,visible:null,animation:"normal",easing:"swing",auto:0,wrap:null,initCallback:null,reloadCallback:null,itemLoadCallback:null,itemFirstInCallback:null,itemFirstOutCallback:null,itemLastInCallback:null, itemLastOutCallback:null,itemVisibleInCallback:null,itemVisibleOutCallback:null,buttonNextHTML:"<div></div>",buttonPrevHTML:"<div></div>",buttonNextEvent:"click",buttonPrevEvent:"click",buttonNextCallback:null,buttonPrevCallback:null,itemFallbackDimension:null},q=false;i(window).bind("load.jcarousel",function(){q=true});i.jcarousel=function(a,c){this.options=i.extend({},p,c||{});this.locked=false;this.buttonPrev=this.buttonNext=this.list=this.clip=this.container=null;if(!c||c.rtl===undefined)this.options.rtl= (i(a).attr("dir")||i("html").attr("dir")||"").toLowerCase()=="rtl";this.wh=!this.options.vertical?"width":"height";this.lt=!this.options.vertical?this.options.rtl?"right":"left":"top";for(var b="",d=a.className.split(" "),e=0;e<d.length;e++)if(d[e].indexOf("jcarousel-skin")!=-1){i(a).removeClass(d[e]);b=d[e];break}if(a.nodeName.toUpperCase()=="UL"||a.nodeName.toUpperCase()=="OL"){this.list=i(a);this.container=this.list.parent();if(this.container.hasClass("jcarousel-clip")){if(!this.container.parent().hasClass("jcarousel-container"))this.container= this.container.wrap("<div></div>");this.container=this.container.parent()}else if(!this.container.hasClass("jcarousel-container"))this.container=this.list.wrap("<div></div>").parent()}else{this.container=i(a);this.list=this.container.find("ul,ol").eq(0)}b!=""&&this.container.parent()[0].className.indexOf("jcarousel-skin")==-1&&this.container.wrap('<div class=" '+b+'"></div>');this.clip=this.list.parent();if(!this.clip.length||!this.clip.hasClass("jcarousel-clip"))this.clip=this.list.wrap("<div></div>").parent(); this.buttonNext=i(".jcarousel-next",this.container);if(this.buttonNext.size()==0&&this.options.buttonNextHTML!=null)this.buttonNext=this.clip.after(this.options.buttonNextHTML).next();this.buttonNext.addClass(this.className("jcarousel-next"));this.buttonPrev=i(".jcarousel-prev",this.container);if(this.buttonPrev.size()==0&&this.options.buttonPrevHTML!=null)this.buttonPrev=this.clip.after(this.options.buttonPrevHTML).next();this.buttonPrev.addClass(this.className("jcarousel-prev"));this.clip.addClass(this.className("jcarousel-clip")).css({overflow:"hidden", position:"relative"});this.list.addClass(this.className("jcarousel-list")).css({overflow:"hidden",position:"relative",top:0,margin:0,padding:0}).css(this.options.rtl?"right":"left",0);this.container.addClass(this.className("jcarousel-container")).css({position:"relative"});!this.options.vertical&&this.options.rtl&&this.container.addClass("jcarousel-direction-rtl").attr("dir","rtl");var f=this.options.visible!=null?Math.ceil(this.clipping()/this.options.visible):null;b=this.list.children("li");var g= this;if(b.size()>0){var j=0;e=this.options.offset;b.each(function(){g.format(this,e++);j+=g.dimension(this,f)});this.list.css(this.wh,j+100+"px");if(!c||c.size===undefined)this.options.size=b.size()}this.container.css("display","block");this.buttonNext.css("display","block");this.buttonPrev.css("display","block");this.funcNext=function(){g.next()};this.funcPrev=function(){g.prev()};this.funcResize=function(){g.reload()};this.options.initCallback!=null&&this.options.initCallback(this,"init");if(!q&&  i.browser.safari){this.buttons(false,false);i(window).bind("load.jcarousel",function(){g.setup()})}else this.setup()};var h=i.jcarousel;h.fn=h.prototype={jcarousel:"0.2.5"};h.fn.extend=h.extend=i.extend;h.fn.extend({setup:function(){this.prevLast=this.prevFirst=this.last=this.first=null;this.animating=false;this.tail=this.timer=null;this.inTail=false;if(!this.locked){this.list.css(this.lt,this.pos(this.options.offset)+"px");var a=this.pos(this.options.start);this.prevFirst=this.prevLast=null;this.animate(a, false);i(window).unbind("resize.jcarousel",this.funcResize).bind("resize.jcarousel",this.funcResize)}},reset:function(){this.list.empty();this.list.css(this.lt,"0px");this.list.css(this.wh,"10px");this.options.initCallback!=null&&this.options.initCallback(this,"reset");this.setup()},reload:function(){this.tail!=null&&this.inTail&&this.list.css(this.lt,h.intval(this.list.css(this.lt))+this.tail);this.tail=null;this.inTail=false;this.options.reloadCallback!=null&&this.options.reloadCallback(this);if(this.options.visible!= null){var a=this,c=Math.ceil(this.clipping()/this.options.visible),b=0,d=0;this.list.children("li").each(function(e){b+=a.dimension(this,c);if(e+1<a.first)d=b});this.list.css(this.wh,b+"px");this.list.css(this.lt,-d+"px")}this.scroll(this.first,false)},lock:function(){this.locked=true;this.buttons()},unlock:function(){this.locked=false;this.buttons()},size:function(a){if(a!=undefined){this.options.size=a;this.locked||this.buttons()}return this.options.size},has:function(a,c){if(c==undefined||!c)c= a;if(this.options.size!==null&&c>this.options.size)c=this.options.size;for(var b=a;b<=c;b++){var d=this.get(b);if(!d.length||d.hasClass("jcarousel-item-placeholder"))return false}return true},get:function(a){return i(".jcarousel-item-"+a,this.list)},add:function(a,c){var b=this.get(a),d=0,e=i(c);if(b.length==0){var f;b=this.create(a);for(var g=h.intval(a);f=this.get(--g);)if(g<=0||f.length){g<=0?this.list.prepend(b):f.after(b);break}}else d=this.dimension(b);if(e.get(0).nodeName.toUpperCase()=="LI"){b.replaceWith(e); b=e}else b.empty().append(c);this.format(b.removeClass(this.className("jcarousel-item-placeholder")),a);e=this.options.visible!=null?Math.ceil(this.clipping()/this.options.visible):null;d=this.dimension(b,e)-d;a>0&&a<this.first&&this.list.css(this.lt,h.intval(this.list.css(this.lt))-d+"px");this.list.css(this.wh,h.intval(this.list.css(this.wh))+d+"px");return b},remove:function(a){var c=this.get(a);if(!(!c.length||a>=this.first&&a<=this.last)){var b=this.dimension(c);a<this.first&&this.list.css(this.lt, h.intval(this.list.css(this.lt))+b+"px");c.remove();this.list.css(this.wh,h.intval(this.list.css(this.wh))-b+"px")}},next:function(){this.stopAuto();this.tail!=null&&!this.inTail?this.scrollTail(false):this.scroll((this.options.wrap=="both"||this.options.wrap=="last")&&this.options.size!=null&&this.last==this.options.size?1:this.first+this.options.scroll)},prev:function(){this.stopAuto();this.tail!=null&&this.inTail?this.scrollTail(true):this.scroll((this.options.wrap=="both"||this.options.wrap== "first")&&this.options.size!=null&&this.first==1?this.options.size:this.first-this.options.scroll)},scrollTail:function(a){if(!(this.locked||this.animating||!this.tail)){var c=h.intval(this.list.css(this.lt));!a?c-=this.tail:c+=this.tail;this.inTail=!a;this.prevFirst=this.first;this.prevLast=this.last;this.animate(c)}},scroll:function(a,c){this.locked||this.animating||this.animate(this.pos(a),c)},pos:function(a){var c=h.intval(this.list.css(this.lt));if(this.locked||this.animating)return c;if(this.options.wrap!= "circular")a=a<1?1:this.options.size&&a>this.options.size?this.options.size:a;for(var b=this.first>a,d=this.options.wrap!="circular"&&this.first<=1?1:this.first,e=b?this.get(d):this.get(this.last),f=b?d:d-1,g=null,j=0,l=false,k=0;b?--f>=a:++f<a;){g=this.get(f);l=!g.length;if(g.length==0){g=this.create(f).addClass(this.className("jcarousel-item-placeholder"));e[b?"before":"after"](g);if(this.first!=null&&this.options.wrap=="circular"&&this.options.size!==null&&(f<=0||f>this.options.size)){e=this.get(this.index(f)); if(e.length)g=this.add(f,e.clone(true))}}e=g;k=this.dimension(g);if(l)j+=k;if(this.first!=null&&(this.options.wrap=="circular"||f>=1&&(this.options.size==null||f<=this.options.size)))c=b?c+k:c-k}d=this.clipping();var o=[],n=0;f=a;var m=0;for(e=this.get(a-1);++n;){g=this.get(f);l=!g.length;if(g.length==0){g=this.create(f).addClass(this.className("jcarousel-item-placeholder"));e.length==0?this.list.prepend(g):e[b?"before":"after"](g);if(this.first!=null&&this.options.wrap=="circular"&&this.options.size!== null&&(f<=0||f>this.options.size)){e=this.get(this.index(f));if(e.length)g=this.add(f,e.clone(true))}}e=g;k=this.dimension(g);if(k==0)throw Error("jCarousel: No width/height set for items. This will cause an infinite loop. Aborting...");if(this.options.wrap!="circular"&&this.options.size!==null&&f>this.options.size)o.push(g);else if(l)j+=k;m+=k;if(m>=d)break;f++}for(g=0;g<o.length;g++)o[g].remove();if(j>0){this.list.css(this.wh,this.dimension(this.list)+j+"px");if(b){c-=j;this.list.css(this.lt,h.intval(this.list.css(this.lt))- j+"px")}}j=a+n-1;if(this.options.wrap!="circular"&&this.options.size&&j>this.options.size)j=this.options.size;if(f>j){n=0;f=j;for(m=0;++n;){g=this.get(f--);if(!g.length)break;m+=this.dimension(g);if(m>=d)break}}f=j-n+1;if(this.options.wrap!="circular"&&f<1)f=1;if(this.inTail&&b){c+=this.tail;this.inTail=false}this.tail=null;if(this.options.wrap!="circular"&&j==this.options.size&&j-n+1>=1){b=h.margin(this.get(j),!this.options.vertical?"marginRight":"marginBottom");if(m-b>d)this.tail=m-d-b}for(;a-- > f;)c+=this.dimension(this.get(a));this.prevFirst=this.first;this.prevLast=this.last;this.first=f;this.last=j;return c},animate:function(a,c){if(!(this.locked||this.animating)){this.animating=true;var b=this,d=function(){b.animating=false;a==0&&b.list.css(b.lt,0);if(b.options.wrap=="circular"||b.options.wrap=="both"||b.options.wrap=="last"||b.options.size==null||b.last<b.options.size)b.startAuto();b.buttons();b.notify("onAfterAnimation");if(b.options.wrap=="circular"&&b.options.size!==null)for(var e= b.prevFirst;e<=b.prevLast;e++)if(e!==null&&!(e>=b.first&&e<=b.last)&&(e<1||e>b.options.size))b.remove(e)};this.notify("onBeforeAnimation");if(!this.options.animation||c==false){this.list.css(this.lt,a+"px");d()}else this.list.animate(!this.options.vertical?this.options.rtl?{right:a}:{left:a}:{top:a},this.options.animation,this.options.easing,d)}},startAuto:function(a){if(a!=undefined)this.options.auto=a;if(this.options.auto==0)return this.stopAuto();if(this.timer==null){var c=this;this.timer=setTimeout(function(){c.next()}, this.options.auto*1E3)}},stopAuto:function(){if(this.timer!=null){clearTimeout(this.timer);this.timer=null}},buttons:function(a,c){if(a==undefined||a==null){a=!this.locked&&this.options.size!==0&&(this.options.wrap&&this.options.wrap!="first"||this.options.size==null||this.last<this.options.size);if(!this.locked&&(!this.options.wrap||this.options.wrap=="first")&&this.options.size!=null&&this.last>=this.options.size)a=this.tail!=null&&!this.inTail}if(c==undefined||c==null){c=!this.locked&&this.options.size!== 0&&(this.options.wrap&&this.options.wrap!="last"||this.first>1);if(!this.locked&&(!this.options.wrap||this.options.wrap=="last")&&this.options.size!=null&&this.first==1)c=this.tail!=null&&this.inTail}var b=this;this.buttonNext[a?"bind":"unbind"](this.options.buttonNextEvent+".jcarousel",this.funcNext)[a?"removeClass":"addClass"](this.className("jcarousel-next-disabled")).attr("disabled",a?false:true);this.buttonPrev[c?"bind":"unbind"](this.options.buttonPrevEvent+".jcarousel",this.funcPrev)[c?"removeClass": "addClass"](this.className("jcarousel-prev-disabled")).attr("disabled",c?false:true);this.options.buttonNextCallback!=null&&this.buttonNext.data("jcarouselstate")!=a&&this.buttonNext.each(function(){b.options.buttonNextCallback(b,this,a)}).data("jcarouselstate",a);this.options.buttonPrevCallback!=null&&this.buttonPrev.data("jcarouselstate")!=c&&this.buttonPrev.each(function(){b.options.buttonPrevCallback(b,this,c)}).data("jcarouselstate",c)},notify:function(a){var c=this.prevFirst==null?"init":this.prevFirst< this.first?"next":"prev";this.callback("itemLoadCallback",a,c);if(this.prevFirst!==this.first){this.callback("itemFirstInCallback",a,c,this.first);this.callback("itemFirstOutCallback",a,c,this.prevFirst)}if(this.prevLast!==this.last){this.callback("itemLastInCallback",a,c,this.last);this.callback("itemLastOutCallback",a,c,this.prevLast)}this.callback("itemVisibleInCallback",a,c,this.first,this.last,this.prevFirst,this.prevLast);this.callback("itemVisibleOutCallback",a,c,this.prevFirst,this.prevLast, this.first,this.last)},callback:function(a,c,b,d,e,f,g){if(!(this.options[a]==undefined||typeof this.options[a]!="object"&&c!="onAfterAnimation")){var j=typeof this.options[a]=="object"?this.options[a][c]:this.options[a];if(i.isFunction(j)){var l=this;if(d===undefined)j(l,b,c);else if(e===undefined)this.get(d).each(function(){j(l,this,d,b,c)});else for(var k=d;k<=e;k++)k!==null&&!(k>=f&&k<=g)&&this.get(k).each(function(){j(l,this,k,b,c)})}}},create:function(a){return this.format("<li></li>",a)},format:function(a, c){a=i(a);for(var b=a.get(0).className.split(" "),d=0;d<b.length;d++)b[d].indexOf("jcarousel-")!=-1&&a.removeClass(b[d]);a.addClass(this.className("jcarousel-item")).addClass(this.className("jcarousel-item-"+c)).css({"float":this.options.rtl?"right":"left","list-style":"none"}).attr("jcarouselindex",c);return a},className:function(a){return a+" "+a+(!this.options.vertical?"-horizontal":"-vertical")},dimension:function(a,c){var b=a.jquery!=undefined?a[0]:a,d=!this.options.vertical?(b.offsetWidth|| h.intval(this.options.itemFallbackDimension))+h.margin(b,"marginLeft")+h.margin(b,"marginRight"):(b.offsetHeight||h.intval(this.options.itemFallbackDimension))+h.margin(b,"marginTop")+h.margin(b,"marginBottom");if(c==undefined||d==c)return d;d=!this.options.vertical?c-h.margin(b,"marginLeft")-h.margin(b,"marginRight"):c-h.margin(b,"marginTop")-h.margin(b,"marginBottom");i(b).css(this.wh,d+"px");return this.dimension(b)},clipping:function(){return!this.options.vertical?this.clip[0].offsetWidth-h.intval(this.clip.css("borderLeftWidth"))- h.intval(this.clip.css("borderRightWidth")):this.clip[0].offsetHeight-h.intval(this.clip.css("borderTopWidth"))-h.intval(this.clip.css("borderBottomWidth"))},index:function(a,c){if(c==undefined)c=this.options.size;return Math.round(((a-1)/c-Math.floor((a-1)/c))*c)+1}});h.extend({defaults:function(a){return i.extend(p,a||{})},margin:function(a,c){if(!a)return 0;var b=a.jquery!=undefined?a[0]:a;if(c=="marginRight"&&i.browser.safari){var d={display:"block","float":"none",width:"auto"},e,f;i.swap(b,d, function(){e=b.offsetWidth});d.marginRight=0;i.swap(b,d,function(){f=b.offsetWidth});return f-e}return h.intval(i.css(b,c))},intval:function(a){a=parseInt(a);return isNaN(a)?0:a}})})(jQuery);


/*!
 * jQuery Tools v1.2.6 - The missing UI library for the Web
 * 
 * tabs/tabs.js
 * 
 * NO COPYRIGHTS OR LICENSES. DO WHAT YOU LIKE.
 * 
 * http://flowplayer.org/tools/
 * 
 */
(function(a){a.tools=a.tools||{version:"v1.2.6"},a.tools.tabs={conf:{tabs:"a",current:"current",onBeforeClick:null,onClick:null,effect:"default",initialIndex:0,event:"click",rotate:!1,slideUpSpeed:400,slideDownSpeed:400,history:!1},addEffect:function(a,c){b[a]=c}};var b={"default":function(a,b){this.getPanes().hide().eq(a).show(),b.call()},fade:function(a,b){var c=this.getConf(),d=c.fadeOutSpeed,e=this.getPanes();d?e.fadeOut(d):e.hide(),e.eq(a).fadeIn(c.fadeInSpeed,b)},slide:function(a,b){var c=this.getConf();this.getPanes().slideUp(c.slideUpSpeed),this.getPanes().eq(a).slideDown(c.slideDownSpeed,b)},ajax:function(a,b){this.getPanes().eq(0).load(this.getTabs().eq(a).attr("href"),b)}},c,d;a.tools.tabs.addEffect("horizontal",function(b,e){if(!c){var f=this.getPanes().eq(b),g=this.getCurrentPane();d||(d=this.getPanes().eq(0).width()),c=!0,f.show(),g.animate({width:0},{step:function(a){f.css("width",d-a)},complete:function(){a(this).hide(),e.call(),c=!1}}),g.length||(e.call(),c=!1)}});function e(c,d,e){var f=this,g=c.add(this),h=c.find(e.tabs),i=d.jquery?d:c.children(d),j;h.length||(h=c.children()),i.length||(i=c.parent().find(d)),i.length||(i=a(d)),a.extend(this,{click:function(c,d){var i=h.eq(c);typeof c=="string"&&c.replace("#","")&&(i=h.filter("[href*="+c.replace("#","")+"]"),c=Math.max(h.index(i),0));if(e.rotate){var k=h.length-1;if(c<0)return f.click(k,d);if(c>k)return f.click(0,d)}if(!i.length){if(j>=0)return f;c=e.initialIndex,i=h.eq(c)}if(c===j)return f;d=d||a.Event(),d.type="onBeforeClick",g.trigger(d,[c]);if(!d.isDefaultPrevented()){b[e.effect].call(f,c,function(){j=c,d.type="onClick",g.trigger(d,[c])}),h.removeClass(e.current),i.addClass(e.current);return f}},getConf:function(){return e},getTabs:function(){return h},getPanes:function(){return i},getCurrentPane:function(){return i.eq(j)},getCurrentTab:function(){return h.eq(j)},getIndex:function(){return j},next:function(){return f.click(j+1)},prev:function(){return f.click(j-1)},destroy:function(){h.unbind(e.event).removeClass(e.current),i.find("a[href^=#]").unbind("click.T");return f}}),a.each("onBeforeClick,onClick".split(","),function(b,c){a.isFunction(e[c])&&a(f).bind(c,e[c]),f[c]=function(b){b&&a(f).bind(c,b);return f}}),e.history&&a.fn.history&&(a.tools.history.init(h),e.event="history"),h.each(function(b){a(this).bind(e.event,function(a){f.click(b,a);return a.preventDefault()})}),i.find("a[href^=#]").bind("click.T",function(b){f.click(a(this).attr("href"),b)}),location.hash&&e.tabs=="a"&&c.find("[href="+location.hash+"]").length?f.click(location.hash):(e.initialIndex===0||e.initialIndex>0)&&f.click(e.initialIndex)}a.fn.tabs=function(b,c){var d=this.data("tabs");d&&(d.destroy(),this.removeData("tabs")),a.isFunction(c)&&(c={onBeforeClick:c}),c=a.extend({},a.tools.tabs.conf,c),this.each(function(){d=new e(a(this),b,c),a(this).data("tabs",d)});return c.api?d:this}})(jQuery);


/*!
 * jQuery Tools v1.2.6 - The missing UI library for the Web
 * 
 * toolbox/toolbox.history.js
 * 
 * NO COPYRIGHTS OR LICENSES. DO WHAT YOU LIKE.
 * 
 * http://flowplayer.org/tools/
 * 
 */
(function(a){var b,c,d,e;a.tools=a.tools||{version:"v1.2.6"},a.tools.history={init:function(g){e||(a.browser.msie&&a.browser.version<"8"?c||(c=a("<iframe/>").attr("src","javascript:false;").hide().get(0),a("body").prepend(c),setInterval(function(){var d=c.contentWindow.document,e=d.location.hash;b!==e&&a(window).trigger("hash",e)},100),f(location.hash||"#")):setInterval(function(){var c=location.hash;c!==b&&a(window).trigger("hash",c)},100),d=d?d.add(g):g,g.click(function(b){var d=a(this).attr("href");c&&f(d);if(d.slice(0,1)!="#"){location.href="#"+d;return b.preventDefault()}}),e=!0)}};function f(a){if(a){var b=c.contentWindow.document;b.open().close(),b.location.hash=a}}a(window).bind("hash",function(c,e){e?d.filter(function(){var b=a(this).attr("href");return b==e||b==e.replace("#","")}).trigger("history",[e]):d.eq(0).trigger("history",[e]),b=e}),a.fn.history=function(b){a.tools.history.init(this);return this.bind("history",b)}})(jQuery);


jQuery.fn.center = function() {
var w = $(window);
this.css("position","absolute");
this.css("top",(w.height()-this.height())/2+w.scrollTop() + "px");
this.css("left",(w.width()-this.width())/2+w.scrollLeft() + "px");
return this;
}

jQuery.fn.setDocumentHeight = function() {
var w = $(window);
var d = $('html');
var h = d.height() > w.height() ? d.height() : w.height();
h = h > $(document).height() ? h : $(document).height();
this.height(h);
return this;
}

jQuery.fn.setDocumentWidth = function() {
var w = $(window);
var d = $('html');
var h = d.width() > w.width() ? d.width() : w.width();
h = h > $(document).width() ? h : $(document).width();
this.width(h);
return this;
}

var PopupBoxManager = function()
{
	this.popupboxLastZindex = 1900;
	this.lastId = 0;
	this.boxCollection = {};
	$(document).keyup($.proxy(this.onKeyPress, this));
};

PopupBoxManager.prototype = {
	count: function() {
		var count = 0;
		
		for (var i in this.boxCollection) {
			count++;
		}
		
		return count;
	},

	create: function(text, header, options) {
		return new PopupBox(text, header, options);
	},

	load: function(params) {
		$.ajax(params.url, {
			type: !!params.data ? 'post' : 'get',
			data: params.data,
			success: function(data) {
				new PopupBox(data, params.header, params.options);
			}
		});
	},

	add: function(box) {
		this.boxCollection[box.id] = box;
		this.lastId = box.id;
		this.popupboxLastZindex += 10;
	},

	remove: function(box) {
		delete this.boxCollection[box.id];
	},
	
	closeLast: function(time) {
		var zIndex = 0;
		var lastBox;
		$.each(this.boxCollection, function(i, box) {
			if (box.zIndex > zIndex) {
				zIndex = box.zIndex;
				lastBox = box;
			}
		});
		if (lastBox) {
			lastBox.close(time);
		}
	},

	onKeyPress: function(e) {
		var zIndex = 0;
		var lastBox;
		$.each(this.boxCollection, function(i, box) {
			if (box.zIndex > zIndex) {
				zIndex = box.zIndex;
				lastBox = box;
			}
		});

		if (lastBox) {
			var code = e.keyCode || e.which;
			if (lastBox.onKeyPress(e) !== false) {
				if (code == 27) {
					lastBox.close();
				}
			}
		}
	}
}

$.popupBoxManager = new PopupBoxManager();

var PopupBox = function(content, header, options) {
	
	var defaults = {
		closeCallback : function() {},
		contentMaxHeight : false,
		contentMinWidth : false,
		boxClass: '',
		keyPressCallback : function() {},
		callback : function() {}
	};

	if (!!options) {
		var options = $.extend(defaults, options);
	} else {
		var options = defaults;
	}
	
	this.options = options;
	
	if(!header) {
		var header = '&nbsp;';
	}

	this.id = $.popupBoxManager.lastId + 1;
	this.zIndex = $.popupBoxManager.popupboxLastZindex;
	
	this.onClose = options.closeCallback;
	this.onKeyPress = options.keyPressCallback;

	$('body').append('<div class="popup-box-container"><div class="popup-box ' + options.boxClass + '" style="z-index:'+(this.zIndex+1)+'"></div></div>');
	$('body').append('<div class="popup-overlay" style="z-index:'+(this.zIndex)+'"></div>');

	this.block = $('.popup-box').last();
	this.overlay = $('.popup-overlay').last();

	$(this.block).append('<a href="#" class="x">&times;</a>');
	$(this.block).append('<h2>'+header+'</h2>');
	
	$(this.block).append('<div class="content" style="'
							+ (options.contentMaxHeight ? 'max-height:' + (parseInt(options.contentMaxHeight) ? options.contentMaxHeight + 'px' : options.contentMaxHeight )+';' : '')
							+ (options.contentMinWidth ? 'min-width:' + (parseInt(options.contentMinWidth) ? options.contentMinWidth + 'px' : options.contentMinWidth )+';' : '')
							+'"></div>');

	$(this.block).children(".content").html( content );
	//$(this.block).find(".content").focus();
	$(this.overlay).show();
	var box = this;
	$(this.block).children('.x').click( function(){box.close(300);return false;});
	$(this.overlay).unbind('click').click(function(){box.close(300);return false;});

	box.center();
	$(this.overlay).setDocumentHeight();
	$(this.overlay).setDocumentWidth();
	$(window).scroll(function(){
		box.center();
		$(box.overlay).setDocumentHeight();
	});

	$(window).resize(function(){
		box.center();
		$(box.overlay).setDocumentHeight();
		$(box.overlay).setDocumentWidth();
	});
	
	$.popupBoxManager.add(this);
	
	$.proxy(this.options.callback, this)();
};

PopupBox.prototype = {
	disableMaxHeight: function() {
		$(this.block).find('.content').css('max-height', 'none');
	},

	center: function() {
		$(this.block).parent().center();
	},

	headerHeight: function() {
		return $(this.block).find('h2').height() + parseInt($(this.block).find('h2').css('padding-top')) + parseInt($(this.block).find('h2').css('padding-bottom'));
	},
	
	contentPaddingHeight: function() {
		return parseInt($(this.block).find('.content').css('padding-top')) + parseInt($(this.block).find('.content').css('padding-bottom'))
	},

	close: function(val) {
		if(!val) {
			val = 0;
		}

		var box = this;
		$(this.block).fadeOut(val, function(){$(box.overlay).detach();});
		$(this.block).parent().detach();

		if (!$.popupBoxManager.count()) {
			$(window).unbind('scroll');
		}

		this.onClose();
		
		$.popupBoxManager.remove(this);
	}
};

var FormPopupBox = function(params)
{
	var onBoxLoad = function() {
		var form = $(this.block).find('.content').find('form');
		if (!form.length) return;
		var box = this;
		
		form.find("input[type=text],textarea").first().focus();
		
		form.submit(function(event) {
			event.preventDefault();
			event.stopPropagation();
			
			if ($(this).attr('action')) {
				var newparams = params;
				newparams.url = $(this).attr('action');
				newparams.data = $(this).serialize();
				new FormPopupBox(newparams);
			} else {
				if (params.submitCallback) {
					$.proxy(params.submitCallback, this)(event);
				}
			}
			
			box.close();
		});
	};

	if (!params.options) {
		params.options = {};
	}
	
	if (!params.callback) {
		params.options.callback = onBoxLoad;
	} else {
		params.options.callback = function() {
			$.proxy(params.callback,this)();
			$.proxy(onBoxLoad,this)();
		};
	}

	if (!params.url) {
		$.popupBoxManager.create(params.content, params.header, params.options);
	} else {
		$.popupBoxManager.load({
			url : params.url,
			data : params.data,
			header : params.header,
			options : params.options
		});
	}
};


jQuery.fn.imagesBox = function(previewTarget, options)
{
	var defaults = {
		popupBox: true,
		imagesPopupBoxOptions: {}
	};

	if (!!options) {
		var options = $.extend(defaults, options);
	} else {
		var options = defaults;
	}
	
	this.options = options;
	
	var first = $(this).children('li').first();
	
	this.previewTarget = previewTarget;
	$(this.previewTarget).attr('href', $(first).attr('href'));
	
	if (this.options.popupBox) {
		$(this.previewTarget).click($.proxy(function (e) {
			new ImagesPopupBox(this, $(e.currentTarget).attr('href'), this.options.imagesPopupBoxOptions);
			return false;
		}, this));
	} else {
		$(this.previewTarget).click(function(){return false;});
	}
	
	if (this.length > 0) {
		$(this).children('li').each($.proxy(function (i, val) {
			$(val).find('a').hover($.proxy(function(e) {
				var el = e.currentTarget;
				var newpreview = $(el).next().attr('src');
				
				if ($(this.previewTarget).find('img').attr('src') != newpreview)
				$(this.previewTarget).find('img').animate({
					opacity: 0
				  }, 200, $.proxy(function(e) {
					$(this.previewTarget).find('img').attr('src', newpreview);
					$(this.previewTarget).find('img').animate({
						opacity: 1
					}, 200);
				}, this));
				
				// $(this.previewTarget).find('img').attr('src', $(el).next().attr('src'));
				$(this.previewTarget).attr('href', $(el).attr('href'));
				$(this).children('li').removeClass('active');
				$(el).parent().addClass('active');
			}, this));
			
			if (this.options.popupBox) {
				$(val).find('a').click($.proxy(function(e) {
					var el = e.currentTarget;
					
					$(this).children('li').removeClass('active');
					$(el).parent().addClass('active');
					new ImagesPopupBox(this, $(e.currentTarget).attr('href'), this.options.imagesPopupBoxOptions);
				
					return false;
				}, this));
			} else {
				$(val).find('a').click(function(){return false});
			}
		}, this));
	}
	return this;
}

var ImagesPopupBox = function(listTarget, image, options)
{
	this.listTarget = $(listTarget);
	
	var defaults = {
		imageBlockHeight: 600,
		imageBlockWidth: 600,
		title: 'Просмотр фото'
	};

	var options = $.extend(defaults, options);
	this.options = options;
	
	this.imageBlockHeight = this.options.imageBlockHeight;
	this.imageBlockWidth = this.options.imageBlockWidth;

	var html = $(this.listTarget).html();
	
	this.currentImage = image;

	if (this.listTarget.length) {
		html = '<ul class="popup-images-box-list">'+html+'</ul>';
		
		html = '<table class="popup-images-box-header"><tr><td class="pr"><a href="#" class="popup-images-box-prev"></a></td>' 
				+ '<td class="cn">' 
				+ html 
				+ '</td><td class="nx"><a href="#" class="popup-images-box-next"></a></td></tr></table>'
		; 
	} else {
		html = '';
	}
	
	html += '<table width="100%" cellspacing="0" cellpadding="0"><tr><td class="popup-images-image-show popup-images-image-show-loading"></td></tr></table>';
	html = '<div class="popup-images-box">' + html + '</div>';
	
	this.box = new PopupBox(html, this.options.title, {
		contentMaxHeight : 'none',
		contentMinWidth: this.imageBlockWidth,
		keyPressCallback : $.proxy(function(e) {
			var code = e.keyCode || e.which;
			switch (code) {
				case 37:
					this.prev();
				break;
				case 39:
					this.next();
				break;
			}
			
			//return false;
		}, this)
	});
	
	this.setImage(image);
	
	$(window).resize($.proxy(this.onResize, this));
	
	if (!!this.listTarget.length) {
		$('.popup-images-box-list li a').click($.proxy(this.clickBoxImage, this));
		
		$('.popup-images-box-prev').click($.proxy(this.prev, this));
		
		$('.popup-images-box-next').click($.proxy(this.next, this));
		
		var maxImageHeightVal = this.maxImageHeight();
		if (this.imageBlockHeight < maxImageHeightVal) {
			$('.popup-images-image-show').height(this.imageBlockHeight);
		} else {
			$('.popup-images-image-show').height(maxImageHeightVal);
		}
	}
}

ImagesPopupBox.prototype.maxImageHeight = function()
{
	var winHeight = $(window).height();
	var maxBoxHeight = winHeight - 50;
	var maxBoxHeaderHeight = this.box.headerHeight();
	
	maxBoxHeaderHeight += $(this.box.block).find('.popup-images-box-header').height();
	var maxImageHeightVal = maxBoxHeight - maxBoxHeaderHeight;
	maxImageHeightVal -= this.box.contentPaddingHeight();
	
	return maxImageHeightVal;
}

ImagesPopupBox.prototype.onResize = function(){
	var maxImageHeightVal = this.maxImageHeight();

	var heavyImage = new Image(); 
	heavyImage.src = $('.popup-images-image-show img').attr('src');
	var imageHeight = heavyImage.height;

	if (imageHeight > maxImageHeightVal) {
		imageHeight = maxImageHeightVal;
	}
	var _new = imageHeight;
	if (this.imageBlockHeight < maxImageHeightVal) {
		$('.popup-images-image-show').height(this.imageBlockHeight);
	} else {
		$('.popup-images-image-show').height(maxImageHeightVal);
	}
	
	$('.popup-images-image-show img').height(imageHeight);
	
	this.box.center();
}

ImagesPopupBox.prototype.setImage = function(image)
{
	var heavyImage = new Image(); 
	
	heavyImage.src = image;
	
	this.currentImage = image;
	
	$(this.box.block).find(".popup-images-image-show").html('');
	$(this.box.block).find(".popup-images-image-show").addClass('popup-images-image-show-loading');
	
	if (heavyImage.height > 0) {
		this.showImage(heavyImage);
	}
	
	$(heavyImage).load($.proxy(this.onImageLoad, this));
	
	// this.box.center();
};

ImagesPopupBox.prototype.onImageLoad = function (e) {
	var img = e.currentTarget;

	this.showImage(img);
}

ImagesPopupBox.prototype.showImage = function (img) {
	var maxImageHeightVal = this.maxImageHeight();
	var imageHeight = img.height;
	
	var maxHeight = imageHeight;
	
	if (imageHeight > maxImageHeightVal) {
		imageHeight = maxImageHeightVal;
	}
	
	$('.popup-images-image-show').html('<img src="'+$(img).attr('src')+'" alt="" style="max-height:'+maxHeight+'px;height:'+imageHeight+'px;" />');
	$('.popup-images-image-show').removeClass('popup-images-image-show-loading');
	
	this.box.center();
};

ImagesPopupBox.prototype.clickBoxImage = function(e)
{
	var list = $(this.box.block).find('.popup-images-box-list');
	var img_el = e.currentTarget;
	
	$(list).find('li').removeClass('active');
	$(img_el).parent().addClass('active');
	this.setImage($(img_el).attr('href'));
	
	return false;
};

ImagesPopupBox.prototype.prev = function()
{
	var list = $(this.box.block).find('.popup-images-box-list');
	
	if (!list.length) return false;
	
	if ($(list).find('.active').prev().length) {
		var prev = $(list).find('.active').prev();
		$(list).find('li').removeClass('active');
		$(prev).addClass('active');
		this.setImage($(prev).find('a').attr('href'));
	} else {
		this.setImage($(list).find('li').last().find('a').attr('href'));
		$(list).find('li').removeClass('active');
		$(list).find('li').last().addClass('active');
	}
	
	return false;
};

ImagesPopupBox.prototype.next = function()
{
	var list = $(this.box.block).find('.popup-images-box-list');
	
	if (!list.length) return false;
	
	if ($(list).find('.active').next().length) {
		var next = $(list).find('.active').next();
		$(list).find('li').removeClass('active');
		$(next).addClass('active');
		this.setImage($(next).find('a').attr('href'));
	} else {
		this.setImage($(list).find('li').first().find('a').attr('href'));
		$(list).find('li').removeClass('active');
		$(list).find('li').first().addClass('active');
	}
	
	return false;
};

/* SITE LOGIC */

function checkForm(form)
{
	var valid = true;
		
	$(form).find('input[type=text], textarea').each(function(key, item) {
		if ($(item).hasClass('required') && !$(item).val()) {
			valid = false;
			$(item).addClass('emptyfield');
		} else {
			$(item).removeClass('emptyfield');
		}
	});
	
	return valid;
}

$(document).ajaxComplete(function(event, request, settings) {
	$(".loading-overlay").detach();
});

$(document).ajaxSend(function(event, jqXHR, ajaxOptions) {
	$('body').append('<div class="loading-overlay"></div>');
	$('.loading-overlay').setDocumentHeight();
});

$(document).ajaxError(function(event, jqXHR, ajaxSettings, thrownError) {
	var p = (new PopupBox(jqXHR.responseText, "Ошибка", {
		boxClass: 'popup-box-error'
	}));
	$(".loading-overlay").detach();
});

$.fn.multiBanner = function(options) {
	$.extend({
		delay: 5000,
		width: 0,
		height: 0,
		arrows: false
	}, options);
	
	if (options.width) {
		$(this).width(options.width);
	}
	
	if (options.height) {
		$(this).height(options.height);
	}
	
	var timeout_id;
	var var_pos_last = 0;
	var var_pos_switch = '';
	var var_interval = options.delay;
	
	var multibanners = $(this).find('.banner');
	var multibanners_count = multibanners.length;
	if (multibanners_count <= 1) {
		return false;
	}
	
	multibanners.each(function(){
		$(this).attr('pos', ++var_pos_last);
		var_pos_switch += '<span pos="'+var_pos_last+'">&nbsp;</span>';
	});

	$(this).append('<div class="switch">' + var_pos_switch + '</div>');
	
	var multiswitch = $(this).find('.switch');

	var go_multibanner = function(i) {
		var next = multibanners.filter('[pos='+i+']');

		multiswitch.find('span').removeClass('checked');
		multiswitch.find('span[pos='+i+']').addClass('checked');

		if (next.is(':visible')) return;

		var current = multibanners.filter(':visible');
		current.css('z-index', 2);
		multibanners.each(function(){
			if (!$(this).is(':visible')) {
				$(this).css('z-index', 1);
			}
		});

		next.css('z-index', 3);
		next.fadeIn('slow', function(){
			current.hide();
		});
	}

	multiswitch.find('span').click(function(){
		var pos = $(this).attr('pos');
		go_multibanner(pos);
	});

	multibanners.hide();
	multibanners.first().show();
	i = multibanners.first().attr('pos');
	multiswitch.find('span').removeClass('checked');
	multiswitch.find('span[pos='+i+']').addClass('checked');

	var go_multibanner_next = function(next) {
		var current = multibanners.filter(':visible');
		var i = current.attr('pos') - 0;

		if (i < multibanners_count) {
			go_multibanner(i+1);
		} else {
			go_multibanner(1);
		}
		
		clearTimeout(timeout_id);
		timeout_id = setTimeout(go_multibanner_next, var_interval);
	}
	
	if (options.arrows) {
		$(this).append('<a class="next" href="#"></a>');
		$(this).append('<a class="prev" href="#"></a>');
		
		var prev = $(this).find('.prev');
		var next = $(this).find('.next');
		
		prev.on('click', function() {
			//go_multibanner_next(-1);
			if (!next) next = 1; 
			var current = multibanners.filter(':visible');
			var i = current.attr('pos') - 0;

			if (i > 1) {
				go_multibanner(i-1);
			} else {
				go_multibanner(multibanners_count);
			}
			
			return false;
		});
		
		next.on('click', function() {
			var current = multibanners.filter(':visible');
			var i = current.attr('pos') - 0;
			
			if (i < multibanners_count) {
				go_multibanner(i+1);
			} else {
				go_multibanner(1);
			}
			
			return false;
		});
	}

	timeout_id = setTimeout(go_multibanner_next, var_interval);
	
	$(this).hover(function() {
		clearTimeout(timeout_id);
	}, function() {
		timeout_id = setTimeout(go_multibanner_next, var_interval);
	});
}


$(document).ready(function() {
	$('.search-input').focus(function() {
		$(this).parent().parent().addClass('search-form-focus');
	});
	
	$('.search-input').blur(function() {
		$(this).parent().parent().removeClass('search-form-focus');
		
		if (!$(this).val()) {
			$(this).parent().find('label').show();
		}
	});
	
	$('.search-input').keyup(function() {
		if (!$(this).val()) {
			$(this).parent().find('label').show();
		} else {
			$(this).parent().find('label').fadeOut();
		}
	});
	
	$('.search-input').each(function() {
		if ($(this).val()) {
			$(this).parent().find('label').hide();
		}
	});
	
	$('.sitemap').click(function(event) {
		new FormPopupBox({
			url : '/sitemap/',
			header : 'Карта сайта'
		});
		
		return false;
	});
	
	$('.login').click(function(event) {
		new FormPopupBox({
			url : '/auth/',
			header : 'Вход на сайт'
		});
		
		return false;
	});
	
	$('.forgot').live('click', function(event) {
		new FormPopupBox({
			url : '/auth/forgot/',
			header : 'Вспомнить пароль'
		});
		
		return false;
	});
	
	$('.registration').live('click', function(event) {
		$.popupBoxManager.closeLast();
		new FormPopupBox({
			url : '/auth/reg/',
			header : 'Регистрация'
		});
		
		return false;
	});
	
	$('.profile').live('click', function(event) {
		$.popupBoxManager.closeLast();
		new FormPopupBox({
			url : '/auth/profile/',
			header : 'Профиль'
		});
		
		return false;
	});
	
	$('.wherebuy').live('click', function(event) {
		if ($.popupBoxManager.count() > 0) { 
			new FormPopupBox({
				url : $(this).attr('href'),
				header : 'Как приобрести',
			});
			return false;
		}
	});
	
	$('.shoppingcart').live('click', function(event) {
		if ($.popupBoxManager.count() > 0) {
			$.popupBoxManager.closeLast();
			new FormPopupBox({
				url : '/shoppingcart/',
				header : 'Корзина'
			});
		} else {
			window.location = '/shoppingcart/';
		}
		
		return false;
	});
	
	$('.buy-good-button').live('click', function() {
		/*$.ajax($(this).attr('href'), {
			success: function() {
				new FormPopupBox({
					url : '/shoppingcart/',
					header : 'Корзина'
				});
			}
		});*/
		
		new FormPopupBox({
			url : $(this).attr('href'),
			header : 'Добавление в корзину'
		});
		return false;
	});
	
	$('.shoppingcart-close').live('click', function() {
		if ($.popupBoxManager.count() > 0) { 
			$.popupBoxManager.closeLast();
		} else {
			history.go(-1);
		}
		return false;
	});
	
	$(".shoppingcart-goodoperation").live('click', function(){
		var act = $(this).attr('act');
		if (act != 'goodremove' || confirm('Вы уверены, что хотите удалить товар из корзины?'))
		$.ajax('/shoppingcart/' + act + '/', {
			dataType: 'html',
			type: 'post',
			data: 'id=' + $(this).attr('item_id'),
			success: function(data) {
				if (!$.popupBoxManager.count()) {
					$.ajax('/shoppingcart/', {
						dataType : 'html',
						success: function(data) {
							$('.shoppingcart-wrapper').parent().html(data);
						}
					});
				} else {
					$.popupBoxManager.closeLast();
					new FormPopupBox({
						url : '/shoppingcart/',
						header : 'Корзина'
					});
				}
			}
		});
		
		return false;
	});
	
	$('.cell-number').find('input[type=text]').keydown(function(e) {
		
		var key = e.which ? e.which : e.keyCode;

		if((key < 97 || key > 105) && key != 46 && key != 116 && key != 45 && key > 31 && (key < 48 || key > 57)) {
			return false;
		}
		
		return true;
	});
	
	var setSumByNumber = function() {
		var number = parseInt($(this).val());
		var price = parseFloat($(this).attr('price'));
		
		if (!$(this).val()) {
			number = 0;
			price = 0;
		}
		
		$(this).parent().next().find('.price-value').html(number*price);
		var sum = 0;
		$('.cell-sum').find('.price-value').each(function() {
			sum += parseFloat($(this).html());
		});
		
		$('.shoppingcart-sum').find('.price-value').html(sum);
	};
	
	$('.cell-number').find('input[type=text]').keyup(setSumByNumber);
	
	$('.cell-number').find('input[type=text]').focus(function(){
		$(this).select();
	});
	
	$('.cell-number').find('input[type=text]').each(function() {
		$.proxy(setSumByNumber, this)();
	});
	
});
