/* ------------------------------------------------------------------------
	s3Slider
	
	Developped By: Boban Karišik -> http://www.serie3.info/
        CSS Help: Mészáros Róbert -> http://www.perspectived.com/
	Version: 1.0
	
	Copyright: Feel free to redistribute the script/modify it, as
			   long as you leave my infos at the top.
------------------------------------------------------------------------- */


(function($){  

    $.fn.s3Slider = function(vars) {       
        
        var element     = this;
        var timeOut     = (vars.timeOut != undefined) ? vars.timeOut : 4000;
        var current     = null;
        var timeOutFn   = null;
        var faderStat   = true;
        var mOver       = false;
        var items       = $("#" + element[0].id + "Content ." + element[0].id + "Image");
        var itemsSpan   = $("#" + element[0].id + "Content ." + element[0].id + "Image span");
        var images		= items.children('img');
        
        
        $(this).prepend("<div class='ss_loader'></div>");
        var parentDim={
			  width:$(this).outerWidth(),
			  height:$(this).outerHeight()
        };
       //fix the loader in the middle
        $(".ss_loader").css({width:32,height:32,position:'absolute',left:parentDim.width/2-16,top:parentDim.height/2-16});
            
        items.each(function(i) {
    
            $(items[i]).mouseover(function() {
               mOver = true;
            });
            
            $(items[i]).mouseout(function() {
                mOver   = false;
                fadeElement(true);
            });
            
        });
        
        var preloadImages=function(){
			  nImages=images.length;
			  var pictures=new Array();
				  function loop (i){
					  if (i<nImages){

						  img=new Image();
						  img.onload=function(){
								i++;

								if (i==nImages-1){$('.ss_loader').hide();
								return true;}
					  			loop(i);  
						  }
						  img.src=images[i].src;
					  }
				  }
			  loop(0);
			// alert(pictures.length);
        }
        
        
        var fadeElement = function(isMouseOut) {
            var thisTimeOut = (isMouseOut) ? (timeOut/2) : timeOut;
            thisTimeOut = (faderStat) ? 10 : thisTimeOut;
            if(items.length > 0) {
                timeOutFn = setTimeout(makeSlider, thisTimeOut);
            } else {
                console.log("Poof..");
            }
        }
        
        var makeSlider = function() {
            current = (current != null) ? current : items[(items.length-1)];
            var currNo      = jQuery.inArray(current, items) + 1
            currNo = (currNo == items.length) ? 0 : (currNo - 1);
            var newMargin   = $(element).width() * currNo;
            if(faderStat == true) {
                if(!mOver) {
                    $(items[currNo]).fadeIn((timeOut/6), function() {
                        if($(itemsSpan[currNo]).css('bottom') == 0) {
                            $(itemsSpan[currNo]).slideUp((timeOut/6), function() {
                                faderStat = false;
                                current = items[currNo];
                                if(!mOver) {
                                    fadeElement(false);
                                }
                            });
                        } else {
                            $(itemsSpan[currNo]).slideDown((timeOut/6), function() {
                                faderStat = false;
                                current = items[currNo];
                                if(!mOver) {
                                    fadeElement(false);
                                }
                            });
                        }
                    });
                }
            } else {
                if(!mOver) {
                    if($(itemsSpan[currNo]).css('bottom') == 0) {
                        $(itemsSpan[currNo]).slideDown((timeOut/6), function() {
                            $(items[currNo]).fadeOut((timeOut/6), function() {
                                faderStat = true;
                                current = items[(currNo+1)];
                                if(!mOver) {
                                    fadeElement(false);
                                }
                            });
                        });
                    } else {
                        $(itemsSpan[currNo]).slideUp((timeOut/6), function() {
                        $(items[currNo]).fadeOut((timeOut/6), function() {
                                faderStat = true;
                                current = items[(currNo+1)];
                                if(!mOver) {
                                    fadeElement(false);
                                }
                            });
                        });
                    }
                }
            }
        }
		 preloadImages();
		 makeSlider();
    };  

})(jQuery);  

/*
 * jQuery UI 1.7.1
 *
 * 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($) {

var _remove = $.fn.remove,
	isFF2 = $.browser.mozilla && (parseFloat($.browser.version) < 1.9);

//Helper functions and ui object
$.ui = {
	version: "1.7.1",

	// $.ui.plugin is deprecated.  Use the proxy pattern instead.
	plugin: {
		add: function(module, option, set) {
			var proto = $.ui[module].prototype;
			for(var i in set) {
				proto.plugins[i] = proto.plugins[i] || [];
				proto.plugins[i].push([option, set[i]]);
			}
		},
		call: function(instance, name, args) {
			var set = instance.plugins[name];
			if(!set || !instance.element[0].parentNode) { return; }

			for (var i = 0; i < set.length; i++) {
				if (instance.options[set[i][0]]) {
					set[i][1].apply(instance.element, args);
				}
			}
		}
	},

	contains: function(a, b) {
		return document.compareDocumentPosition
			? a.compareDocumentPosition(b) & 16
			: a !== b && a.contains(b);
	},

	hasScroll: function(el, a) {

		//If overflow is hidden, the element might have extra content, but the user wants to hide it
		if ($(el).css('overflow') == 'hidden') { return false; }

		var scroll = (a && a == 'left') ? 'scrollLeft' : 'scrollTop',
			has = false;

		if (el[scroll] > 0) { return true; }

		// TODO: determine which cases actually cause this to happen
		// if the element doesn't have the scroll set, see if it's possible to
		// set the scroll
		el[scroll] = 1;
		has = (el[scroll] > 0);
		el[scroll] = 0;
		return has;
	},

	isOverAxis: function(x, reference, size) {
		//Determines when x coordinate is over "b" element axis
		return (x > reference) && (x < (reference + size));
	},

	isOver: function(y, x, top, left, height, width) {
		//Determines when x, y coordinates is over "b" element
		return $.ui.isOverAxis(y, top, height) && $.ui.isOverAxis(x, left, width);
	},

	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
	}
};

// WAI-ARIA normalization
if (isFF2) {
	var attr = $.attr,
		removeAttr = $.fn.removeAttr,
		ariaNS = "http://www.w3.org/2005/07/aaa",
		ariaState = /^aria-/,
		ariaRole = /^wairole:/;

	$.attr = function(elem, name, value) {
		var set = value !== undefined;

		return (name == 'role'
			? (set
				? attr.call(this, elem, name, "wairole:" + value)
				: (attr.apply(this, arguments) || "").replace(ariaRole, ""))
			: (ariaState.test(name)
				? (set
					? elem.setAttributeNS(ariaNS,
						name.replace(ariaState, "aaa:"), value)
					: attr.call(this, elem, name.replace(ariaState, "aaa:")))
				: attr.apply(this, arguments)));
	};

	$.fn.removeAttr = function(name) {
		return (ariaState.test(name)
			? this.each(function() {
				this.removeAttributeNS(ariaNS, name.replace(ariaState, ""));
			}) : removeAttr.call(this, name));
	};
}

//jQuery plugins
$.fn.extend({
	remove: function() {
		// Safari has a native remove event which actually removes DOM elements,
		// so we have to use triggerHandler instead of trigger (#3037).
		$("*", this).add(this).each(function() {
			$(this).triggerHandler("remove");
		});
		return _remove.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 scrollParent;
		if(($.browser.msie && (/(static|relative)/).test(this.css('position'))) || (/absolute/).test(this.css('position'))) {
			scrollParent = this.parents().filter(function() {
				return (/(relative|absolute|fixed)/).test($.curCSS(this,'position',1)) && (/(auto|scroll)/).test($.curCSS(this,'overflow',1)+$.curCSS(this,'overflow-y',1)+$.curCSS(this,'overflow-x',1));
			}).eq(0);
		} else {
			scrollParent = this.parents().filter(function() {
				return (/(auto|scroll)/).test($.curCSS(this,'overflow',1)+$.curCSS(this,'overflow-y',1)+$.curCSS(this,'overflow-x',1));
			}).eq(0);
		}

		return (/fixed/).test(this.css('position')) || !scrollParent.length ? $(document) : scrollParent;
	}
});


//Additional selectors
$.extend($.expr[':'], {
	data: function(elem, i, match) {
		return !!$.data(elem, match[3]);
	},

	focusable: function(element) {
		var nodeName = element.nodeName.toLowerCase(),
			tabIndex = $.attr(element, 'tabindex');
		return (/input|select|textarea|button|object/.test(nodeName)
			? !element.disabled
			: 'a' == nodeName || 'area' == nodeName
				? element.href || !isNaN(tabIndex)
				: !isNaN(tabIndex))
			// the element and all of its ancestors must be visible
			// the browser may report that the area is hidden
			&& !$(element)['area' == nodeName ? 'parents' : 'closest'](':hidden').length;
	},

	tabbable: function(element) {
		var tabIndex = $.attr(element, 'tabindex');
		return (isNaN(tabIndex) || tabIndex >= 0) && $(element).is(':focusable');
	}
});


// $.widget is a factory to create jQuery plugins
// taking some boilerplate code out of the plugin code
function getter(namespace, plugin, method, args) {
	function getMethods(type) {
		var methods = $[namespace][plugin][type] || [];
		return (typeof methods == 'string' ? methods.split(/,?\s+/) : methods);
	}

	var methods = getMethods('getter');
	if (args.length == 1 && typeof args[0] == 'string') {
		methods = methods.concat(getMethods('getterSetter'));
	}
	return ($.inArray(method, methods) != -1);
}

$.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);

		// prevent calls to internal methods
		if (isMethodCall && options.substring(0, 1) == '_') {
			return this;
		}

		// handle getter methods
		if (isMethodCall && getter(namespace, name, options, args)) {
			var instance = $.data(this[0], name);
			return (instance ? instance[options].apply(instance, args)
				: undefined);
		}

		// handle initialization and non-getter methods
		return this.each(function() {
			var instance = $.data(this, name);

			// constructor
			(!instance && !isMethodCall &&
				$.data(this, name, new $[namespace][name](this, options))._init());

			// method call
			(instance && isMethodCall && $.isFunction(instance[options]) &&
				instance[options].apply(instance, args));
		});
	};

	// create widget constructor
	$[namespace] = $[namespace] || {};
	$[namespace][name] = function(element, options) {
		var self = this;

		this.namespace = namespace;
		this.widgetName = name;
		this.widgetEventPrefix = $[namespace][name].eventPrefix || name;
		this.widgetBaseClass = namespace + '-' + name;

		this.options = $.extend({},
			$.widget.defaults,
			$[namespace][name].defaults,
			$.metadata && $.metadata.get(element)[name],
			options);

		this.element = $(element)
			.bind('setData.' + name, function(event, key, value) {
				if (event.target == element) {
					return self._setData(key, value);
				}
			})
			.bind('getData.' + name, function(event, key) {
				if (event.target == element) {
					return self._getData(key);
				}
			})
			.bind('remove', function() {
				return self.destroy();
			});
	};

	// add widget prototype
	$[namespace][name].prototype = $.extend({}, $.widget.prototype, prototype);

	// TODO: merge getter and getterSetter properties from widget prototype
	// and plugin prototype
	$[namespace][name].getterSetter = 'option';
};

$.widget.prototype = {
	_init: function() {},
	destroy: function() {
		this.element.removeData(this.widgetName)
			.removeClass(this.widgetBaseClass + '-disabled' + ' ' + this.namespace + '-state-disabled')
			.removeAttr('aria-disabled');
	},

	option: function(key, value) {
		var options = key,
			self = this;

		if (typeof key == "string") {
			if (value === undefined) {
				return this._getData(key);
			}
			options = {};
			options[key] = value;
		}

		$.each(options, function(key, value) {
			self._setData(key, value);
		});
	},
	_getData: function(key) {
		return this.options[key];
	},
	_setData: function(key, value) {
		this.options[key] = value;

		if (key == 'disabled') {
			this.element
				[value ? 'addClass' : 'removeClass'](
					this.widgetBaseClass + '-disabled' + ' ' +
					this.namespace + '-state-disabled')
				.attr("aria-disabled", value);
		}
	},

	enable: function() {
		this._setData('disabled', false);
	},
	disable: function() {
		this._setData('disabled', true);
	},

	_trigger: function(type, event, data) {
		var callback = this.options[type],
			eventName = (type == this.widgetEventPrefix
				? type : this.widgetEventPrefix + type);

		event = $.Event(event);
		event.type = eventName;

		// copy original event properties over to the new event
		// this would happen if we could call $.event.fix instead of $.Event
		// but we don't have a way to force an event to be fixed multiple times
		if (event.originalEvent) {
			for (var i = $.event.props.length, prop; i;) {
				prop = $.event.props[--i];
				event[prop] = event.originalEvent[prop];
			}
		}

		this.element.trigger(event, data);

		return !($.isFunction(callback) && callback.call(this.element[0], event, data) === false
			|| event.isDefaultPrevented());
	}
};

$.widget.defaults = {
	disabled: false
};


/** Mouse Interaction Plugin **/

