/**
 * @author Alexander Farkas
 * v. 1.02
 */

function flashConsole(errorStr){
    if(typeof console != 'undefined' && console && console.log){
		console.log(errorStr);
	}
	
}
function getFlash(flash){
    if (document.all) {
        if (document.all[flash]) {
            return document.all[flash];
        }
        if (window.opera) {
            var movie = eval(window.document + flash);
            if (movie.SetVariable) {
                return movie;
            }
        }
        return;
    }
    if (document.layers) {
        if (document.embeds) {
            var movie = document.embeds[flash];
            if (movie.SetVariable) {
                return movie;
            }
        }
        return;
    }
    if (!document.getElementById) {
        return;
    }
    var movie = document.getElementById(flash);
    if (movie.SetVariable) {
        return movie;
    }
    var movies = movie.getElementsByTagName('embed');
    if (!movies || !movies.length) {
        return;
    }
    movie = movies[0];
    if (movie.SetVariable) {
        return movie;
    }
    return;
}
(function($) {
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];           
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];
            
           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});
})(jQuery);
/**
 * @author trixta
 */
(function($){
	$.extend($.event.special, {
        keyfocus: (function(){
            var focusAllowed = true;
			function mousedown(){
               focusAllowed = false;
			   setTimeout(allowFocus, 99);
            }
			function focus(e){
	            var that = this;
				setTimeout(function(){
					  (focusAllowed && jQuery.event.special.keyfocus.handler.apply(that, [e]));
					  allowFocus();
				}, 0);
            }
			function allowFocus(){
				focusAllowed = true;
			}
            return {
                setup: function(){
					$(this).bind("focus", focus).bind('mousedown', mousedown);
                    return true;
                },
                teardown: function(){
                    $(this).unbind("focus", focus).unbind('mousedown', mousedown);
                    return true;
                },
                handler: function(event){
                    arguments[0].type = "keyfocus";
                    return jQuery.event.handle.apply(this, arguments);
                }
            };
        })()
    });
})(jQuery);


/* Copyright (c) 2006 Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 *
 * $LastChangedDate: 2007-12-20 09:02:08 -0600 (Thu, 20 Dec 2007) $
 * $Rev: 4265 $
 *
 * Version: 3.0
 * 
 * Requires: $ 1.2.2+
 */

(function($) {

$.event.special.mousewheel = {
	setup: function() {
		var handler = $.event.special.mousewheel.handler;
		
		// Fix pageX, pageY, clientX and clientY for mozilla
		if ( $.browser.mozilla )
			$(this).bind('mousemove.mousewheel', function(event) {
				$.data(this, 'mwcursorposdata', {
					pageX: event.pageX,
					pageY: event.pageY,
					clientX: event.clientX,
					clientY: event.clientY
				});
			});
	
		if ( this.addEventListener )
			this.addEventListener( ($.browser.mozilla ? 'DOMMouseScroll' : 'mousewheel'), handler, false);
		else
			this.onmousewheel = handler;
	},
	
	teardown: function() {
		var handler = $.event.special.mousewheel.handler;
		
		$(this).unbind('mousemove.mousewheel');
		
		if ( this.removeEventListener )
			this.removeEventListener( ($.browser.mozilla ? 'DOMMouseScroll' : 'mousewheel'), handler, false);
		else
			this.onmousewheel = function(){};
		
		$.removeData(this, 'mwcursorposdata');
	},
	
	handler: function(event) {
		var args = Array.prototype.slice.call( arguments, 1 );
		
		event = $.event.fix(event || window.event);
		// Get correct pageX, pageY, clientX and clientY for mozilla
		$.extend( event, $.data(this, 'mwcursorposdata') || {} );
		var delta = 0, returnValue = true;
		
		if ( event.wheelDelta ) delta = event.wheelDelta/120;
		if ( event.detail     ) delta = -event.detail/3;
		if ( $.browser.opera  ) delta = -event.wheelDelta;
		
		event.data  = event.data || {};
		event.type  = "mousewheel";
		
		// Add delta to the front of the arguments
		args.unshift(delta);
		// Add event to the front of the arguments
		args.unshift(event);

		return $.event.handle.apply(this, args);
	}
};

$.fn.extend({
	mousewheel: function(fn) {
		return fn ? this.bind("mousewheel", fn) : this.trigger("mousewheel");
	},
	
	unmousewheel: function(fn) {
		return this.unbind("mousewheel", fn);
	}
});

})(jQuery);

