function initPage()
{
	clearFormFields({
		clearInputs: true,
		clearTextareas: true,
		passwordFieldText: false,
		addClassFocus: "focus",
		filterClass: "default"
	});
}
function clearFormFields(o)
{
	if (o.clearInputs == null) o.clearInputs = true;
	if (o.clearTextareas == null) o.clearTextareas = true;
	if (o.passwordFieldText == null) o.passwordFieldText = false;
	if (o.addClassFocus == null) o.addClassFocus = false;
	if (!o.filterClass) o.filterClass = "default";
	if(o.clearInputs) {
		var inputs = document.getElementsByTagName("input");
		for (var i = 0; i < inputs.length; i++ ) {
			if((inputs[i].type == "text" || inputs[i].type == "password") && inputs[i].className.indexOf(o.filterClass) == -1) {
				inputs[i].valueHtml = inputs[i].value;
				inputs[i].onfocus = function ()	{
					if(this.valueHtml == this.value) this.value = "";
					if(this.fake) {
						inputsSwap(this, this.previousSibling);
						this.previousSibling.focus();
					}
					if(o.addClassFocus && !this.fake) {
						this.className += " " + o.addClassFocus;
						this.parentNode.className += " parent-" + o.addClassFocus;
					}
				}
				inputs[i].onblur = function () {
					if(this.value == "") {
						this.value = this.valueHtml;
						if(o.passwordFieldText && this.type == "password") inputsSwap(this, this.nextSibling);
					}
					if(o.addClassFocus) {
						this.className = this.className.replace(o.addClassFocus, "");
						this.parentNode.className = this.parentNode.className.replace("parent-"+o.addClassFocus, "");
					}
				}
				if(o.passwordFieldText && inputs[i].type == "password") {
					var fakeInput = document.createElement("input");
					fakeInput.type = "text";
					fakeInput.value = inputs[i].value;
					fakeInput.className = inputs[i].className;
					fakeInput.fake = true;
					inputs[i].parentNode.insertBefore(fakeInput, inputs[i].nextSibling);
					inputsSwap(inputs[i], null);
				}
			}
		}
	}
	if(o.clearTextareas) {
		var textareas = document.getElementsByTagName("textarea");
		for(var i=0; i<textareas.length; i++) {
			if(textareas[i].className.indexOf(o.filterClass) == -1) {
				textareas[i].valueHtml = textareas[i].value;
				textareas[i].onfocus = function() {
					if(this.value == this.valueHtml) this.value = "";
					if(o.addClassFocus) {
						this.className += " " + o.addClassFocus;
						this.parentNode.className += " parent-" + o.addClassFocus;
					}
				}
				textareas[i].onblur = function() {
					if(this.value == "") this.value = this.valueHtml;
					if(o.addClassFocus) {
						this.className = this.className.replace(o.addClassFocus, "");
						this.parentNode.className = this.parentNode.className.replace("parent-"+o.addClassFocus, "");
					}
				}
			}
		}
	}
	function inputsSwap(el, el2) {
		if(el) el.style.display = "none";
		if(el2) el2.style.display = "inline";
	}
}
if (window.addEventListener)
	window.addEventListener("load", initPage, false);
else if (window.attachEvent)
	window.attachEvent("onload", initPage);


/*
 * jQuery galleryCircle v1.0.4
 *****************************************************************
	btPrev: 'a.prev',				button prev
	btNext: 'a.next',				button next
	holderList: 'div',				holder of elements window were you see sliding elements !  CSS for this element:	 div {position: relative;	width: "your width" ; 	overflow: hidden;}
	scrollElParent: 'ul',			holder of all sliding elements
	scrollEl: 'li',					element wich would slide
	numHolder: 'div.num-control',	holder of control element
	numCreate: false,				create new num control or use default (wich exist in markup) can be: False or True
	step: false,					boolean false= scroll on window width, true = scroll on each element width
	innerMargin: 0,					if "ul" has some default margin that is not  "0" set it here
	switchTime: false,				time between sliding image: 	false or some integer 1000 = 1 sec
	duration : 1500					time of animation			some integer 1000 = 1 sec
 *****************************************************************
 */