$.ui.mouse = {
	_mouseInit: function() {
		var self = this;

		this.element
			.bind('mousedown.'+this.widgetName, function(event) {
				return self._mouseDown(event);
			})
			.bind('click.'+this.widgetName, function(event) {
				if(self._preventClickEvent) {
					self._preventClickEvent = false;
					event.stopImmediatePropagation();
					return false;
				}
			});

		// Prevent text selection in IE
		if ($.browser.msie) {
			this._mouseUnselectable = this.element.attr('unselectable');
			this.element.attr('unselectable', 'on');
		}

		this.started = false;
	},

	// TODO: make sure destroying one instance of mouse doesn't mess with
	// other instances of mouse
	_mouseDestroy: function() {
		this.element.unbind('.'+this.widgetName);

		// Restore text selection in IE
		($.browser.msie
			&& this.element.attr('unselectable', this._mouseUnselectable));
	},

	_mouseDown: function(event) {
		// don't let more than one widget handle mouseStart
		// TODO: figure out why we have to use originalEvent
		event.originalEvent = event.originalEvent || {};
		if (event.originalEvent.mouseHandled) { return; }

		// we may have missed mouseup (out of window)
		(this._mouseStarted && this._mouseUp(event));

		this._mouseDownEvent = event;

		var self = this,
			btnIsLeft = (event.which == 1),
			elIsCancel = (typeof this.options.cancel == "string" ? $(event.target).parents().add(event.target).filter(this.options.cancel).length : false);
		if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) {
			return true;
		}

		this.mouseDelayMet = !this.options.delay;
		if (!this.mouseDelayMet) {
			this._mouseDelayTimer = setTimeout(function() {
				self.mouseDelayMet = true;
			}, this.options.delay);
		}

		if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
			this._mouseStarted = (this._mouseStart(event) !== false);
			if (!this._mouseStarted) {
				event.preventDefault();
				return true;
			}
		}

		// these delegates are required to keep context
		this._mouseMoveDelegate = function(event) {
			return self._mouseMove(event);
		};
		this._mouseUpDelegate = function(event) {
			return self._mouseUp(event);
		};
		$(document)
			.bind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
			.bind('mouseup.'+this.widgetName, this._mouseUpDelegate);

		// preventDefault() is used to prevent the selection of text here -
		// however, in Safari, this causes select boxes not to be selectable
		// anymore, so this fix is needed
		($.browser.safari || event.preventDefault());

		event.originalEvent.mouseHandled = true;
		return true;
	},

	_mouseMove: function(event) {
		// IE mouseup check - mouseup happened when mouse was out of window
		if ($.browser.msie && !event.button) {
			return this._mouseUp(event);
		}

		if (this._mouseStarted) {
			this._mouseDrag(event);
			return event.preventDefault();
		}

		if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
			this._mouseStarted =
				(this._mouseStart(this._mouseDownEvent, event) !== false);
			(this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event));
		}

		return !this._mouseStarted;
	},

	_mouseUp: function(event) {
		$(document)
			.unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
			.unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);

		if (this._mouseStarted) {
			this._mouseStarted = false;
			this._preventClickEvent = (event.target == this._mouseDownEvent.target);
			this._mouseStop(event);
		}

		return false;
	},

	_mouseDistanceMet: function(event) {
		return (Math.max(
				Math.abs(this._mouseDownEvent.pageX - event.pageX),
				Math.abs(this._mouseDownEvent.pageY - event.pageY)
			) >= this.options.distance
		);
	},

	_mouseDelayMet: function(event) {
		return this.mouseDelayMet;
	},

	// These are placeholder methods, to be overriden by extending plugin
	_mouseStart: function(event) {},
	_mouseDrag: function(event) {},
	_mouseStop: function(event) {},
	_mouseCapture: function(event) { return true; }
};

$.ui.mouse.defaults = {
	cancel: null,
	distance: 1,
	delay: 0
};

})(jQuery);


/*
 * jQuery UI Slider 1.7.1
 *
 * 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/Slider
 *
 * Depends:
 *	ui.core.js
 */