/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept == "undefined") var deconcept = new Object();
if(typeof deconcept.util == "undefined") deconcept.util = new Object();
if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = new Object();
deconcept.SWFObject = function(swf, id, w, h, ver, c, quality, xiRedirectUrl, redirectUrl, detectKey) {
	if (!document.getElementById) { return; }
	this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
	this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	if(swf) { this.setAttribute('swf', swf); }
	if(id) { this.setAttribute('id', id); }
	if(w) { this.setAttribute('width', w); }
	if(h) { this.setAttribute('height', h); }
	if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
	this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion();
	if (!window.opera && document.all && this.installedVer.major > 7) {
		// only add the onunload cleanup if the Flash Player version supports External Interface and we are in IE
		deconcept.SWFObject.doPrepUnload = true;
	}
	if(c) { this.addParam('bgcolor', c); }
	var q = quality ? quality : 'high';
	this.addParam('quality', q);
	this.setAttribute('useExpressInstall', false);
	this.setAttribute('doExpressInstall', false);
	var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
	this.setAttribute('xiRedirectUrl', xir);
	this.setAttribute('redirectUrl', '');
	if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
};
deconcept.SWFObject.prototype = {
	useExpressInstall: function(path) {
		this.xiSWFPath = !path ? "expressinstall.swf" : path;
		this.setAttribute('useExpressInstall', true);
	},
	setAttribute: function(name, value){
		this.attributes[name] = value;
	},
	getAttribute: function(name){
		return this.attributes[name];
	},
	addParam: function(name, value){
		this.params[name] = value;
	},
	getParams: function(){
		return this.params;
	},
	addVariable: function(name, value){
		this.variables[name] = value;
	},
	getVariable: function(name){
		return this.variables[name];
	},
	getVariables: function(){
		return this.variables;
	},
	getVariablePairs: function(){
		var variablePairs = new Array();
		var key;
		var variables = this.getVariables();
		for(key in variables){
			variablePairs[variablePairs.length] = key +"="+ variables[key];
		}
		return variablePairs;
	},
	getSWFHTML: function() {
		var swfNode = "";
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "PlugIn");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ this.getAttribute('style') +'"';
			swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
			var params = this.getParams();
			 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
			var pairs = this.getVariablePairs().join("&");
			 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
			swfNode += '/>';
		} else { // PC IE
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "ActiveX");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ this.getAttribute('style') +'">';
			swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
			var params = this.getParams();
			for(var key in params) {
			 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			var pairs = this.getVariablePairs().join("&");
			if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
			swfNode += "</object>";
		}
		return swfNode;
	},
	write: function(elementId){
		if(this.getAttribute('useExpressInstall')) {
			// check to see if we need to do an express install
			var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
			if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
				this.setAttribute('doExpressInstall', true);
				this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
				document.title = document.title.slice(0, 47) + " - Flash Player Installation";
				this.addVariable("MMdoctitle", document.title);
			}
		}
		if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
			var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
			n.innerHTML = this.getSWFHTML();
			return true;
		}else{
			if(this.getAttribute('redirectUrl') != "") {
				document.location.replace(this.getAttribute('redirectUrl'));
			}
		}
		return false;
	}
};