jQuery.fn.galleryCircle = function(_options){
	// defaults options
	var _options = jQuery.extend({
		btPrev: 'a.prev',
		btNext: 'a.next',
		holderList: 'div',
		scrollElParent: 'ul',
		scrollEl: 'li',
		numHolder: false,
		numCreate: false,
		step: false,
		innerMargin: 0,
		curPage: false,
		onClick: null,
		onChangeFunc: null,
		easing: 'linear',
		switchTime: false,
		duration : 1500
	},_options);

	return this.each(function(){
		var _this = jQuery(this);
		var _next = jQuery(_options.btNext, _this).length ? jQuery(_options.btNext, _this) : false;
		var _prev = jQuery(_options.btPrev, _this).length ? jQuery(_options.btPrev, _this) : false;
		var _holderList = jQuery(_options.holderList, _this);
		var _scrollElParent = jQuery(_options.scrollElParent, _holderList).css('position', 'relative');
		var _scrollEl = jQuery(_options.scrollEl, _scrollElParent);
		var _numHolder = false ;
		if (_options.numHolder) _numHolder = jQuery(_options.numHolder, _this).length ? jQuery(_options.numHolder, _this) : false;
		var _step, _t = null;
		var _widthSum = 0;
		_scrollEl.each(function(){_widthSum += jQuery(this).outerWidth(true);})
		var _startPosition = _scrollEl.index(_scrollEl.filter('.active'));
		if (_startPosition==-1) _startPosition=0;
		_scrollEl.removeClass('active');
		var _easing = _options.easing;
		if(_options.switchTime) var _switchTime = _options.switchTime + _options.duration;

		if (!_options.step) _step = _holderList.innerWidth();
		var _margin = _widthSum;
		_scrollElParent.append(_scrollEl.clone(true));
		_scrollElParent.prepend(_scrollEl.clone(true));

		var _offsetStartPosition =0;
		_offsetStartPosition = culcOffset(_startPosition);

		_scrollElParent.css('left', (-_margin+_options.innerMargin-_offsetStartPosition));

		//auto rotation
		function autoRotate(){
			if (_switchTime){
				_t = setTimeout(function(){
					nextSlides();
				},_switchTime)
			}
		}
		autoRotate();

		//button next "click"
		if (_next) {
			_next.click(function(){
				if (!_scrollElParent.is(':animated')) {
					if (jQuery.isFunction(_options.onClick)) _options.onClick.apply(_this);
					nextSlides();
				}
				return false;
			});
		}

		//button prev "click"
		if (_prev) {
			_prev.click(function(){
				if (!_scrollElParent.is(':animated')) {
					if (jQuery.isFunction(_options.onClick)) _options.onClick.apply(_this);
					prevSlides();
				}
				return false;
			});
		}

		//curent position
		function getCurElIndex(){
			var _curMargin = parseInt(_scrollElParent.css('left')) + _widthSum - _options.innerMargin;
			for(i=0; i < _scrollEl.length; i++){
				if (_curMargin == 0) return i;
				if (_curMargin <= _options.innerMargin) _curMargin += _scrollEl.eq(i).innerWidth(true);
				else _curMargin -= _scrollEl.eq(i).innerWidth(true);
				if (_curMargin == _options.innerMargin) return i+1;
			}
		}

		// offset of gallery if when activ element not first at start 
		function culcOffset(_ind){
			var _tmpcounter=0;
			var _pos=0;
			while (_tmpcounter < _ind){
				_pos += _scrollEl.eq(_tmpcounter).outerWidth(true);
				_tmpcounter++;
			};
			return _pos;
		}

		//go next slide
		function nextSlides(){
			if (_t) clearTimeout(_t);
			if (_options.step) {
				_curElIndex = getCurElIndex();
				_step = _scrollEl.eq(_curElIndex).innerWidth(true);
			};
			_margin = -parseInt(_scrollElParent.css('left'));
			_margin += _step;
			
			_scrollElParent.animate({'left':(-_margin+_options.innerMargin)}, {duration:_options.duration, easing: _easing, complete:function(){
				if (_margin >= _widthSum*2) {
					_margin = _widthSum + (_margin - _widthSum*2);
				}
				_scrollElParent.css({'left':-_margin+_options.innerMargin});
				jQuery.fn.galleryCircle.numListActive(_numHolder, _scrollEl);

				if (jQuery.isFunction(_options.onChangeFunc)) {
					_options.onChangeFunc.apply(_holderList);
				}
				//autoslide
				if (_switchTime) {
					_t = setTimeout(function(){
						nextSlides();
					},_switchTime)
				}
			}});
		}

		function changeSlide(){
			if (_t) clearTimeout(_t);
			if(_options.direction=='vertical'){
				
			}else{
				
			}
			autoRotate();
		}
		//go prev slide
		function prevSlides(){
			if (_t) clearTimeout(_t);
			if (_options.step) {
				_curElIndex = getCurElIndex();
				if (_curElIndex == 0) _curElIndex= _scrollEl.length;
				_step = _scrollEl.eq(_curElIndex-1).innerWidth(true);
			};
			_margin = -parseInt(_scrollElParent.css('left'));
			_margin -= _step;
			_scrollElParent.animate({'left':(-_margin+_options.innerMargin)}, {duration:_options.duration, easing: _easing, complete:function(){
				if (_margin < _widthSum) {
					_margin = _widthSum*2 - (_widthSum - _margin);
				}
				_scrollElParent.css({'left':-_margin+_options.innerMargin});
				jQuery.fn.galleryCircle.numListActive(_numHolder, _scrollEl);

				if (jQuery.isFunction(_options.onChangeFunc)) {
					_options.onChangeFunc.apply(_holderList);
				}
				//autoslide
				if (_switchTime) {
					_t = setTimeout(function(){
						nextSlides();
					},_switchTime)
				}
			}});
		}

		// Number list Create
		jQuery.fn.galleryCircle.numListCreate = function(_numHolder, _scrollEl){
			var _numListElC = '';
			for(var i=0; i<_scrollEl.length; i++){
				_numListElC += '<li><a href="">'+(i+1)+'</a></li>';
			}
			jQuery(_numHolder).html('<ul>'+_numListElC+'</ul>');
		};

		// Number list Activate
		jQuery.fn.galleryCircle.numListActive = function(_numHolder, _scrollEl){
			_curElIndex = getCurElIndex();
			if (jQuery(_options.curPage, _this).length && _options.curPage) jQuery(_options.curPage, _this).text('Pagina '+(getCurElIndex()+1)+'/'+_scrollEl.length);
			if (_numHolder) {
				jQuery('a',_numHolder).removeClass('active');
				jQuery('a',_numHolder).eq(_curElIndex).addClass('active');
			}
		};

		//click on control elemens
		function numClick() {
			jQuery(_options.numHolder, _this).find('a').click(function(){
				if(_scrollElParent.is(':animated')) _scrollElParent.stop(true, true);
				if (_t) clearTimeout(_t);
				var _aList = jQuery(_options.numHolder, _this).find('a');
				var _index = _aList.index(jQuery(this));
				_margin = _widthSum + _index * _scrollEl.outerWidth(true);
				_scrollElParent.animate({'left':(-_margin+_options.innerMargin)}, {duration:_options.duration, easing: _easing, complete:function(){
					if (_margin >= _widthSum*2) {
						_margin = _widthSum + (_margin - _widthSum*2);
					}
					_scrollElParent.css({'left':-_margin+_options.innerMargin});
					_aList.removeClass('active').eq(_index).addClass('active');

					if (jQuery.isFunction(_options.onChangeFunc)) {
						_options.onChangeFunc.apply(_holderList);
					}
					//autoslide
					if (_switchTime) {
						_t = setTimeout(function(){
							nextSlides();
						},_switchTime)
					}
				}});
				return false;
			});
		};

		// init creating num list
		if (_options.numCreate) jQuery.fn.galleryCircle.numListCreate(_numHolder, _scrollEl);

		// pagination first init (example Page 2/6)
		if (jQuery(_options.curPage, _this).length && _options.curPage) jQuery(_options.curPage, _this).text('Pagina '+(getCurElIndex()+1)+'/'+_scrollEl.length);

		// init activate num list item and init numClick()
		if (_options.numHolder) {
			jQuery.fn.galleryCircle.numListActive(_numHolder, _scrollEl);
			numClick();
		}
	});
}


