$(document).ready(function(){
	ieHover('ul.subnav > li, #menu > li, .user-profile > div, #user-menu > div, #user-menu2 > div');
	initSlide();
	initClose();
	initGall();
	initAccordion();
	clearInputs();
});
/* clearInputs function */
function clearInputs() {
	//$('input:text, input:password').each(function(){
	$('input.clear').each(function() {
		this.val = this.value;
		this.onfocus = function() {
			if(this.value == this.val) {
				this.value = '';
				$(this).removeClass('clear');
			}
		}
		this.onblur = function() {
			if(this.value == '') {
				this.value = this.val;
				$(this).addClass('clear');
			}
		}
	});
}
/* IE6 hover function */
function ieHover(h_list) {
	if ($.browser.msie && $.browser.version < 7) {
		$(h_list).hover(function() {
			$(this).addClass('hover');
			if(this.getElementsByTagName("ul")[0] && typeof(hideSelectBoxes) == 'function'){
				hideSelectBoxes(this.getElementsByTagName("ul")[0]);
			}
		}, function() {
			$(this).removeClass('hover');
			if(this.getElementsByTagName("ul")[0] && typeof(hideSelectBoxes) == 'function'){
				showSelectBoxes(this.getElementsByTagName("ul")[0]);
			}
		});
	}
	if ($.browser.msie && $.browser.version < 7) {
		$(h_list).hover(function() {
			$(this).addClass('hover');
			if(this.getElementsByTagName("div")[0] && typeof(hideSelectBoxes) == 'function'){
				hideSelectBoxes(this.getElementsByTagName("div")[0]);
			}
		}, function() {
			$(this).removeClass('hover');
			if(this.getElementsByTagName("div")[0] && typeof(hideSelectBoxes) == 'function'){
				showSelectBoxes(this.getElementsByTagName("ul")[0]);
			}
		});
	}
}
/* slide function */
function initSlide(){
	if($('div#block').length){
		//$('div#block').hide();
		$('a.toggle').click(function(){
			$('div#block').slideToggle();
		});
	}
}
/* close block function */
function initClose(){
	$('a.close').click(function(){
		$(this).parent().parent().parent().toggleClass('none-box');
		return false;
	});
	$('a.close2').click(function(){
		$(this).parent().toggleClass('none-box');
		return false;
	});
}
/* slide gallery function */
function initGall(){
	$('.gallery').each(function(){
		var btn_prev = $(this).children('.link-prev').addClass('disabled');
		var btn_next = $(this).children('.link-next').addClass('disabled');
		var list_h = $(this).find('div > ul');
		var _list = list_h.children();
		var _step = list_h.parent().width();
		var _w = 0;
		var _m = 0;
		_list.each(function(){
			_w += this.offsetWidth;
		});
		if(_w > _step){
			btn_next.removeClass('disabled');
			btn_prev.click(function(){
				if(!$(this).hasClass('disabled')) changeEl(false);
				return false;
			});
			btn_next.click(function(){
				if(!$(this).hasClass('disabled')) changeEl(true);
				return false;
			});
		}
		function changeEl(_f){
			if(_f){
				if(_m + _step < _w - _step) _m += _step;
				else _m = _w - _step;
			}
			else{
				if(_m - _step > 0) _m -= _step;
				else _m = 0;
			}
			if(_m == _w - _step) btn_next.addClass('disabled');
			else btn_next.removeClass('disabled');
			if(_m == 0) btn_prev.addClass('disabled');
			else btn_prev.removeClass('disabled');
			list_h.animate({marginLeft: -_m}, 1000, function(){
				_flag = true;
			});
		}
	});
}
/* accordion function */
function initAccordion(){
	var _hold = $('.members-main .accordion');
	if(_hold.length){
		var _list = _hold.children();
		var _a = _list.index(_list.filter('.active'));
		if(_a == -1) _a = 0;
		_list.removeClass('active').eq(_a).addClass('active');
		_list.each(function(_i){
			this._btn = $(this).find('a.opener');
			this._w = this._btn.parent().outerWidth();
			if(_i == _a){
				this._btn.find('img').css('opacity', 1);
				$(this).width(361);
			}
			else{
				this._btn.find('img').css('opacity', 0.7);
				$(this).width(this._w);
			}
			this._btn.click(function(){
				changeEl(_i);
				return false;
			});
		});
		function changeEl(_ind){
			if(_ind != _a){
				_list.eq(_a).removeClass('active');
				_list.eq(_ind).addClass('active');
				_list.eq(_a).animate({width: _list.get(_a)._w}, {queue:false, duration:500});
				_list.eq(_ind).animate({width: 361}, {queue:false, duration:500});
				_list.get(_a)._btn.find('img').animate({opacity: 0.7}, {queue:false, duration:500});
				_list.get(_ind)._btn.find('img').animate({opacity: 1}, {queue:false, duration:500});
				_a = _ind;
			}
		}
	}
}
/* safari detect */
function initPage(){
	if (navigator.appVersion.indexOf("Safari") != -1){
		if (!window.getComputedStyle) document.body.className += " safari";
			else document.body.className += " safari3";
		}
	}
if (window.addEventListener) window.addEventListener("load", initPage, false);
else if (window.attachEvent && !window.opera) window.attachEvent("onload", initPage);

/*link hover*/
function initLink(){
	_link = document.getElementById('user-menu');
	_link2 = document.getElementById('user-menu2');
	if(_link){
		_link.onmouseover = function(){
			this.style.zIndex= 40;
		}
		_link.onmouseout = function(){
			this.style.zIndex= 2;
		}
	}
	if(_link2){
		_link2.onmouseover = function(){
			this.style.zIndex= 40;
		}
		_link2.onmouseout = function(){
			this.style.zIndex= 2;
		}
	}
}
if (window.addEventListener) window.addEventListener("load", initLink, false);
else if (window.attachEvent && !window.opera) window.attachEvent("onload", initLink);

$(function() {
    setInterval(KeepSessionAlive, 60000);
});

function KeepSessionAlive() {           
    $.post("/_layouts/enetahandlers/SessionKeepUpHandler.ashx", null, function() {
        return true;
    });   
}  
/*
CSS Browser Selector v0.3.2
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',h=document.getElementsByTagName('html')[0],b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3')?g+' ff3':is('gecko/')?g:/opera(\s|\/)(\d+)/.test(ua)?'opera opera'+RegExp.$2:is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);