(function($) {

$.widget("ui.slider", $.extend({}, $.ui.mouse, {

	_init: function() {

		var self = this, o = this.options;
		this._keySliding = false;
		this._handleIndex = null;
		this._detectOrientation();
		this._mouseInit();

		this.element
			.addClass("ui-slider"
				+ " ui-slider-" + this.orientation
				+ " ui-widget"
				+ " ui-widget-content"
				+ " ui-corner-all");

		this.range = $([]);

		if (o.range) {

			if (o.range === true) {
				this.range = $('<div></div>');
				if (!o.values) o.values = [this._valueMin(), this._valueMin()];
				if (o.values.length && o.values.length != 2) {
					o.values = [o.values[0], o.values[0]];
				}
			} else {
				this.range = $('<div></div>');
			}

			this.range
				.appendTo(this.element)
				.addClass("ui-slider-range");

			if (o.range == "min" || o.range == "max") {
				this.range.addClass("ui-slider-range-" + o.range);
			}

			// note: this isn't the most fittingly semantic framework class for this element,
			// but worked best visually with a variety of themes
			this.range.addClass("ui-widget-header");

		}

		if ($(".ui-slider-handle", this.element).length == 0)
			$('<a href="#"></a>')
				.appendTo(this.element)
				.addClass("ui-slider-handle");

		if (o.values && o.values.length) {
			while ($(".ui-slider-handle", this.element).length < o.values.length)
				$('<a href="#"></a>')
					.appendTo(this.element)
					.addClass("ui-slider-handle");
		}

		this.handles = $(".ui-slider-handle", this.element)
			.addClass("ui-state-default"
				+ " ui-corner-all");

		this.handle = this.handles.eq(0);

		this.handles.add(this.range).filter("a")
			.click(function(event) { event.preventDefault(); })
			.hover(function() { $(this).addClass('ui-state-hover'); }, function() { $(this).removeClass('ui-state-hover'); })
			.focus(function() { $(".ui-slider .ui-state-focus").removeClass('ui-state-focus'); $(this).addClass('ui-state-focus'); })
			.blur(function() { $(this).removeClass('ui-state-focus'); });

		this.handles.each(function(i) {
			$(this).data("index.ui-slider-handle", i);
		});

		this.handles.keydown(function(event) {

			var ret = true;

			var index = $(this).data("index.ui-slider-handle");

			if (self.options.disabled)
				return;

			switch (event.keyCode) {
				case $.ui.keyCode.HOME:
				case $.ui.keyCode.END:
				case $.ui.keyCode.UP:
				case $.ui.keyCode.RIGHT:
				case $.ui.keyCode.DOWN:
				case $.ui.keyCode.LEFT:
					ret = false;
					if (!self._keySliding) {
						self._keySliding = true;
						$(this).addClass("ui-state-active");
						self._start(event, index);
					}
					break;
			}

			var curVal, newVal, step = self._step();
			if (self.options.values && self.options.values.length) {
				curVal = newVal = self.values(index);
			} else {
				curVal = newVal = self.value();
			}

			switch (event.keyCode) {
				case $.ui.keyCode.HOME:
					newVal = self._valueMin();
					break;
				case $.ui.keyCode.END:
					newVal = self._valueMax();
					break;
				case $.ui.keyCode.UP:
				case $.ui.keyCode.RIGHT:
					if(curVal == self._valueMax()) return;
					newVal = curVal + step;
					break;
				case $.ui.keyCode.DOWN:
				case $.ui.keyCode.LEFT:
					if(curVal == self._valueMin()) return;
					newVal = curVal - step;
					break;
			}

			self._slide(event, index, newVal);

			return ret;

		}).keyup(function(event) {

			var index = $(this).data("index.ui-slider-handle");

			if (self._keySliding) {
				self._stop(event, index);
				self._change(event, index);
				self._keySliding = false;
				$(this).removeClass("ui-state-active");
			}

		});

		this._refreshValue();

	},

	destroy: function() {

		this.handles.remove();
		this.range.remove();

		this.element
			.removeClass("ui-slider"
				+ " ui-slider-horizontal"
				+ " ui-slider-vertical"
				+ " ui-slider-disabled"
				+ " ui-widget"
				+ " ui-widget-content"
				+ " ui-corner-all")
			.removeData("slider")
			.unbind(".slider");

		this._mouseDestroy();

	},

	_mouseCapture: function(event) {

		var o = this.options;

		if (o.disabled)
			return false;

		this.elementSize = {
			width: this.element.outerWidth(),
			height: this.element.outerHeight()
		};
		this.elementOffset = this.element.offset();

		var position = { x: event.pageX, y: event.pageY };
		var normValue = this._normValueFromMouse(position);

		var distance = this._valueMax() - this._valueMin() + 1, closestHandle;
		var self = this, index;
		this.handles.each(function(i) {
			var thisDistance = Math.abs(normValue - self.values(i));
			if (distance > thisDistance) {
				distance = thisDistance;
				closestHandle = $(this);
				index = i;
			}
		});

		// workaround for bug #3736 (if both handles of a range are at 0,
		// the first is always used as the one with least distance,
		// and moving it is obviously prevented by preventing negative ranges)
		if(o.range == true && this.values(1) == o.min) {
			closestHandle = $(this.handles[++index]);
		}

		this._start(event, index);

		self._handleIndex = index;

		closestHandle
			.addClass("ui-state-active")
			.focus();
		
		var offset = closestHandle.offset();
		var mouseOverHandle = !$(event.target).parents().andSelf().is('.ui-slider-handle');
		this._clickOffset = mouseOverHandle ? { left: 0, top: 0 } : {
			left: event.pageX - offset.left - (closestHandle.width() / 2),
			top: event.pageY - offset.top
				- (closestHandle.height() / 2)
				- (parseInt(closestHandle.css('borderTopWidth'),10) || 0)
				- (parseInt(closestHandle.css('borderBottomWidth'),10) || 0)
				+ (parseInt(closestHandle.css('marginTop'),10) || 0)
		};

		normValue = this._normValueFromMouse(position);
		this._slide(event, index, normValue);
		return true;

	},

	_mouseStart: function(event) {
		return true;
	},

	_mouseDrag: function(event) {

		var position = { x: event.pageX, y: event.pageY };
		var normValue = this._normValueFromMouse(position);
		
		this._slide(event, this._handleIndex, normValue);

		return false;

	},

	_mouseStop: function(event) {

		this.handles.removeClass("ui-state-active");
		this._stop(event, this._handleIndex);
		this._change(event, this._handleIndex);
		this._handleIndex = null;
		this._clickOffset = null;

		return false;

	},
	
	_detectOrientation: function() {
		this.orientation = this.options.orientation == 'vertical' ? 'vertical' : 'horizontal';
	},

	_normValueFromMouse: function(position) {

		var pixelTotal, pixelMouse;
		if ('horizontal' == this.orientation) {
			pixelTotal = this.elementSize.width;
			pixelMouse = position.x - this.elementOffset.left - (this._clickOffset ? this._clickOffset.left : 0);
		} else {
			pixelTotal = this.elementSize.height;
			pixelMouse = position.y - this.elementOffset.top - (this._clickOffset ? this._clickOffset.top : 0);
		}

		var percentMouse = (pixelMouse / pixelTotal);
		if (percentMouse > 1) percentMouse = 1;
		if (percentMouse < 0) percentMouse = 0;
		if ('vertical' == this.orientation)
			percentMouse = 1 - percentMouse;

		var valueTotal = this._valueMax() - this._valueMin(),
			valueMouse = percentMouse * valueTotal,
			valueMouseModStep = valueMouse % this.options.step,
			normValue = this._valueMin() + valueMouse - valueMouseModStep;

		if (valueMouseModStep > (this.options.step / 2))
			normValue += this.options.step;

		// Since JavaScript has problems with large floats, round
		// the final value to 5 digits after the decimal point (see #4124)
		return parseFloat(normValue.toFixed(5));

	},

	_start: function(event, index) {
		var uiHash = {
			handle: this.handles[index],
			value: this.value()
		};
		if (this.options.values && this.options.values.length) {
			uiHash.value = this.values(index)
			uiHash.values = this.values()
		}
		this._trigger("start", event, uiHash);
	},

	_slide: function(event, index, newVal) {

		var handle = this.handles[index];

		if (this.options.values && this.options.values.length) {

			var otherVal = this.values(index ? 0 : 1);

			if ((index == 0 && newVal >= otherVal) || (index == 1 && newVal <= otherVal))
				newVal = otherVal;

			if (newVal != this.values(index)) {
				var newValues = this.values();
				newValues[index] = newVal;
				// A slide can be canceled by returning false from the slide callback
				var allowed = this._trigger("slide", event, {
					handle: this.handles[index],
					value: newVal,
					values: newValues
				});
				var otherVal = this.values(index ? 0 : 1);
				if (allowed !== false) {
					this.values(index, newVal, ( event.type == 'mousedown' && this.options.animate ), true);
				}
			}

		} else {

			if (newVal != this.value()) {
				// A slide can be canceled by returning false from the slide callback
				var allowed = this._trigger("slide", event, {
					handle: this.handles[index],
					value: newVal
				});
				if (allowed !== false) {
					this._setData('value', newVal, ( event.type == 'mousedown' && this.options.animate ));
				}
					
			}

		}

	},

	_stop: function(event, index) {
		var uiHash = {
			handle: this.handles[index],
			value: this.value()
		};
		if (this.options.values && this.options.values.length) {
			uiHash.value = this.values(index)
			uiHash.values = this.values()
		}
		this._trigger("stop", event, uiHash);
	},

	_change: function(event, index) {
		var uiHash = {
			handle: this.handles[index],
			value: this.value()
		};
		if (this.options.values && this.options.values.length) {
			uiHash.value = this.values(index)
			uiHash.values = this.values()
		}
		this._trigger("change", event, uiHash);
	},

	value: function(newValue) {

		if (arguments.length) {
			this._setData("value", newValue);
			this._change(null, 0);
		}

		return this._value();

	},

	values: function(index, newValue, animated, noPropagation) {

		if (arguments.length > 1) {
			this.options.values[index] = newValue;
			this._refreshValue(animated);
			if(!noPropagation) this._change(null, index);
		}

		if (arguments.length) {
			if (this.options.values && this.options.values.length) {
				return this._values(index);
			} else {
				return this.value();
			}
		} else {
			return this._values();
		}

	},

	_setData: function(key, value, animated) {

		$.widget.prototype._setData.apply(this, arguments);

		switch (key) {
			case 'orientation':

				this._detectOrientation();
				
				this.element
					.removeClass("ui-slider-horizontal ui-slider-vertical")
					.addClass("ui-slider-" + this.orientation);
				this._refreshValue(animated);
				break;
			case 'value':
				this._refreshValue(animated);
				break;
		}

	},

	_step: function() {
		var step = this.options.step;
		return step;
	},

	_value: function() {

		var val = this.options.value;
		if (val < this._valueMin()) val = this._valueMin();
		if (val > this._valueMax()) val = this._valueMax();

		return val;

	},

	_values: function(index) {

		if (arguments.length) {
			var val = this.options.values[index];
			if (val < this._valueMin()) val = this._valueMin();
			if (val > this._valueMax()) val = this._valueMax();

			return val;
		} else {
			return this.options.values;
		}

	},

	_valueMin: function() {
		var valueMin = this.options.min;
		return valueMin;
	},

	_valueMax: function() {
		var valueMax = this.options.max;
		return valueMax;
	},

	_refreshValue: function(animate) {

		var oRange = this.options.range, o = this.options, self = this;

		if (this.options.values && this.options.values.length) {
			var vp0, vp1;
			this.handles.each(function(i, j) {
				var valPercent = (self.values(i) - self._valueMin()) / (self._valueMax() - self._valueMin()) * 100;
				var _set = {}; _set[self.orientation == 'horizontal' ? 'left' : 'bottom'] = valPercent + '%';
				$(this).stop(1,1)[animate ? 'animate' : 'css'](_set, o.animate);
				if (self.options.range === true) {
					if (self.orientation == 'horizontal') {
						(i == 0) && self.range.stop(1,1)[animate ? 'animate' : 'css']({ left: valPercent + '%' }, o.animate);
						(i == 1) && self.range[animate ? 'animate' : 'css']({ width: (valPercent - lastValPercent) + '%' }, { queue: false, duration: o.animate });
					} else {
						(i == 0) && self.range.stop(1,1)[animate ? 'animate' : 'css']({ bottom: (valPercent) + '%' }, o.animate);
						(i == 1) && self.range[animate ? 'animate' : 'css']({ height: (valPercent - lastValPercent) + '%' }, { queue: false, duration: o.animate });
					}
				}
				lastValPercent = valPercent;
			});
		} else {
			var value = this.value(),
				valueMin = this._valueMin(),
				valueMax = this._valueMax(),
				valPercent = valueMax != valueMin
					? (value - valueMin) / (valueMax - valueMin) * 100
					: 0;
			var _set = {}; _set[self.orientation == 'horizontal' ? 'left' : 'bottom'] = valPercent + '%';
			this.handle.stop(1,1)[animate ? 'animate' : 'css'](_set, o.animate);

			(oRange == "min") && (this.orientation == "horizontal") && this.range.stop(1,1)[animate ? 'animate' : 'css']({ width: valPercent + '%' }, o.animate);
			(oRange == "max") && (this.orientation == "horizontal") && this.range[animate ? 'animate' : 'css']({ width: (100 - valPercent) + '%' }, { queue: false, duration: o.animate });
			(oRange == "min") && (this.orientation == "vertical") && this.range.stop(1,1)[animate ? 'animate' : 'css']({ height: valPercent + '%' }, o.animate);
			(oRange == "max") && (this.orientation == "vertical") && this.range[animate ? 'animate' : 'css']({ height: (100 - valPercent) + '%' }, { queue: false, duration: o.animate });
		}

	}
	
}));

$.extend($.ui.slider, {
	getter: "value values",
	version: "1.7.1",
	eventPrefix: "slide",
	defaults: {
		animate: false,
		delay: 0,
		distance: 0,
		max: 100,
		min: 0,
		orientation: 'horizontal',
		range: false,
		step: 1,
		value: 0,
		values: null
	}
});

})(jQuery);