/* ---- detection functions ---- */
deconcept.SWFObjectUtil.getPlayerVersion = function(){
	var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else if (navigator.userAgent && navigator.userAgent.indexOf("Windows CE") >= 0){ // if Windows CE
		var axo = 1;
		var counter = 3;
		while(axo) {
			try {
				counter++;
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+ counter);
//				document.write("player v: "+ counter);
				PlayerVersion = new deconcept.PlayerVersion([counter,0,0]);
			} catch (e) {
				axo = null;
			}
		}
	} else { // Win IE (non mobile)
		// do minor version lookup in IE, but avoid fp6 crashing issues
		// see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		}catch(e){
			try {
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				PlayerVersion = new deconcept.PlayerVersion([6,0,21]);
				axo.AllowScriptAccess = "always"; // error if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
			} catch(e) {
				if (PlayerVersion.major == 6) {
					return PlayerVersion;
				}
			}
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			} catch(e) {}
		}
		if (axo != null) {
			PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
		}
	}
	return PlayerVersion;
};
deconcept.PlayerVersion = function(arrVersion){
	this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
	this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
	this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
};
deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
};
/* ---- get value of query string param ---- */
deconcept.util = {
	getRequestParameter: function(param) {
		var q = document.location.search || document.location.hash;
		if (param == null) { return q; }
		if(q) {
			var pairs = q.substring(1).split("&");
			for (var i=0; i < pairs.length; i++) {
				if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
					return pairs[i].substring((pairs[i].indexOf("=")+1));
				}
			}
		}
		return "";
	}
};
/* fix for video streaming bug */
deconcept.SWFObjectUtil.cleanupSWFs = function() {
	var objects = document.getElementsByTagName("OBJECT");
	for (var i = objects.length - 1; i >= 0; i--) {
		objects[i].style.display = 'none';
		for (var x in objects[i]) {
			if (typeof objects[i][x] == 'function') {
				objects[i][x] = function(){};
			}
		}
	}
};
// fixes bug in some fp9 versions see http://blog.deconcept.com/2006/07/28/swfobject-143-released/
if (deconcept.SWFObject.doPrepUnload) {
	if (!deconcept.unloadSet) {
		deconcept.SWFObjectUtil.prepUnload = function() {
			__flash_unloadHandler = function(){};
			__flash_savedUnloadHandler = function(){};
			window.attachEvent("onunload", deconcept.SWFObjectUtil.cleanupSWFs);
		};
		window.attachEvent("onbeforeunload", deconcept.SWFObjectUtil.prepUnload);
		deconcept.unloadSet = true;
	}
}
/* add document.getElementById if needed (mobile IE < 5) */
if (!document.getElementById && document.all) { document.getElementById = function(id) { return document.all[id]; };}

/* add some aliases for ease of use/backwards compatibility */
var getQueryParamValue = deconcept.util.getRequestParameter;
var FlashObject = deconcept.SWFObject; // for legacy support
var SWFObject = deconcept.SWFObject;

/**
 * @author alexander.farkas
 */
