/* Gallery */
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,
		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);
		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;
		var flag = true;

		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('marginLeft', (-_margin+_options.innerMargin-_offsetStartPosition));

		//auto rotation
		if (_options.switchTime) {
			_t = setTimeout(function(){
				nextSlides();
			},_options.switchTime)
		}

		//button next "click"
		/*if (_options.btNext) {
			_next.click(function(){
				if (!_scrollElParent.is(':animated')) {
					if (jQuery.isFunction(_options.onClick)) _options.onClick.apply(_this);
					nextSlides();
				}
				return false;
			});
		}*/

		//button prev "click"
		/*if (_options.btPrev) {
			_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('marginLeft')) + _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('marginLeft'));
			_margin += _step;
			
			_scrollElParent.animate({'marginLeft':(-_margin+_options.innerMargin)}, {duration:_options.duration, easing: _easing, complete:function(){
				if (_margin >= _widthSum*2) {
					_margin = _widthSum + (_margin - _widthSum*2);
				}
				_scrollElParent.css({'marginLeft':-_margin+_options.innerMargin});
				jQuery.fn.galleryCircle.numListActive(_numHolder, _scrollEl);

				//autoslide
				if (_options.switchTime) {
					_t = setTimeout(function(){
						nextSlides();
					},_options.switchTime)
				}
			}});
		}
		
		$(this).mouseenter(function(){
			if (_t) clearTimeout(_t);
			flag = false;
		}).mouseleave(function(){
			_t = setTimeout(function(){
				nextSlides();
			},_options.switchTime)
			flag = true;
		});

		//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('marginLeft'));
			_margin -= _step;
			_scrollElParent.animate({'marginLeft':(-_margin+_options.innerMargin)}, {duration:_options.duration, easing: _easing, complete:function(){
				if (_margin < _widthSum) {
					_margin = _widthSum*2 - (_widthSum - _margin);
				}
				_scrollElParent.css({'marginLeft':-_margin+_options.innerMargin});
				jQuery.fn.galleryCircle.numListActive(_numHolder, _scrollEl);

				//autoslide
				if (_options.switchTime) {
					_t = setTimeout(function(){
						nextSlides();
					},_options.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 (_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({'marginLeft':(-_margin+_options.innerMargin)}, {duration:_options.duration, easing: _easing, complete:function(){
					if (_margin >= _widthSum*2) {
						_margin = _widthSum + (_margin - _widthSum*2);
					}
					_scrollElParent.css({'marginLeft':-_margin+_options.innerMargin});
					_aList.removeClass('active').eq(_index).addClass('active');

					//autoslide
					if(flag){
						if (_options.switchTime) {
							_t = setTimeout(function(){
								nextSlides();
							},_options.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 initContentChange(){
	var _btn = $('div.scroll').find('ul').find('a');
	var _list = $('ul.imagelist');
	_btn.click(function(){
		_list.find('li').hide();
		var _href = $(this).attr('href');
		_btn.parents('li').removeClass('active-item');
		$(this).parents('li').addClass('active-item');
		_list.find('li.'+_href).show();
		return false;
	});
}
function ieHover(h_list){
	if ($.browser.msie && $.browser.version < 7){
		$(h_list).live('mouseover', function(){
			$(this).addClass('hover');
		}).live('mouseout', function(){
			$(this).removeClass('hover');
		});
	}
}

$(document).ready(function(){
	$('div.gallery').galleryCircle({
		holderList: 'div.gallery-holder',
		scrollElParent: 'ul',
		scrollEl: 'li',
		easing: 'linear',
		switchTime: 3000,
		duration : 300,
		numCreate : true,
		numHolder : '.switcher'
	});
	
	$('#name').focus(function(){
		$('.register-form .btn').css('background-position','0px -33px');
	});
	
	$('#name').blur(function(){
		var name = $('#name').val();
		if(name == "" || name == "Your Name*"){
			$('.register-form .btn').css('background-position','0px 0px');
		}
	});
	
	$('#company').focus(function(){
		$('.register-form .btn').css('background-position','0px -33px');
	});
	
	$('#company').blur(function(){
		var company = $('#company').val();
		if(company == "" || company == "Company Name*"){
			$('.register-form .btn').css('background-position','0px 0px');
		}
	});
	
	$('#email').focus(function(){
		$('.register-form .btn').css('background-position','0px -33px');
	});
	
	$('#email').blur(function(){
		var email = $('#email').val();
		if(email == "" || email == "Your Email ID*"){
			$('.register-form .btn').css('background-position','0px 0px');
		}
	});
	
	$('#contact').focus(function(){
		$('.register-form .btn').css('background-position','0px -33px');
	});
	
	$('#contact').blur(function(){
		var contact = $('#contact').val();
		if(contact == "" || contact == "Your Contact Number*"){
			$('.register-form .btn').css('background-position','0px 0px');
		}
	});
	
	$('#contact-details').toggle(function(){
		$('.contact-details').fadeIn('slow');
		$('#contact-details span').html('&#9650;');
		$(this).addClass('open');
	},
	function(){
		$('.contact-details').fadeOut('slow');
		$(this).removeClass('open');
	});

	$('div.logo-bar').gallery({
		duration: 700,
		autoSlide: 5000,
		pause: 'a.pause',
		effect: 'fade',
		fadeEl: 'ul.gallery > li'
	});

	$(".item-logo a").click(function(){
		var url = $(this).attr("href");
		window.open(url);
	});

	$('#dwldsolar a').click(function(){
		$('#dwldsolar').hide();
	});
	/*$('.file').click(function(){
		var test = false;
		var linkto = $(this).attr('href');
		$.ajax({
			type: "POST",
			dataType: 'html',
			async: false,
			url:"../check-session.php",
			data: '',  
			success: function(msg){
				msg = msg*1;
				if(msg == 0)
				{
					$('#dwldsolar').show();
					$('#filename').val(linkto);
					test= false;
				}else{
					test= true;
				}
			}
		});
		return test;
	});*/
	
	$('.agenda tr').hover(function(){
		$('.agenda tr').removeClass('hoverbg');
		$(this).addClass('hoverbg');						   
	});