/*
*   Lazy Slider, 16/7/2009
*
*/

/* if you have <ul id="lazyslider">li>element1</li>
            <li>element2</li>
            <li>element3</li>
            <li>element4</li>
            <li>element5</li>
            <li>element6</li>
        </ul>
        on your html page, using this plugin will create the following markup
                
    <div class="lazywrapper">
    <div class="lazyslider-container">
        <ul id="lazyslider" class="lazy-skin">
            <li>element1</li>
            <li>element2</li>
            <li>element3</li>
            <li>element4</li>
            <li>element5</li>
            <li>element6</li>
        </ul>
        <div class="lazyslider ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all">
        <span class="slider-lbl1"/>
        <span class="slider-lbl2"/>
        <span class="slider-lbl3"/>
        <span class="slider-lbl4"/>
        <span class="slider-lbl5"/>
        <a href="#" class="ui-slider-handle ui-state-default ui-corner-all" style="left: 0%;"/>
        </div>
    </div>
    </div>
*/

(function($) {
$.fn.lazyslider=function(o){
        return this.each(function(){
           new $ls(this,o);
        });
};

    var defaults={
        step: 8,  //brzina na vrtenje na listata
        fastleft:'.slider-lbl1', //elementot koj sho kje bide za brzo u levo
        left:'.slider-lbl2',
        right:'.slider-lbl3',
        sliderClassname:'lazyslider',
        fastright:'.slider-lbl5',
        btnsWidth:100,
        btnsHeight:23,
        leftPos:100,
        fastleftPos:0,
        fastrightPos:0,
        slowcontrols:true,
        rightPos:100
    };

    

$.lazyslider=function (e,o) {
        //opcii na izvrsuvanje na plagino
     this.options    = $.extend({}, defaults, o || {});
     //li listata od sliki
     this.list=null;
     this.container=null;
     this.slidero=null;
     this.sirina=null;
     this.wid='width';
     this.lef='left';
     var self=this;
     
             if (e.nodeName == 'UL' || e.nodeName == 'OL') {
            	 this.list = $(e);
            	 this.container = this.list.parent();

            if (this.container.hasClass('lazyslider-container')) {
                if (!this.container.parent().hasClass('lazywrapper'))
                	this.container = this.container.wrap('<div></div>').parent().addClass('lazywrapper');

                this.container = this.container.parent();
            } else if (!this.container.hasClass('lazyvlad-container'))
                this.container = this.list.wrap('<div></div>').parent().append('<div class="ctrls"><span class="slider-lbl1"></span><span class="slider-lbl2"></span><span class="slider-lbl3"></span><span class="slider-lbl4"></span><span class="slider-lbl5"></span></div>').addClass('lazyslider-container').wrap('<div></div>').parent().addClass('lazywrapper');
        } else {
            this.container = $(e);
            this.list = $(e).find('>ul,>ol,div>ul,div>ol');
        }
        
        
             this.container.append('<div class="lazyhandle-container"><div class="'+this.options.sliderClassname+'"></div></div>').children('div');
             this.slidero=$('.'+this.options.sliderClassname);


             var li=this.list.children('li');
             var cw=self.intval(this.list.parent().css('width'));



 if (li.size() > 0) {
            var wh = 0;
            li.each(function() {
                wh += self.dimension(this);
            });
this.list.css(this.wid,wh+'px');
this.sirina=wh-cw;
this.slidero.slider({
          min: 0,
          max: wh-cw,
          animate:true,
          slide: function (ev, ui) {
          self.list.css('left', '-' + ui.value + 'px');
          }, 
          change: function (ev, ui) {
            self.list.animate({ 'left' : '-' + ui.value + 'px' }, 500, 'linear');
          }
        });

	//mozebi ne se deklarirani vo css-sot zatoa gi deklarirame na novo tuka
    $(this.options.fastleft).css({'width':this.options.btnsWidth+'px','height':this.options.btnsHeight+'px','left':this.options.fastleftPos+'px','position': 'absolute','z-index': '500'});    
    if (this.options.slowcontrols){
    $(this.options.left).css({'width':this.options.btnsWidth+'px','height':this.options.btnsHeight+'px','left':this.options.leftPos+'px','position': 'absolute','z-index': '500'});
    $(this.options.right).css({'width':this.options.btnsWidth+'px','height':this.options.btnsHeight+'px','right':this.options.rightPos+'px','position': 'absolute','z-index': '500'});
    }
    $(this.options.fastright).css({'width':this.options.btnsWidth+'px','height':this.options.btnsHeight+'px','right':this.options.fastrightPos+'px','position': 'absolute','z-index': '500'});
    
		this.moveleft($(this.options.fastleft),this.options.step);
		if (this.options.slowcontrols){
        this.moveleft($(this.options.left),self.intval(this.options.step*0.3));
		this.moveright($(this.options.right),self.intval(this.options.step*0.3));
        }
		this.moveright($(this.options.fastright),this.options.step);
 }
};
var $ls=$.lazyslider;

	$ls.fn = $ls.prototype = {
        lazyslider: '0.0.1'
    };
    
    $ls.fn.extend=$ls.extend=$.extend;

$ls.fn.extend({
    dimension:function (e){ 
    var el = e.jquery != undefined ? e[0] : e;
    //mora da ima display:block i da ima width definirano za da rabote u safari i chrome
    var padding=this.intval($(el).css('padding-left'))+this.intval($(el).css('padding-right'));
    var old=this.intval($(el).css('width'))+padding;
    return old;
    },
    intval: function(v) {
            v = parseInt(v);
            return isNaN(v) ? 0 : v;
    },
    moveleft: function (el,step){
    
 
        var povtari=null;
        if (!el)
            return 0;

        
         var list=this.list;
         var mi=this.intval;
         var slidero=this.slidero;
         

       el.hover(
            function(){
                var numlevo=mi(list.css('left'));
                povtari=setInterval(function(){
                    numlevo=numlevo+step;
                    if (numlevo>0) {clearInterval(povtari);list.css('left',0 + 'px');return null;}
                    list.css('left',numlevo + 'px');
                    slidero.slider('option','value',numlevo*(-1));},20);
                    $(this).addClass('hover');
            },
            function(){
                $(this).removeClass('hover');
                clearInterval(povtari);});
                
            },
     moveright: function (el,step) {
         var povtari=null;
        if (!el)
            return 0;
         
         var list=this.list;
         var mi=this.intval;
         var slidero=this.slidero;
         var sirina=this.sirina;
            
            el.hover(
            function(){
               var numlevo=mi(list.css('left'));
                povtari=setInterval(function(){
                    numlevo=numlevo-step;
                    if (numlevo<sirina*(-1)) {clearInterval(povtari);list.css('left',sirina*(-1)+'px');return null;}
                    list.css('left',numlevo+'px');
                    slidero.slider('option','value',numlevo*(-1));},20);
                     $(this).addClass('hover');
            },
            function(){
                 $(this).removeClass('hover');
                clearInterval(povtari);});
     }
 });
})(jQuery);