(function($){
    $.fn.extend({
        tab: function(options){
            var args = Array.prototype.slice.call(arguments, 1), tabO;
            if(this.length){
				if (typeof options == "string") {
                    var tab = $.data(this[0], "accordion-tab");
                    tab[options].apply(tab, args);
                }
                else 
                    if (!$.data(this, "accordion-tab")) {
                         tabO = new $.tab(this, options);
                    }
			}
			return this.each(function(){
                if (!$.data(this, "accordion-tab") && tabO) {
                    $.data(this, "accordion-tab", tabO);
                }
                
            });
        }
    });
	$.tab = function(elms, s){
		this.s = $.extend({
                activeClass: 'on',
                firstActive: false,
                animationToggle: false,
                complete: function(){
                },
                closeOnClick: false,
                closeOther: true,
                onEvent: 'click',
                noAction: false,
                diaShow: false,
				tabListSel: false
            }, s);
			this.s.onEvent = this.s.onEvent.split(',');
			var that = this,
			tabID = 'tab-'+new Date().getTime();
			this.controls = elms;
			this.timerID = null;
			this.panels = [];
			if (this.s.diaShow) {
                this.timerID = setInterval(function(){
					that.diaShow.call(that);
				}, s.diaShow);
            }
			if(this.s.tabListSel){
				$(s.tabListSel).attr({'role': 'tablist'});
			}
			this.controls.each(function(i){
                var jElm = $(this),
				eId = jElm.attr('id');
				if(!eId){
					eId = tabID+i;
					jElm.attr({'id': eId});
				}
                that.panels.push($(that.getIDfromAnker(jElm)));
                that.panels[i].one('mouseover.tabsAperto', function(){
                    clearInterval(that.timerID);
                }).one('focus.tabsAperto', function(){
                    clearInterval(that.timerID);
                }).attr({role: 'tabpanel', 'aria-labelledby': eId, tabindex: '-1', 'aria-hidden': 'false'})
					.css({
	                    outline: 'none'
	                });
                if (that.s.firstActive && i === 0) {
                    jElm.addClass(that.s.activeClass)
						.attr({'aria-selected': 'true'});
                }
                else
                    if (!jElm.is('.' + that.s.activeClass)) {
                        that.panels[i].css({
                            display: 'none'
                        }).attr({'aria-hidden': 'true'});
						jElm.attr({'aria-selected': 'false'});
                    } else {
						jElm.attr({'aria-selected': 'true'});
					}
                
                for (var j = 0, len = that.s.onEvent.length; j < len; j++) {
                    jElm.bind($.trim(that.s.onEvent[j]) + '.tabsAperto', function(e){
						that.handleAction.call(that, this, e);
						return false;
					});
                }
                jElm.bind('click.tabsAperto', function(e){
					that.clickHandler.call(that, this, e);
					return false;
				}).attr({role: 'tab'});				
			});
	};
	$.extend($.tab.prototype, {
		getIDfromAnker: function(jElm){
            var id = jElm.attr('href'), 
			fund = id.indexOf('#');
            id = (fund != -1) ? id.substr(fund) : false;
            return id;
        },
		diaShow: function(){
            var n, that = this;
            this.controls.each(function(i){
                if ($(this).is('.' + that.s.activeClass)) {
                    n = i + 1;
                    return false;
                }
            });
            var next = (this.controls[n]) ? this.controls[n] : this.controls[0];
            this.doAction(next);
        },
		doAction: function(elm, e) {
            var jElm = $(elm);
            if (!this.s.closeOnClick && jElm.is('.' + this.s.activeClass)) {
                return false;
            }
            var curActive = (this.s.closeOther) ? this.controls.filter('.' + this.s.activeClass) : $([]), curID = null, newID = this.getIDfromAnker(jElm);
            jElm.toggleClass(this.s.activeClass);
            if (!jElm.is('.' + this.s.activeClass)) {
                curActive = jElm;
            } else {
				jElm.attr({'aria-selected': 'true'});
			}
            if (curActive.length) {
                curActive.removeClass(this.s.activeClass);
				curActive.attr({'aria-selected': 'false'});
                curID = this.getIDfromAnker(curActive);
            }
            if (curID === newID) {
                newID = [];
                curActive = $([]);
            }
            var curActiveBlock = $(curID);
            var toActivateBlock = $(newID);
            if (!this.s.noAction) {
                if (!this.s.animationToggle) {
                    curActiveBlock.css({
                        display: 'none'
                    }).attr({'aria-hidden': 'true'});
                    toActivateBlock.css({
                        display: 'block'
                    }).attr({'aria-hidden': 'false'});
                    if (e && e.type == 'click') {
						setTimeout(function(){
		                        toActivateBlock.focus();
		                }, 9);
                    }
                }
                else {
					
                    $.each(this.panels, function(){
                        $(this).stop(true, true);
                    });
                    curActiveBlock[this.s.animationToggle]().attr({'aria-hidden': 'true'});
                    toActivateBlock[this.s.animationToggle](function(){
                        if (e && e.type == 'click') {
							setTimeout(function(){
		                       toActivateBlock[0].focus();
		                    }, 9);
                        }
                    }).attr({'aria-hidden': 'false'});
                }
            }
            this.s.complete(jElm, toActivateBlock, curActive, curActiveBlock);
        },
		clickHandler: function(elm, e){
            var that = this;
			e.preventDefault();
			if (this.s.onEvent.join('').indexOf('click') == -1) {
                var jElm = $(elm);
                setTimeout(function(){
                    $(that.getIDfromAnker(jElm)).focus();
                }, 9);
            }
            return false;
        },
		handleAction: function (elm, e){
            clearInterval(this.timerID);
            this.doAction(elm, e);
            return false;
        }
	});
})(jQuery);

/*
 * jQuery Color Animations
 * Copyright 2007 John Resig
 * Released under the MIT and GPL licenses.
 */