;(function(jQuery){
jQuery.fn.uniShow = function(_options){
	// defaults options
	var _options = jQuery.extend({
		width: 420,
		height: 90,
		bannerText: false,
		bgColor: false,
		scrollElParent: '> ul',
		scrollEl: '> li',
		onMouseOver: null,
		numHolderClass: false,
		thumsBG: '#f00',
		thumsBGActive: '#0f0',
		transition: 'fade',
		autoStart: true,
		switchTime: 5000,
		duration : 500
	},_options);

	return this.each(function(){
		var _this = this;

		//options
		_this.opt = {
			width 			:				_options.width,
			height			:				_options.height,
			bannerText 		:				_options.bannerText,
			bgColor			:				_options.bgColor,
			scrollElParent 	:				_options.scrollElParent,
			scrollEl 		:				_options.scrollEl,
			numHolderClass 	:				_options.numHolderClass ? ((_options.numHolderClass==true) ? ' ' : _options.numHolderClass) : false,
			onMouseOver 	:				_options.onMouseOver,
			pause 			:				false,
			animated		:				false,
			thumbs 			:				null,
			thumsBG			:				_options.thumsBG,
			thumsBGActive 	:				_options.thumsBGActive,
			transition 		:				_options.transition,
			autoStart 		:				_options.autoStart,
			switchTime 		:				_options.switchTime,
			duration 		:				_options.duration
		};

		//options

		//get element 
		_this.parent = jQuery(_this).find(_this.opt.scrollElParent);
		_this.els = jQuery(_this.opt.scrollEl, _this.parent);

		//def settings for holder 
		jQuery(_this).css({
			position: 'relative',
			overflow: 'hidden',
			width: _this.opt.width,
			height: _this.opt.height,
			'background-color': _this.opt.bgColor
		}).mouseenter(function(){
			if(_this.opt.timer) clearTimeout(_this.opt.timer);
			_this.opt.pause = true;
			if (jQuery.isFunction(_this.opt.onMouseOver)) {
				_this.opt.onMouseOver.apply(_this);
			};
		}).mouseleave(function(){
			_this.opt.pause = false;
			jQuery.fn.uniShow.autoslide(_this, _this.els, _this.opt);
		});
		jQuery(_this.parent).css({
			position: 'relative',
			overflow: 'hidden',
			width: _this.opt.width,
			height: _this.opt.height
		});
		jQuery(_this.els).css({
			position: 'absolute',
			top:0,
			left:0,
			width: _this.opt.width,
			height: _this.opt.height
		});

		//create thumbs
		_this.opt.active = 0;
		_this.els.eq(_this.opt.active).css('zIndex',1);
		_this.opt.next = 0;
		if(_this.opt.numHolderClass && _this.els.length > 1){
			var _html = '<ul class="'+_this.opt.numHolderClass+'">';
			for(var i=0; i<_this.els.length; i++) {
				_html+='<li><a href="#">'+(i+1)+'</a></li>';
			};
			_html += '</ul>';
			_this.opt.thumbs = jQuery(_html);
			jQuery(_this).append(_this.opt.thumbs);
			_this.opt.thumbs = _this.opt.thumbs.find('li');
			jQuery.fn.uniShow.activatePager(_this, _this.opt);

			_this.opt.thumbs.click(function(){
				if(_this.opt.thumbs.index(this) != _this.opt.active && !_this.opt.animated){
					_this.opt.animated = true;
					_this.opt.next = _this.opt.thumbs.index(this);
					jQuery.fn.uniShow.activatePager(_this, _this.opt);
					var init = jQuery.fn.uniShow.transition[_this.opt.transition];
					if (jQuery.isFunction(init)) init(_this, _this.els, _this.opt);
				}
				return false;
			});
		};

		if(_this.opt.bannerText){
			_this.bText = jQuery('<p>'+_this.opt.bannerText+'</p>');
			jQuery(_this).append(_this.bText);
		};

		jQuery.fn.uniShow.autoslide(_this, _this.els, _this.opt);
	});
};

jQuery.fn.uniShow.activatePager = function(_this, opt){
	if(_this.opt.thumbs){
		_this.opt.thumbs.eq(_this.opt.next).addClass('active');
		_this.opt.thumbs.css({
			background: _this.opt.thumsBG
		}).eq(_this.opt.next).css({
			background: _this.opt.thumsBGActive
		});
	};
}
//transition default - fade
jQuery.fn.uniShow.transition = {
	fade: function(_cont, _slides, opt){
		if(opt.timer) clearTimeout(opt.timer);
		_slides.css({zIndex: 1});
		_slides.eq(opt.active).removeClass('active').css({
			display:'block',
			opacity: 1,
			zIndex: 2,
			left: 0,
			top: 0
		}).animate({opacity: 0},{duration:opt.duration});
		_slides.eq(opt.next).css({
			display:'block',
			opacity: 0,
			left: 0,
			zIndex: 3,
			top: 0
		}).addClass('active').animate({opacity: 1}, {duration:opt.duration,complete: function(){
			jQuery(this).css('opacity','auto');
			opt.active = opt.next;
			opt.autoStart = 0;
			opt.animated = false;
			jQuery.fn.uniShow.autoslide(_cont, _slides, opt);
		}});
	}
};

//autorotation
jQuery.fn.uniShow.autoslide = function(_this, els, opt){
	if(opt.switchTime && !_this.opt.pause){
		var _delay = 0
		if(opt.autoStart && opt.autoStart!=true){
			_delay = _this.opt.autoStart;
		};
		setTimeout(function(){
			opt.timer = setTimeout(function(){
				opt.next = opt.active;
				if(opt.active!= els.length-1) opt.next++;
				else opt.next =0;
				_this.opt.animated = true;
				jQuery.fn.uniShow.activatePager(_this, opt);
				var init = jQuery.fn.uniShow.transition[opt.transition];
				if (jQuery.isFunction(init)) init(_this, els, opt);
			},_this.opt.switchTime);
		},_delay);
	};
};
})(jQuery);

jQuery.fn.uniShow.transition.slideBottom = function(_cont, _slides, opt){
	if(opt.timer) clearTimeout(opt.timer);
	var _top = opt.height;
	_slides.css({zIndex: 1});
	_slides.eq(opt.next).css({
		display:'block',
		opacity: '',
		zIndex: 3,
		left: 0,
		top: -_top
	}).addClass('active').animate({top: 0},{duration:opt.duration,complete: function(){
		opt.active = opt.next;
		opt.autoStart = 0;
		opt.animated = false;
		jQuery.fn.uniShow.autoslide(_cont, _slides, opt);
	}});
	_slides.eq(opt.active).removeClass('active').css({
		display:'block',
		opacity: '',
		zIndex: 2,
		left: 0,
		top: 0
	}).animate({top: _top},{duration:opt.duration});
};

jQuery(function(){
	jQuery('.home-slide div.slider-wrap').uniShow({
		width: 907,
		height: 368,
		scrollElParent: '> ul',
		scrollEl: '> li',
		transition: 'slideBottom',
		switchTime: 3500,
		duration : 600
	});
});