/*jquery.lazybox
7/31/2009
*/
(function($) {
$.fn.lazybox=function(o){
       _init();
       options = $.extend({}, defaults, o || {});
       dbox=$.extend({},{
             wrapper:$("#lb_lazybox"),
             window:$("#lb_window"),
             imageholder:$("#lb_imageholder"),
             captionholder:$("#lb_caption"),
             close:$("#lb_closebutton a"),
             overlay:$("#lb_overlay"),
             loader:$('#lb_loader'),
             footer:$('#lb_footer'),
             previous:$('#lb_previous'),
             next:$('#lb_next'),
             prevImg:-1,
             actImg:0,
             nextImg:1,
             loaderdim:{width:options.ajaxwidth,height:options.ajaxheight}
           
       }); 
       var pictures=new Array();
       dbox.close.bind("click",function(e){dbox.wrapper.hide();return false;});
       dbox.next.bind("click",function(e){showHelper(dbox.nextImg,pictures);return false;});
       dbox.previous.bind("click",function(e){showHelper(dbox.prevImg,pictures);return false;}); 
       return this.each(function(id){
                var apic={idto:id,href:this.href,caption:this.title || $(this).text() || this.href,loaded:false,width:0,height:0};
                pictures.push(apic);
         $(this).bind("click",function(e){showHelper(id,pictures);return false;});
         });
};
var defaults={
        ajaxwidth:32,  //sirina na ajax slikata
        ajaxheight:32, //visina na ajax slikata
        paddingLR:5, //kolku px padding kje ima megu bordero i slikata sho kje se prikazuva
        footer:'<a href="http://adamantus.mk">Adamantus</a> &copy; All Rights Reserved' //tekst vo footero      
};
function getType(url){
                var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
                var urlType = url.toLowerCase().match(urlString);
                return urlType;
            };
function printobj(object){
                var pr='';
                for (var key in object) {
                pr=pr+key+': '+object[key]+'<br>';
                }
               return pr;
            };
function viewport(){
                return {
                    x: $(window).scrollLeft(),
                    y: $(window).scrollTop(),
                    cx: $(window).width(),
                    cy: $(window).height()
                };
            };
function prepareHelper(imgobj,action){
          switch (action)
          {
              case 'show':
                        dbox.loader.hide();
                        dbox.captionholder.html(imgobj.caption);
                        dbox.captionholder.show();
                        dbox.footer.html(options.footer);
                        dbox.footer.show();
                        dbox.previous.show();
                        dbox.next.show();
                        dbox.imageholder.show();break;
              case 'loading':
                        dbox.loader.show();
                        dbox.imageholder.html("");
                        dbox.captionholder.hide();
                        dbox.close.hide();
                        dbox.next.hide();
                        dbox.previous.hide();
                        dbox.imageholder.hide();
                        dbox.footer.hide();
                        position(dbox.loaderdim);
                        dbox.wrapper.show();break;
          }
};
function showHelper(actImg,pictures){
                var imgobj=pictures[actImg]!=undefined?pictures[actImg]:'nopic';
                
                if (getType(imgobj.href)){
                    prepareHelper(imgobj,'loading');
                  if (imgobj.loaded){
                        var dimensions={width:imgobj.width,height:imgobj.height};

                        prepareHelper(imgobj,'show');
                        dbox.actImg=imgobj.idto;
                        var prevImg=dbox.actImg-1;
                        var nextImg=dbox.actImg+1;

                        preloadNext(nextImg,pictures);
                        preloadPrev(prevImg,pictures);
                        
                        dbox.imageholder.html("<img src='"+imgobj.href+"' alt='' />");
                        position(dimensions);
                        dbox.close.show();
                        dbox.wrapper.show();
                    }
                     else{
                         loadImg(actImg,pictures);
                     }
                }
             };
function loadImg(actImg,pictures,action){
           if (typeof action=='undefined') action='loading';
                     var imgobj=pictures[actImg]!=undefined?pictures[actImg]:'nopic';
                      //$('#status').html(printobj(imgobj));
                      if (getType(imgobj.href)){
                      if (!imgobj.loaded){
                            var img=new Image();
                            img.onload=function(){
                                    imgobj.loaded=true;
                                    imgobj.width=this.width;
                                    imgobj.height=this.height;
                                    if (action!='preload') showHelper(actImg,pictures);
                                    img.onload=function(){};
                            }
                            img.src=imgobj.href;
                        }
                    }
};
function preloadNext(nextImg,pictures){
    var nextPic=pictures[nextImg];
               if (nextPic!=undefined){
                   dbox.next.show();
                   if (!(getType(nextPic.href))){
                        preloadNext(nextImg+1,pictures);
                        //dbox.next.hide();
                    }
                    else{
                      dbox.nextImg=nextPic.idto;
                      loadImg(dbox.nextImg,pictures,'preload');
                      //dbox.next.show();
                    }
                }
                else{
                    dbox.next.hide();
                }
};
function preloadPrev(prevImg,pictures){
    var prevPic=pictures[prevImg];
            if(prevPic!=undefined){
                dbox.previous.show();
                if(!(getType(prevPic.href))){
                    preloadPrev(prevImg-1,pictures);
                }
                else{
                    dbox.prevImg=prevPic.idto;
                    loadImg(dbox.prevImg,pictures,'preload');
                }
            }
            else{
                dbox.previous.hide();
            }
};
function preload(actImg,pictures){
        var imgobj=pictures[actImg]!=undefined?pictures[actImg]:'nopic';
        
};
function position(dimensions){
                var de = document.documentElement;
                var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
                var pos=viewport();
                dimensions.width=dimensions.width>0?dimensions.width:options.ajaxwidth;
                dimensions.height=dimensions.height>0?dimensions.height:options.ajaxheight-22;
                dbox.window.css({width:(dimensions.width)+"px",left: ((w - dimensions.width)/2)+"px",top:(pos.y+15)+"px",paddingLeft:options.paddingLR,paddingRight:options.paddingLR});
                dbox.imageholder.css({width:(dimensions.width)+"px",height:(dimensions.height)+"px"});
            };

function _init()
{
    $(document.body)
    .append("<div id='lb_lazybox'></div>")
    .children('#lb_lazybox').hide()
    .append("<div id='lb_overlay'></div>")
    .append("<div id='lb_window'></div>")
    .children('#lb_window')
    .append("<div id='lb_caption'></div><div id='lb_closebutton'><a href='#'>затвори</a></div>")
    .append("<div id='lb_imageholder'></div>")
    .append("<div id='lb_previous' class='ctrbtns'><a href='#'>претходна</a></div>")
    .append("<div id='lb_next' class='ctrbtns'><a href='#'>следна</a></div>")
    .append("<div id='lb_loader'></div>")
    .append("<div id='lb_footer'></div>");
    
};
})(jQuery);

