$(document).ready(function(){
	$('#nav li a').not('#nav ul li a').mouseenter(function(){
		$(this).parent().parent().find('.active').not('#nav ul li').removeClass('active');
		$(this).parent().addClass('active');
	});
	$('.product-photo .photo-list a').click(function(){
		$(this).parents('.product-photo').find('.photo img').attr('src',$(this).attr('href'));
		$(this).parents('.product-photo').find('.photo a').attr('href',$(this).attr('href'));
		
		return false;
	});
	
	$('.news .post .head').click(function(){
		if ($(this).parent().is('.active')) {
			$(this).parent().find('.content').css('display','block');
			$(this).parent().removeClass('active');
			$(this).parent().find('.content').slideUp(400);
		} else {
			$(this).parent().find('.content').css('display','none');
			$(this).parent().addClass('active');
			$(this).parent().find('.content').slideDown(400);
		}
		return false;
	});
	
	/* ---------- 21.02.2011 alexpic | add comment this box */
	/*$('#sidebar .menu .opener').click(function(){
		if ($(this).parent().is('.active')) {
			$(this).parent().find('ul:first').css('display','block');
		} else {
			$(this).parent().find('ul:first').css('display','none');
		};
		$(this).parent().toggleClass('active');
		$(this).parent().find('ul:first').slideToggle(400);
		return false;
	});*/
	
	
	/* ---------- 21.02.2011 alexpic */
	/*$('#sidebar .menu .opener').click(function(){
		if (!$(this).parent().is('.active')) {
			$('#sidebar .menu li.active li.active').removeClass('active');
			$('#sidebar .menu li.active ul').slideUp(375, function (){$('#sidebar .menu li.active').removeClass('active');});
			
			$(this).parent().find('ul:first').slideDown(400, function (){$(this).parent().addClass('active');});
		}
		return false;
	});*/
	/*
	$('#sidebar .menu li li a').click(function(){
		if (!$(this).parent().is('.active')) {
			$('#sidebar .menu li.active li.active').removeClass('active');
			$(this).parent().addClass('active');
		}
		return false;
	});*/
	/* ---------- 21.02.2011 alexpic */
	
	/*$('.slideshow-control a').mouseenter(function(){
		$(this).find('img').eq(0).hide();
		$(this).find('img').eq(1).show();
		$(this).find('.ico-norm').hide();
		$(this).find('.ico-hover').show();
		$(this).find('.ico-norm').css('display','none');
		$(this).find('.ico-hover').css('display','inline');
		var source = $(this).find('.ico img').attr('src');
		source = source.replace(".png","_hover.png");
		$(this).find('.ico img').attr('src',source);
	});
	$('.slideshow-control a').mouseleave(function(){
		$(this).find('img').eq(1).hide();
		$(this).find('img').eq(0).show();
		$(this).find('.ico-norm').css('display','inline');
		$(this).find('.ico-hover').css('display','none');
		var source = $(this).find('.ico img').attr('src');
		source = source.replace("_hover.png",".png");
		$(this).find('.ico img').attr('src',source);
	});
	*/
});

/* ---------- 21.02.2011 alexpic */
/*function goTo(url, innerContentClass) {
	$('#content').load(url);
	if (innerContentClass) {
		$('#main').addClass('main-inner');
	} else {
		$('#main').removeClass('main-inner');
	}
	return;
}*/
/* ---------- 21.02.2011 alexpic */