(function(jQuery){

	// We override the animation for all of these color styles
	jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
		jQuery.fx.step[attr] = function(fx){
			if ( fx.state == 0 ) {
				fx.start = getColor( fx.elem, attr );
				fx.end = getRGB( fx.end );
			}

			fx.elem.style[attr] = "rgb(" + [
				Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
				Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
			].join(",") + ")";
		}
	});

	// Color Conversion functions from highlightFade
	// By Blair Mitchelmore
	// http://jquery.offput.ca/highlightFade/

	// Parse strings looking for color tuples [255,255,255]
	function getRGB(color) {
		var result;

		// Check if we're already dealing with an array of colors
		if ( color && color.constructor == Array && color.length == 3 )
			return color;

		// Look for rgb(num,num,num)
		if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
			return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];

		// Look for rgb(num%,num%,num%)
		if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
			return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];

		// Look for #a0b1c2
		if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
			return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];

		// Look for #fff
		if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
			return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];

		// Otherwise, we're most likely dealing with a named color
		return colors[jQuery.trim(color).toLowerCase()];
	}
	
	function getColor(elem, attr) {
		var color;

		do {
			color = jQuery.curCSS(elem, attr);

			// Keep going until we find an element that has color, or we hit the body
			if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
				break; 

			attr = "backgroundColor";
		} while ( elem = elem.parentNode );

		return getRGB(color);
	};
	
	// Some named colors to work with
	// From Interface by Stefan Petre
	// http://interface.eyecon.ro/

	var colors = {
		
	};
	
})(jQuery);

/**
 * @author alexander.farkas
 */
(function($){
	// $.widget is a factory to create jQuery plugins
	// taking some boilerplate code out of the plugin code
	// created by Scott González and Jörn Zaefferer
	function getter(namespace, plugin, method) {
		var methods = $[namespace][plugin].getter || [];
		methods = (typeof methods == "string" ? methods.split(/,?\s+/) : methods);
		return ($.inArray(method, methods) != -1);
	}
	
	var widgetPrototype = {
		init: function() {},
		destroy: function() {
			this.element.removeData(this.widgetName);
		},
		
		getData: function(key) {
			return this.options[key];
		},
		setData: function(key, value) {
			this.options[key] = value;
		},
		
		enable: function() {
			this.setData('disabled', false);
		},
		disable: function() {
			this.setData('disabled', true);
		}
	};
	
	$.widget = function(name, prototype) {
		var namespace = name.split(".")[0];
		name = name.split(".")[1];
		// create plugin method
		$.fn[name] = function(options) {
			var isMethodCall = (typeof options == 'string'),
				args = Array.prototype.slice.call(arguments, 1);
			
			if (isMethodCall && getter(namespace, name, options)) {
				var instance = $.data(this[0], name);
				return (instance ? instance[options].apply(instance, args)
					: undefined);
			}
			
			return this.each(function() {
				var instance = $.data(this, name);
				if (!instance) {
					$.data(this, name, new $[namespace][name](this, options));
				} else if (isMethodCall) {
					instance[options].apply(instance, args);
				}
			});
		};
		
		// create widget constructor
		$[namespace][name] = function(element, options) {
			var self = this;
			
			this.widgetName = name;
			
			this.options = $.extend({}, $[namespace][name].defaults, options);
			this.element = $(element)
				.bind('setData.' + name, function(e, key, value) {
					return self.setData(key, value);
				})
				.bind('getData.' + name, function(e, key) {
					return self.getData(key);
				})
				.bind('remove', function() {
					return self.destroy();
				});
			this.init();
		};
		
		// add widget prototype
		$[namespace][name].prototype = $.extend({}, widgetPrototype, prototype);
	};
})(jQuery);
/**
 * @author alexander.farkas
 */