function slideSwitch() {
 var $active = $('#fade IMG.active');
 if ( $active.length == 0 ) $active = $('#fade IMG:last');
 var $next = $active.next().length ? $active.next() : $('#fade IMG:first');
// var $sibs = $active.siblings();
// var rndNum = Math.floor(Math.random() * $sibs.length );
// var $next = $( $sibs[ rndNum ] );
$active.addClass('last-active');
 $next.css({opacity: 0.0})
 .addClass('active')
 .animate({opacity: 1.0}, 2000, function() {
 $active.removeClass('active last-active');
 });
}

/*jquery.lazybox
start date: 7/31/2009
ver. 1.0.0: 8/10/2009
author:Lazarevski Vladimir 
mailto: vladimir.lazarevski@adamantus.com
*/
/*jquery plugin that enables you to zoom your pictures just like a picture viewer*/
(function($){
$.fn.lazyzoom=function(o){
        
        var el=this.get(0);
        oh=_init(el,o);
        return this.each(function(){new $lz(this,oh);});
};
    var template={
            lz_lazyzoom:'lz_lazyzoom',lz_overlay:'lz_overlay',lz_window:'lz_window',lz_caption:'lz_caption',
            lz_zoom:'lz_zoom',lz_closebutton:'lz_close',lz_imageholder:'lz_imageholder'
    };
    var defaults={
        ajaxloader:'templates/kipo/images/loader.gif',
        ajaxwidth:32,
        ajaxheight:32,
        D:{width:450,height:375,chW:250,chH:20},//image dimensions,captionholderWidth,
        cXo:-29,//controls X offsest
        cYo:25,//controls Y offset
        wTo:36,//window Top offset
        wETo:15,//window Top offset from caption
        cbXo:5,//close button X offset
        cbYo:25, //close button Y offset
        hook:'#imageholder',
        zoomer:'.controls'        
    };
    var _init=function(el,o)
        {
            var o=$.extend({}, defaults, o || {});
        if ($(o.hook).length>0&&$(o.hook).get(0).tagName=='DIV')
        {
             var object={};
          
            object.hook=$(o.hook);
            o.hooked=true;
            //object.hook.css({positon:'relative',overflow:'hidden',width:o.D.width,height:o.D.height});
            if ($(o.zoomer).length>0&&$(o.zoomer).get(0).tagName=='DIV')
            {
                object.controls=$(o.zoomer);
                object.zinb=object.controls.children('a.zin').length>0?object.controls.children('a.zin'):object.controls.append("<a class='zin' href='#'></a>").children('a.zin');
                object.zoutb=object.controls.children('a.zout').length>0?object.controls.children('a.zout'):object.controls.append("<a class='zout' href='#'></a>").children('a.zout');
            }
            object.hook.html("<img src='"+o.ajaxloader+"'/>");
           
               var LZ=new $lz(el,o);
               LZ.load_image(el.href);
              
        }
        else
        {
            
        $(document.body)
        .append("<div id='lz_lazyzoom'></div>")
        .children('#lz_lazyzoom').hide()
        .append("<div id='lz_overlay'></div>")
        .append("<div id='lz_zoom' class='trans'><a href='#' class='zin'></a><a href='#' class='zout'></a></div>")
        .append("<div id='lz_close' class='trans'><a href='#' class='close roundcorners'></a></div>")
        .append("<div id='lz_caption' class='trans'></div>")
        .append("<div id='lz_window'></div>")
        .children('#lz_window')        
        .append("<div id='lz_imageholder'></div>");
        o.hooked=false;
        }
         return o;
     };
$.lazyzoom=function(e,o){
          //  alert(o.hooked);
        this.images=[];
        this.options = $.extend({}, defaults, o || {});
        this.wrapper=$("#lz_lazyzoom");this.window=$("#lz_window");
        this.ch=$("#lz_caption");
        this.close=$("#lz_close");this.overlay=$("#lz_overlay");
        this.controls=$("#lz_zoom");this.zinb=this.controls.children('a.zin');this.zoutb=this.controls.children('a.zout');
        this.caption = e.title || $(e).text() || e.href;
        var LZ=this;
        this.D={width:0,height:0,loaded:false}; //dimenziite na slikata otkoga kje se loadira
        this.cD={width:this.options.D.width,height:this.options.D.height,iszin:false,iszoot:false};
        
        this.url=e.href;
        this.el=$(e);
        
        if (this.options.hooked)
        {
            this.hook=$(this.options.hook);
            this.controls=$(this.options.zoomer);
            this.zinb=this.controls.children('a.zin');
            this.zoutb=this.controls.children('a.zout');
            this.hook.css({position:'relative',overflow:'hidden',width:this.cD.width,height:this.cD.height});
        }
        else
        {
            this.hook=$("#lz_imageholder");
        }
        //event binding
        this.close.children('a').click(function(){LZ.hideW();return false;});
        this.close.children('a').hover(function(){$(this).addClass('hover');},function(){$(this).removeClass('hover');});
        this.el.click(function(){LZ.load_image(LZ.url);LZ.zinb.removeClass('hover');LZ.zoutb.removeClass('hover');return false;});
    }
        var $lz=$.lazyzoom;
        $lz.fn = $lz.prototype = {lazyzoom: '1.0.1'};
        $lz.fn.extend=$lz.extend=$.extend;
$lz.fn.extend({
    get_type:function(url)
    {
        var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;var urlType = url.toLowerCase().match(urlString);
        return urlType;
    },
    load_image:function(url)
    {
        if (this.get_type(url))
        {
           var D=this.D;var img=new Image();var LZ=this;
           
         if ($.browser.opera) {window.onunload=function(){};} 
//back/forward button fix (also opera wasnt firing the image when loading from cache, this solves the problem)
        //nemam pojma zasho koristam browser iako e preporacano da ne se koriste, ama ednostavno tava nema vrska
         img.onload=function(){LZ.addimage(LZ,this,url);};
         img.src=url;    
        }
     return D;  
    },
    preload:function(){
       this.hook.html("<img src='"+this.options.ajaxloader+"' />");
       this.position(true);
       if (!this.options.hooked) {
           this.ch.hide();
       this.controls.hide();
       this.close.hide();
           this.wrapper.show();
           this.window.show();
       }
      
    },
    addimage:function(LZ,img,url)
    {
        LZ.D.width=img.width;
        LZ.D.height=img.height;
        LZ.D.loaded=true;
        LZ.hook.html("<img src='"+url+"' style='width:"+LZ.cD.width+"px;height:"+LZ.cD.height+"px'/>");
        LZ.zimg=LZ.hook.children('img');
        LZ.zimg.css({'msInterpolationMode':"bicubic",width:LZ.options.D.width,height:LZ.options.D.height,position:'relative','z-index':951});
             //odredi pozicii
              LZ.position();
      if (!LZ.options.hooked)
      {
         LZ.wrapper.show();LZ.ch.html(LZ.caption);LZ.ch.show();LZ.close.show();LZ.controls.show();LZ.window.show();             }
      else
      {
                // LZ.window.hide();LZ.wrapper.show();LZ.controls.show();
      }
              //dodadi listeneri
              //iskluci go desniot klik vrz slikata
      LZ.hook.bind("contextmenu",function(e){return false;});
      LZ.zimg.bind("mousedown",{D:LZ.D,LZ:LZ},LZ._keydown);
      LZ.zinb.bind("click",{LZ:LZ},LZ._zint);
      LZ.zoutb.bind("click",{LZ:LZ},LZ._zoutt);
      $(document).bind("keydown",{LZ:LZ},LZ._dokeydown);
    },
    _dokeydown:function(e){
          e=e?e:window.event;
          a=e.altKey,s=e.shiftKey;
          if (s&&!a){e.data.LZ.cur_zoom(1,e.data.LZ.B,$(e.data.LZ.zimg));}else if (!s&&a) {e.data.LZ.cur_zoom(2,e.data.LZ.B,$(e.data.LZ.zimg));}
    },
    _mouseover:function(e){
        e=e?e:window.event;
        var code = (e.keyCode ? e.keyCode : e.which),a=e.altKey,s=e.shiftKey;
    },
    _keydown:function(e){
        var LZ=e.data.LZ;
        var D=e.data.D;
     
        var zimg=this;
        e=e?e:window.event;
        var code = (e.keyCode ? e.keyCode : e.which),a=e.altKey,s=e.shiftKey;
        var bzi=s&&!a?true:LZ.cD.iszin&&!a?true:false;
        var bzo=!s&&a?true:LZ.cD.iszoot&&!s?true:false;
        var curLeft=LZ.intval($(zimg).css('left')),curTop=LZ.intval($(zimg).css('top'));
        var mouseStartPos={startLeft:e.pageX-$(zimg).parent().offset().left,startTop:e.pageY-$(zimg).parent().offset().top};
       if (e.preventDefault){e.preventDefault();document.ondragstart=function(e){return false;}}
      if (bzi){LZ.zoom(zimg,D,mouseStartPos,true);LZ.cur_zoom(1,LZ.B,$(zimg));} else if (bzo) {LZ.zoom(zimg,D,mouseStartPos,false);LZ.cur_zoom(2,LZ.B,$(zimg));}else
       {
            var moveHandler=function(e){
                var dragLeft=e.pageX-$(zimg).parent().offset().left-mouseStartPos.startLeft,dragTop=e.pageY-$(zimg).parent().offset().top-mouseStartPos.startTop;
                var newcords=LZ.boundaries({left:curLeft+dragLeft,top:curTop+dragTop},LZ.cD);
                $(zimg).css({left:newcords.left,top:newcords.top});LZ.cur_zoom(0,LZ.B,$(zimg));
            };
            var upHandler=function(e){
                $(zimg).unbind("mousemove",moveHandler);$(zimg).unbind("mouseup",upHandler);
            };
                $(zimg).mousemove(moveHandler);$(zimg).mouseup(upHandler);$(zimg).mouseout(upHandler);
       }
    },
    cur_zoom:function(ac,browser,img)
    {
       if (ac==1)
       {img.removeClass('cur_zoomout').addClass('cur_zoomin');}
       else if (ac==2)
       {img.removeClass('cur_zoomin').addClass('cur_zoomout');}
       else
       {img.removeClass('cur_zoomin').removeClass('cur_zoomout');}
    },
    _zint:function(e)
    {   var LZ=e.data.LZ;
        
        LZ.cD.iszin=!LZ.cD.iszin;LZ.cD.iszoot=false;
        LZ.cD.iszin?LZ.cur_zoom(1,LZ.B,LZ.zimg):LZ.cur_zoom(0,LZ.B,LZ.zimg);
        $(this).hasClass('hover')?$(this).removeClass('hover'):$(this).addClass('hover');
        LZ.zoutb.removeClass('hover');
        return false;
    },
    _zoutt:function(e)
    {   
        var LZ=e.data.LZ;
        LZ.cD.iszoot=!LZ.cD.iszoot;LZ.cD.iszin=false;
        LZ.cD.iszoot?LZ.cur_zoom(2,LZ.B,LZ.zimg):LZ.cur_zoom(0,LZ.B,LZ.zimg);
        $(this).hasClass('hover')?$(this).removeClass('hover'):$(this).addClass('hover');
        LZ.zinb.removeClass('hover');
        return false;
    },
    zoom:function(zimg,dim,mouseclick,inout){
        //dim se originalnite dimenzii na slikata; this.cD e momentalnite dimenzii na slikata
       var cof=(inout?1.1:1/1.1);
       var cd=this.cD;
       var od=this.options.D;
       //od.width=od.width;
       //od.height=od.height;
       $('#footer').html('current width:'+od.width+' current height:'+od.height)
       var im_offset={left:$(zimg).css('left'),top:$(zimg).css('top')};
       cd.width=(dim.width>cd.width*cof?cd.width*cof>od.width?Math.round(cd.width*cof):od.width:dim.width);
      
       cd.height=(dim.height>cd.height*cof?cd.height*cof>od.height?Math.round(cd.height*cof):od.height:dim.height);
       $('#footer').append('current width:'+cd.width+' current height:'+cd.height);
       var z_offset=this.boundaries({left:(od.width/2)-mouseclick.startLeft+this.intval(im_offset.left),top:(od.height/2)-mouseclick.startTop+this.intval(im_offset.top)},cd);
       $(zimg).css({width:cd.width,height:cd.height,left:z_offset.left,top:z_offset.top});
    },
    intval: function(v) {
        v = parseInt(v);
        return isNaN(v) ? 0 : v;
    },

    show:function(win,cont,close,caphead){
        
          LZ.wrapper.show();
          LZ.ch.html(LZ.caption);
          
          LZ.ch.show();
          LZ.close.show();
          LZ.controls.show();     
    },
    hideW:function(){
        this.cD.width=this.options.D.width;this.cD.height=this.options.D.height;this.cD.iszin=false;this.cD.iszoot=false;
        this.zinb.removeClass('hover');this.zoutb.removeClass('hover');
        this.wrapper.hide();
    },
    position:function(pre){
     var pos=this.viewport();
     var O=this.options;
     if (!O.hooked)
     {
     var imgWidth=O.D.width>0?pre?32:O.D.width:250;
     var imgHeight=O.D.height>0?pre?32:O.D.height:375;
     this.window.css({width:(imgWidth),height:(imgHeight),left: ((pos.cx - imgWidth)/2),top:(pos.y+O.wTo)});
     this.controls.css({left:((pos.cx-imgWidth)/2)+O.cXo,top:(pos.y+O.cYo+O.D.chH+O.wTo+imgHeight/2)});
     this.close.css({left:((pos.cx+imgWidth)/2)+O.cbXo,top:pos.y+O.wTo});
     this.ch.css({width:O.D.width-7,height:O.D.chH,left:((pos.cx-imgWidth)/2)+3,top:pos.y+O.wTo+3});
     }
     else
     {
        //$('#status5').html('left:'+this.hook.offset().left+' Top:'+this.hook.offset().top);
        this.controls.css({left:this.hook.offset().left,top:this.hook.offset().top});
     }
   },
   boundaries:function(newcords,D){
        var rightbound=D.width>this.options.D.width?(D.width-this.options.D.width)*(-1):0;
        var bottombound=D.height>this.options.D.height?(D.height-this.options.D.height)*(-1):0;
        if (newcords.left>0) newcords.left=0;
        if (newcords.left<rightbound) newcords.left=rightbound;
        if (newcords.top>0) newcords.top=0;
        if (newcords.top<bottombound) newcords.top=bottombound;
        return newcords;
    },
    viewport:function(){
        return {
            x: $(window).scrollLeft(),
            y: $(window).scrollTop(),
            cx: $(window).width(),
            cy: $(window).height()
        };
  }
});
})(jQuery);