// page init
$(function(){
	initSlideShow();
});
function initSlideShow() {
	$('div.slideshow-holder').fadeGallery({
		slideElements:'.slideshow > li',
		pauseOnHover:true,
		autoRotation:true,
		switchTime:3000,
		duration:650,
		event:'click'
	})
}
// slideshow plugin
jQuery.fn.fadeGallery = function(_options){
	var _options = jQuery.extend({
		slideElements:'div.slideset > div',
		pagerLinks:'.slideshow-control a',
		btnNext:'a.link-next',
		btnPrev:'a.link-prev',
		btnPlayPause:'a.play-pause',
		pausedClass:'paused',
		playClass:'playing',
		activeClass:'active',
		pauseOnHover:true,
		autoRotation:false,
		autoHeight:false,
		switchTime:3000,
		duration:650,
		event:'click'
	},_options);

	return this.each(function(){
		// gallery options
		var _this = jQuery(this);
		var _slides = jQuery(_options.slideElements, _this);
		var _pagerLinks = jQuery(_options.pagerLinks, _this);
		var _btnPrev = jQuery(_options.btnPrev, _this);
		var _btnNext = jQuery(_options.btnNext, _this);
		var _btnPlayPause = jQuery(_options.btnPlayPause, _this);
		var _pauseOnHover = _options.pauseOnHover;
		var _autoRotation = _options.autoRotation;
		var _activeClass = _options.activeClass;
		var _pausedClass = _options.pausedClass;
		var _playClass = _options.playClass;
		var _autoHeight = _options.autoHeight;
		var _duration = _options.duration;
		var _switchTime = _options.switchTime;
		var _controlEvent = _options.event;

		// gallery init
		var _hover = false;
		var _prevIndex = 0;
		var _currentIndex = 0;
		var _slideCount = _slides.length;
		var _timer;
		if(!_slideCount) return;
		_slides.hide().eq(_currentIndex).show();
		if(_autoRotation) _this.removeClass(_pausedClass).addClass(_playClass);
		else _this.removeClass(_playClass).addClass(_pausedClass);

		// gallery control
		if(_btnPrev.length) {
			_btnPrev.bind(_controlEvent,function(){
				prevSlide();
				return false;
			});
		}
		if(_btnNext.length) {
			_btnNext.bind(_controlEvent,function(){
				nextSlide();
				return false;
			});
		}
		if(_pagerLinks.length) {
			_pagerLinks.each(function(_ind){
				jQuery(this).bind(_controlEvent,function(){
					if(_currentIndex != _ind) {
						_prevIndex = _currentIndex;
						_currentIndex = _ind;
						switchSlide();
					}
					return false;
				});
			});
		}

		// play pause section
		if(_btnPlayPause.length) {
			_btnPlayPause.bind(_controlEvent,function(){
				if(_this.hasClass(_pausedClass)) {
					_this.removeClass(_pausedClass).addClass(_playClass);
					_autoRotation = true;
					autoSlide();
				} else {
					if(_timer) clearTimeout(_timer);
					_this.removeClass(_playClass).addClass(_pausedClass);
				}
				return false;
			});
		}

		// gallery animation
		function prevSlide() {
			_prevIndex = _currentIndex;
			if(_currentIndex > 0) _currentIndex--;
			else _currentIndex = _slideCount-1;
			switchSlide();
		}
		function nextSlide() {
			_prevIndex = _currentIndex;
			if(_currentIndex < _slideCount-1) _currentIndex++;
			else _currentIndex = 0;
			switchSlide();
		}
		function refreshStatus() {
			if(_pagerLinks.length) _pagerLinks.removeClass(_activeClass).eq(_currentIndex).addClass(_activeClass);
			_slides.eq(_prevIndex).removeClass(_activeClass);
			_slides.eq(_currentIndex).addClass(_activeClass);
		}
		function switchSlide() {
			_slides.eq(_prevIndex).fadeOut(_duration);
			_slides.eq(_currentIndex).fadeIn(_duration);
			refreshStatus();
			autoSlide();
		}

		// autoslide function
		function autoSlide() {
			if(!_autoRotation || _hover) return;
			if(_timer) clearTimeout(_timer);
			_timer = setTimeout(nextSlide,_switchTime+_duration);
		}
		if(_pauseOnHover) {
			_this.hover(function(){
				_hover = true;
				if(_timer) clearTimeout(_timer);
			},function(){
				_hover = false;
				autoSlide();
			});
		}
		refreshStatus();
		autoSlide();
	});
}
function hideFormText() {
	var _inputs = document.getElementsByTagName('input');
	var _txt = document.getElementsByTagName('textarea');
	var _value = [];
	
	if (_inputs) {
		for(var i=0; i<_inputs.length; i++) {
			if (_inputs[i].type == 'text' || _inputs[i].type == 'password') {
				
				_inputs[i].index = i;
				_value[i] = _inputs[i].value;
				
				_inputs[i].onfocus = function(){
					if (this.value == _value[this.index])
						this.value = '';
				}
				_inputs[i].onblur = function(){
					if (this.value == '')
						this.value = _value[this.index];
				}
			}
		}
	}
	if (_txt) {
		for(var i=0; i<_txt.length; i++) {
			_txt[i].index = i;
			_value['txt'+i] = _txt[i].value;
			
			_txt[i].onfocus = function(){
				if (this.value == _value['txt'+this.index])
					this.value = '';
			}
			_txt[i].onblur = function(){
				if (this.value == '')
					this.value = _value['txt'+this.index];
			}
		}
	}
}
if (window.addEventListener)
	window.addEventListener("load", hideFormText, false);
else if (window.attachEvent)
	window.attachEvent("onload", hideFormText);