(function($){

    //If the UI scope is not available, add it
    $.ui = $.ui ||
    {};
    
    $.fn.extend({
        scroller: function(options){
            var args = Array.prototype.slice.call(arguments, 1);
            return this.each(function(){
                if (typeof options == "string") {
                    var scroller = $.data(this, "ui-scroller");
                    scroller[options].apply(scroller, args);
                }
                else 
                    if (!$.data(this, "ui-scroller")) {
                        $.data(this, "ui-scroller", new $.ui.scroller(this, options));
                    }
                
            });
        }
    });
    $.ui.scroller = function(elem, options){
        var that = this;
        this.o = $.extend({
            //Wrapper Classes:
            hidingWrapper: 'div.stage',
            moveWrapper: 'div.stage-design',
            //Elements Classes
            atoms: 'div.teaser',
            nextLink: 'a.next',
            prevLink: 'a.prev',
            activeLinkClass: 'show',
            linkFn: function(){
            },
            //animate
            animate: true,
            animateOptions: {
                duration: 800
            },
            hidingWidth: false,
            hidingHeight: false,
            moveStep: 'atom',
            direction: 'horizontal',
            pagination: false,
            paginationAtoms: '<li class="pa-$number"><a href="#">$number</a></li>',
            paginationTitleFrom: false,
            activePaginationClass: 'on',
            paginationFn: false,
            diashow: false,
            addSubPixel: 0
        }, options);
        this.o.animateOptions.complete = function(){
            that.propagate('end');
        };
        this.o.direction = (this.o.direction == 'vertical') ? {
            scroll: 'scrollTop',
            outerD: 'outerHeight',
            dim: 'height'
        } : {
            scroll: 'scrollLeft',
            outerD: 'outerWidth',
            dim: 'width'
        };
        this.pictureUpdate = 0;
        this.element = $(elem);
        this.moveElem = $(this.o.moveWrapper, elem);
        this.atomElem = $(this.o.atoms, elem);
        this.hidingWrapper = $(this.o.hidingWrapper, elem);
        
        this.nextLink = $(this.o.nextLink, elem);
        this.prevLink = $(this.o.prevLink, elem);
        
        this.position = 0;
        this.atomPos = 0;
        this.percentage = 0;
        this.oldPosition = 0;
        this.oldAtomPos = 0;
        if (this.o.hidingHeight || this.o.hidingWidth) {
            var css = (this.o.hidingHeight) ? {
                height: this.o.hidingHeight
            } : {};
            if ((this.o.hidingWidth)) {
                css = $.extend(css, {
                    width: this.o.hidingWidth
                });
            }
            this.hidingWrapper.css(css);
        }
        this.dims = [0];
        this.hidingWrapper[0][this.o.direction.scroll] = 0;
        this.update();
        if (this.o.diashow) {
            this.startDiashow();
            this.element.bind('mouseenter.diashow', function(){
                clearInterval(that.diaTimer);
            }).bind('mouseleave.diashow', function(){
                that.startDiashow.call(that);
            });
        }
        if ($.fn.mousewheel) {
            this.moveElem.mousewheel(function(e, d){
                that.stopDiashow.call(that);
                d = (d < 0) ? '-' : '+';
                var moveStep = (that.o.moveStep) ? that.o.moveStep : 'atom';
                that.moveTo(d + 'atom1');
                return false;
            });
        }
		this.mouseAction = false;
		this.element.bind('mousedown.diashow', function(){
                that.mouseAction = true;
            }).bind('mouseup.diashow', function(){
                that.mouseAction = false;
            }).bind('mouseleave.diashow', function(){
                that.mouseAction = false;
            });
        this.nextLink.bind('click.uiscroller', function(){
            that.stopDiashow.call(that);
            that.moveTo('-' + that.o.moveStep);
            return false;
        });
        this.prevLink.bind('click.uiscroller', function(){
            that.stopDiashow.call(that);
            that.moveTo('+' + that.o.moveStep);
            return false;
        });
    };
    $.extend($.ui.scroller.prototype, {
        getAtomNearPos: function(oPos, nPos){
            var i = 2, len = this.dims.length;
            for (; i < len; i++) {
                if (nPos <= this.dims[i]) {
                    return i;
                }
            }
            return false;
        },
        atomfocus: function(){
            var scrollPos = this.hidingWrapper[0][this.o.direction.scroll];
			if(!this.mouseAction && this.mouseAction.position != scrollPos){
				scrollPos = this.getAtomNearPos(this.position, scrollPos);
	            if (isFinite(scrollPos)) {
	                this.moveTo(this.dims[scrollPos], false);
	            }
			}
        },
        startDiashow: function(){
            var that = this;
            this.diaTimer = null;
            clearInterval(this.diaTimer);
            this.diaTimer = setInterval(function(){
                ((that.position === that.maxPos) ? that.moveTo(0, false) : that.moveTo('-' + that.o.moveStep));
            }, this.o.diashow);
        },
        stopDiashow: function(){
            this.element.unbind('.diashow');
            clearInterval(this.diaTimer);
        },
        update: function(hard){
            var that = this, jElm;
            if (hard) {
                this.dims = [0];
            }
            this.dims[1] = this.hidingWrapper.css({
                overflow: 'hidden'
            })[that.o.direction.dim]();
            var from = this.dims.length - 2;
			for(var i = from, len = this.atomElem.length; i < len; i++){
                jElm = $(this.atomElem[i]);
                that.dims.push(that.dims[0]);
                width = jElm[that.o.direction.outerD]({
                    margin: true
                });
                that.dims[0] += width;
                jElm.bind('focus.uiscroller', function(){
                    setTimeout(function(){
                        that.stopDiashow.call(that);
                        that.atomfocus.call(that);
                    }, 9);
                });
			}
            this.dims[0] += this.o.addSubPixel;
            this.maxPos = (this.dims[0] - this.dims[1]);
            var moveCss = (that.o.direction.dim == 'height') ? {
                height: this.dims[0] + 'px'
            } : {
                width: this.dims[0] + 'px'
            };
            this.moveElem.css(moveCss);
            this.pagination = null;
            if (this.o.pagination) {
                this.createPagination(hard);
            }
			
            this.showHideLinks();
        },
        pictureIsLoaded: function(){
            this.pictureUpdate--;
            if (!this.pictureUpdate) {
                this.update();
            }
        },
        append: function(html, waitForImageLoad){
            var that = this;
            var appendedHTML = $(html).appendTo(this.moveElem[0]);
			this.atomElem = this.atomElem.add(appendedHTML);
            if (waitForImageLoad) {
                appendedHTML.find('img').each(function(){
                    if (!this.complete) {
                        $(this).bind('load.uiscroller', function(){
                            that.pictureIsLoaded.call(that);
                        });
                        that.pictureUpdate++;
                    }
                });
                if (!this.pictureUpdate) {
                    this.update();
                }
            }
            else {
                this.update();
            }
            
        },
        createPagination: function(hard){
            var content = '<ul>', that = this, tmpContent;
            this.pagination = $(this.o.pagination, this.element[0]);
            this.atomElem.each(function(i){
                tmpContent = that.o.paginationAtoms.replace(/\$number/g, i + 1);
                
                content += (that.o.paginationTitleFrom) ? tmpContent.replace(/\$title/g, $(that.o.paginationTitleFrom, this).text()) : tmpContent;
            });
            this.pagination.html(content + '</ul>').find('a').each(function(i){
                $(this).click(function(){
                    that.stopDiashow.call(that);
                    that.moveTo.call(that, 'goTo' + i);
                    return false;
                });
            });
        },
        showHideLinks: function(pos){
			//calculate the curent position
			pos = (isNaN(pos)) ? parseInt(this.hidingWrapper[0][this.o.direction.scroll], 10) : pos;
            if(pos !== this.position){
				this.percentage = pos / (this.maxPos / 100);
	            this.oldPosition = this.position;
	            this.oldAtomPos = this.atomPos;
	            this.position = pos;
	            var num = this.getAtomNearPos(this.oldPosition, this.position);
	            num = (num) ? num - 2 : 0;
	            this.atomPos = num;
			}
			this.percentage = pos / (this.maxPos / 100);
            var o = this.o;
            if (pos <= 0 && this.prevLink.is('.' + o.activeLinkClass)) {
                o.linkFn.call(this.prevLink, 'hide');
                this.prevLink.removeClass(o.activeLinkClass);
            }
            else 
                if (pos > 0 && !this.prevLink.is('.' + o.activeLinkClass)) {
                    o.linkFn.call(this.prevLink, 'show');
                    this.prevLink.addClass(o.activeLinkClass);
                }
            if (pos >= this.maxPos && this.nextLink.is('.' + o.activeLinkClass)) {
                o.linkFn.call(this.nextLink, 'hide');
                this.nextLink.removeClass(o.activeLinkClass);
            }
            else 
                if (pos < this.maxPos && !this.nextLink.is('.' + o.activeLinkClass)) {
                    o.linkFn.call(this.nextLink, 'show');
                    this.nextLink.addClass(o.activeLinkClass);
                }
            if (this.pagination) {
                var oldActive = this.pagination.find('li').filter('.' + o.activePaginationClass).removeClass(o.activePaginationClass), newActive = oldActive.end().eq(this.atomPos).addClass(o.activePaginationClass);
                if ($.isFunction(o.paginationFn)) {
                    o.paginationFn.call(oldActive, 'inactive');
                    o.paginationFn.call(newActive, 'active');
                }
            }
        },
        calcNewPos: function(ePos){
            var rel = false, num;
            // handle Atom Step & goTo
            if (ePos.indexOf('goTo') === 0) {
                num = parseInt(/(\d+)$/.exec(ePos)[0], 10) + 2;
                ePos = this.dims[num];
            }
            else 
                if (ePos == '-atom' || ePos == '-atom1') {
                    num = this.atomPos + 3;
                    ePos = (this.dims[num] || this.dims[num] === 0) ? this.dims[num] : this.dims[this.dims.length - 1];
                }
                else 
                    if (ePos == '+atom' || ePos == '+atom1') {
                        ePos = (this.atomPos) ? this.dims[this.atomPos + 1] : 0;
                    }
                    else 
                        if (ePos.indexOf('atom') == 1) {
                            num = parseInt(/(\d+)$/.exec(ePos)[0], 10);
                            if (ePos.indexOf('-') === 0) {
                                num += 2;
                                if (this.dims[this.atomPos + num]) {
                                    ePos = this.dims[this.atomPos + num];
                                }
                                else {
                                    ePos = this.dims[this.dims.length - 1];
                                }
                            }
                            else {
                                num -= 2;
                                var aLen = this.atomPos - num;
                                if (aLen > 1 && this.dims[this.atomPos - num]) {
                                    ePos = this.dims[this.atomPos - num];
                                }
                                else {
                                    ePos = 0;
                                }
                            }
                        // handle: +/-Number
                        }
                        else 
                            if (ePos.indexOf('+') === 0 || ePos.indexOf('-') === 0) {
                                rel = ePos.slice(0, 1);
                                ePos = parseInt(ePos.slice(1), 10);
                                ePos = (rel == '-') ? this.position + ePos : this.position - ePos;
                            }
                            else {
                                // handle Percentage
                                var per = /(\d+)%$/.exec(ePos);
                                if (per && per[1]) {
                                    ePos = this.maxPos / 100 * parseFloat(ePos);
                                }
                            }
            return ePos;
        },
        moveTo: function(pos, anim, animOp){
            pos = (isNaN(pos)) ? this.calcNewPos(pos) : pos;
            pos = (pos <= 0) ? 0 : (pos >= this.maxPos) ? this.maxPos : pos;
            if (pos === this.position) {
                return false;
            }
            var o = this.o, scroll = this.o.direction.scroll;
            this.showHideLinks(pos);
            this.propagate('start', this.oldPosition);
            
            anim = (typeof anim == 'undefined') ? o.animate : anim;
            if (anim) {
                //dirty break recursion
                animOp = animOp ||
                {};
                animOp = $.extend({}, o.animateOptions, {
                    slide: this
                }, animOp);
                var animCss = (scroll == 'scrollTop') ? {
                    scrollTop: pos,
                    uiscrollerComplete: pos
                } : {
                    scrollLeft: pos,
                    uiscrollerComplete: pos
                };
                this.hidingWrapper.stop().animate(animCss, animOp);
            }
            else {
                this.hidingWrapper.stop()[0][scroll] = pos;
                this.propagate('end');
            }
        },
        ui: function(){
            return {
                instance: this,
                options: this.o,
                pos: this.position,
                percentPos: this.percentage,
                oldIndex: this.oldAtomPos,
                newIndex: this.atomPos,
                size: this.dims.length - 2
            };
        },
        propagate: function(n, pos){
            var args = (pos || pos === 0) ? [$.extend({}, this.ui(), {
                'pos': pos,
                percentPos: pos / (this.maxPos / 100)
            })] : [this.ui()];
            this.element.triggerHandler("uiscroller" + n, args);
        }
    });
    $.extend($.fx.step, {
        uiscrollerComplete: function(fx){
            if (fx.now || fx.now === 0) {
                var scroller = fx.options.slide;
                if (scroller) {
                    scroller.propagate('slide', scroller.hidingWrapper[0][scroller.o.direction.scroll]);
                }
            }
        }
    });
})(jQuery);