(function($) {
    $.extend({
        ahover: {
            version: 1.0,
            defaults: {
                toggleSpeed: 75,
                toggleEffect: 'both',
                hoverEffect: null,
                moveSpeed: 250,
                easing: 'swing',
                className: 'ahover'
            },
            effects: {
                'width': {width: 0},
                'height': {height: 0},
                'both': {width: 0, height: 0}
            }
        }
    });
    
    $.fn.extend({
        ahover: function(options) {
            var options = $.extend({}, $.ahover.defaults, options);
            var effect = (
                (typeof options.toggleEffect == 'string') ?
                $.ahover.effects[options.toggleEffect] : options.toggleEffect
            );
            var parent = this.offsetParent();
            return this.hover(
                function(e) {
                    var over = $(this);
                    var overSize = {
                        width: over.outerWidth(),
                        height: over.outerHeight()
                    };
                    var overOffset = over.offset();
                    var parentOffset = parent.offset();

                    var under = $('div.' + options.className, parent).stop();
                    var created = (under.length == 0);
                    if (created) {
                        under = $('<div>&nbsp;</div>')
                            .addClass(options.className)
                            .appendTo(parent).css(overSize);
                    }
                    
                    var underOffset = {
                        left: overOffset.left - parentOffset.left -
                            (under.outerWidth() - under.width()) / 2,
                        top: overOffset.top - parentOffset.top -
                            (under.outerHeight() - under.height()) / 2
                    }

                    if (created) {
                        under.css(underOffset).css(effect).animate(overSize, {
                            queue: false,
                            duration: options.toggleSpeed,
                            easing: options.easing
                        });
                    }
                    else {
                        var underCSS = $.extend({}, overSize, underOffset);
                        under.animate(underCSS, {
                            queue: false,
                            duration: options.moveSpeed,
                            easing: options.easing
                        });
                    }
                    if ($.isFunction(options.hoverEffect)) {
                        under.queue(options.hoverEffect);
                    }
                },
                function(e) {
                    $('div.' + options.className, parent).animate(effect, {
                        queue: false,
                        duration: options.toggleSpeed,
                        easing: options.easing,
                        complete: function() { $(this).remove(); }
                    });
                }
            );
        }
    });
})(jQuery);