$('.btn-register').hover(function(){
  $('.pptnav').show();
 });
 
 $('.btn-register').mouseleave(function(){
  $('.pptnav').hide();
 });

});


/* Gallery */
jQuery.fn.gallery = function(_options){
	// defaults options	
	var _options = jQuery.extend({
		duration: 700,
		autoSlide: false,
		slideElement: 1,
		effect: false,
		fadeEl: 'ul',
		switcher: 'ul > li',
		disableBtn: false,
		next: 'a.link-next, a.btn-next, a.next',
		prev: 'a.link-prev, a.btn-prev, a.prev',
		circle: true,
		direction: false,
		pause: false,
		play: 'play'
	},_options);

	return this.each(function(){
		var _hold = $(this);
		if (!_options.effect) var _speed = _options.duration;
		else var _speed = $.browser.msie ? 0 : _options.duration;
		var _timer = _options.autoSlide;
		var _timeHold = _timer;
		var _sliderEl = _options.slideElement;
		var _wrap = _hold.find(_options.fadeEl);
		var _el = _hold.find(_options.switcher);
		var _next = _hold.find(_options.next);
		var _prev = _hold.find(_options.prev);
		var _paused = _hold.find(_options.pause);
		var _count = _el.index(_el.filter(':last'));
		var _w = _el.outerWidth(true);
		var _h = _el.outerHeight(true);
		if (!_options.direction) {
			var _wrapHolderW = Math.ceil(_wrap.parent().width() / _w);
			if (((_wrapHolderW - 1) * _w + _w / 2) > _wrap.parent().width()) _wrapHolderW--;
		}
		else{
			var _wrapHolderW = Math.ceil(_wrap.parent().height()/_h);
			if (((_wrapHolderW-1)*_h + _h/2) > _wrap.parent().height()) _wrapHolderW--;
		}
		if (_timer) var _t;
		var _active = _el.index(_el.filter('.active:eq(0)'));
		if (_active < 0) _active = 0;
		var _last = _active;
		if (!_options.effect) var rew = _count - _wrapHolderW + 1;
		else var rew = _count;
		
		if (!_options.effect) {
			if (!_options.direction) _wrap.css({marginLeft: -(_w * _active)})
			else _wrap.css({marginTop: -(_h * _active)})
		}
		else {
			_wrap.css({
				opacity: 0
			}).removeClass('active').eq(_active).addClass('active').css({
				opacity: 1
			}).css('opacity', 'auto');
			_el.removeClass('active').eq(_active).addClass('active');
		}
		if (_options.disableBtn) {
			if (_count < _wrapHolderW) _next.addClass(_options.disableBtn);
			_prev.addClass(_options.disableBtn);
		}
		
		function fadeElement(){
			_wrap.eq(_last).animate({opacity:0}, {queue:false, duration: _speed});
			_wrap.removeClass('active').eq(_active).addClass('active').animate({
				opacity:1
			}, {queue:false, duration: _speed, complete: function(){
				$(this).css('opacity','auto');
			}});
			_el.removeClass('active').eq(_active).addClass('active');
			_last = _active;
		}
		function scrollEl(){
			if (!_options.direction) _wrap.animate({marginLeft: -(_w * _active)}, {queue:false, duration: _speed})
			else _wrap.animate({marginTop: -(_h * _active)}, {queue:false, duration: _speed})
		}
		function toPrepare(){
			if ((_active == rew) && _options.circle) _active = -_sliderEl;
			for (var i = 0; i < _sliderEl; i++){
				_active++;
				if (_active > rew) {
					_active--;
					if (_options.disableBtn &&(_count > _wrapHolderW)) _next.addClass(_options.disableBtn);
				}
			};
			if (_active == rew) if (_options.disableBtn &&(_count > _wrapHolderW)) _next.addClass(_options.disableBtn);
			if (!_options.effect) scrollEl();
			else fadeElement();
		}
		function runTimer(){
			_t = setInterval(function(){
				toPrepare();
			}, _timer);
		}
		_next.click(function(){
			if(_t) clearTimeout(_t);
			if (_options.disableBtn &&(_count > _wrapHolderW)) _prev.removeClass(_options.disableBtn);
			toPrepare();
			if (_timer) runTimer();
			return false;
		});
		_prev.click(function(){
			if(_t) clearTimeout(_t);
			if (_options.disableBtn &&(_count > _wrapHolderW)) _next.removeClass(_options.disableBtn);
			if ((_active == 0) && _options.circle) _active = rew + _sliderEl;
			for (var i = 0; i < _sliderEl; i++){
				_active--;
				if (_active < 0) {
					_active++;
					if (_options.disableBtn &&(_count > _wrapHolderW)) _prev.addClass(_options.disableBtn);
				}
			};
			if (_active == 0) if (_options.disableBtn &&(_count > _wrapHolderW)) _prev.addClass(_options.disableBtn);
			if (!_options.effect) scrollEl();
			else fadeElement();
			if (_timer) runTimer();
			return false;
		});
		if (_options.effect) _el.click(function(){
			_active = _el.index($(this));
			if(_t) clearTimeout(_t);
			fadeElement();
			if (_timer) runTimer();
			return false;
		});
		if (_timer) runTimer();
		if (_options.pause) _paused.click(function(){
			if ($(this).hasClass(_options.play)){
				$(this).removeClass(_options.play);
				_timer = _timeHold;
				runTimer();
			}
			else{
				$(this).addClass(_options.play);
				_timer = false;
				if(_t) clearTimeout(_t);
			}
			return false;
		});
	});
}


// JavaScript Document