/*jquery.lazypic
1/11/2010
*/
(function($) {
$.fn.lazypic=function(o){
		
       options = $.extend({}, defaults, o || {});
                     _init();
       dbox=$.extend({},{
             captionholder:$("#lazy_caption"),
             loader:$('#lazy_loader'),
             image:$('#lazy_image'),
             previous:$('#lazy_previous'),
             next:$('#lazy_next'),
             wrapper:$('.'+options.imageholder),
             prevImg:-1,
             actImg:0,
             nextImg:1,
             startImg:1,
             loaderdim:{width:options.ajaxwidth,height:options.ajaxheight}
       },defaults); 
		 
		  outerwidth=dbox.image.outerWidth();
        outerheight=dbox.image.outerHeight();
        dbox.wrapper.css({width:outerwidth});  
        dbox.loader.css({top:outerheight/2,left:outerwidth/2});
		 
		 
       var pictures=new Array();
       caption=$('#lazy_caption');
       dbox.next.bind("click",function(e){showHelper(dbox.nextImg,pictures);return false;});
       dbox.previous.bind("click",function(e){showHelper(dbox.prevImg,pictures);return false;}); 
       		
       		if ($(this).length>0){
       		startImg = $(this)[dbox.startImg];
       		//first let's load the starting image, outside the loop so we avoid waiting for it while the other pictures load
      		var apic={
       			idto:dbox.startImg,
					href:startImg.href,
       			caption:startImg.title||starImg.text()||startImg,
       			loaded:false,
       			width:0,
       			height:0
       		}
       		pictures[dbox.startImg]=apic;
				showHelper(dbox.startImg,pictures); //show the picture. it will load it in the process
				}
       return this.each(function(id){
       	 	//lets give a click event to every thumbnail picture in the slider
                var apic={idto:id,href:this.href,caption:this.title || $(this).text() || this.href,loaded:false,width:0,height:0};
                pictures[id]=apic;
					 $(this).bind("click",function(e){showHelper(id,pictures);return false;});
       });
};
var defaults={
        ajaxwidth:32,  //sirina na ajax slikata
        ajaxheight:32, //visina na ajax slikata
        imageholder:"lazy_imageholder",
        ajaxloader:"templates/prezident/images/ajax-loader.gif"
};
function getType(url){
                var urlString = /\.jpg$|\.jpeg$|\.png$|\.gif$|\.bmp$/;
                var urlType = url.toLowerCase().match(urlString);
                return urlType;
            };
function printobj(object){
                var pr='';
                for (var key in object) {
                pr=pr+key+': '+object[key]+'<br>';
                }
               return pr;
            };
function viewport(){
                return {
                    x: $(window).scrollLeft(),
                    y: $(window).scrollTop(),
                    cx: $(window).width(),
                    cy: $(window).height()
                };
            };
function prepareHelper(imgobj,action){
          switch (action){
              case 'show':
                 var dimensions={width:imgobj.width,height:imgobj.height};
					  position(dimensions,imgobj);
                 this.caption.html('<span>'+imgobj.caption+'</span>');
                 this.caption.show();
                 
               break;
              case 'loading':
              		dbox.loader.show();
              		$('#lazy_caption').hide();
              break;
          }
};
function showHelper(actImg,pictures){
               

                var imgobj=pictures[actImg]!=undefined?pictures[actImg]:'nopic';
                
                if (getType(imgobj.href)){
              	  prepareHelper(imgobj,'loading');
                  if (imgobj.loaded){
                       prepareHelper(imgobj,'show');
                        dbox.actImg=imgobj.idto;
                        var prevImg=dbox.actImg-1;
                        var nextImg=dbox.actImg+1;
								preloadNext(nextImg,pictures);
                        preloadPrev(prevImg,pictures);
                    }
                     else{
                         loadImg(actImg,pictures);
                     }
                }

             };
function loadImg(actImg,pictures,action){
           if (typeof action=='undefined') action='loading';
                     var imgobj=pictures[actImg]!=undefined?pictures[actImg]:'nopic';
                      
                      if (getType(imgobj.href)){
                      if (!imgobj.loaded){
                            var img=new Image();
                            img.onload=function(){
                                    imgobj.loaded=true;
                                    imgobj.width=this.width;
                                    imgobj.height=this.height;
                                    if (action!='preload') showHelper(actImg,pictures);
                                    img.onload=function(){};
                            }
                            img.src=imgobj.href;
                        }
                    }
};
function preloadNext(nextImg,pictures){
    var nextPic=pictures[nextImg];
               if (nextPic!=undefined){
                   dbox.next.show();
                   if (!(getType(nextPic.href))){
                        preloadNext(nextImg+1,pictures);
                        //dbox.next.hide();
                    }
                    else{
                      dbox.nextImg=nextPic.idto;
                      loadImg(dbox.nextImg,pictures,'preload');
                      //dbox.next.show();
                    }
                }
                else{
                    dbox.next.hide();
                }
};
function preloadPrev(prevImg,pictures){
    var prevPic=pictures[prevImg];
            if(prevPic!=undefined){
                dbox.previous.show();
                if(!(getType(prevPic.href))){
                    preloadPrev(prevImg-1,pictures);
                }
                else{
                    dbox.prevImg=prevPic.idto;
                    loadImg(dbox.prevImg,pictures,'preload');
                }
            }
            else{
                dbox.previous.hide();
            }
};
function preload(actImg,pictures){
        var imgobj=pictures[actImg]!=undefined?pictures[actImg]:'nopic';
        
};
function position(dimensions,imgobj){
              var de = document.documentElement;
              var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
              var pos=viewport();
              dimensions.width=dimensions.width>0?dimensions.width:options.ajaxwidth;
              dimensions.height=dimensions.height>0?dimensions.height:options.ajaxheight-22;
              outerwidth=dbox.image.outerWidth();
              outerheight=dbox.image.outerHeight();
              	dbox.wrapper.css({width:outerwidth});  
         	  	dbox.loader.css({top:outerheight/2,left:outerwidth/2});
				  	
				  	img=new Image();
				  	img.onload=function(){
				  	  	dbox.image.children("img").attr({src:imgobj.href});
				  	  						dbox.image.children("img").animate({width:(dimensions.width),height:(dimensions.height)},{
						duration:300,complete:function(){					}
						});	
						   dbox.image.css({width:(dimensions.width),height:(dimensions.height)});
						   dbox.loader.hide();
						   outerwidth=dbox.image.outerWidth();
            			dbox.wrapper.css({width:outerwidth}); 
					}
					img.src=imgobj.href;
					




};

function _init()
{
			$("."+options.imageholder)
			.append("<div id='lazy_loader'></div>")
			.append("<div class='contr'><div id='lazy_previous' class='ctrbtns'><a href='#'>претходна</a></div><div id='lazy_next' class='ctrbtns'><a href='#'>следна</a></div></div>")
			.append("<div id='lazy_image'><img src='' alt='' /><div id='lazy_caption'></div></div>")
			
    
};
})(jQuery);


