// top navigation dropdown for IE6
function initPageIE()
{
	var nav = document.getElementById("nav");
	if (nav)
	{
		var nodes = nav.getElementsByTagName("li");
		for (var i = 0; i < nodes.length; i++)
		{
			nodes[i].onmouseover = function () 
			{
				if (this.className.indexOf("hover") == -1)
				{
					this.className += " hover";
				}
			}
			nodes[i].onmouseout = function ()
			{
				this.className = this.className.replace(" hover", "");
			}
		}
	}
}
if (window.attachEvent && !window.opera)
	window.attachEvent("onload", initPageIE);

// tabs
function initTabs()
{
	var sets = document.getElementsByTagName("ul");
	for (var i = 0; i < sets.length; i++)
	{
		if (sets[i].className.indexOf("tabset") != -1)
		{
			var tabs = [];
			var links = sets[i].getElementsByTagName("a");
			for (var j = 0; j < links.length; j++)
			{
				if (links[j].className.indexOf("tab") != -1)
				{
					tabs.push(links[j]);
					links[j].tabs = tabs;
					var c = document.getElementById(links[j].href.substr(links[j].href.indexOf("#") + 1));

					//reset all tabs on start
					if (c) if (links[j].className.indexOf("active") != -1) c.style.display = "block";
					else c.style.display = "none";

					links[j].onclick = function()
					{
						var c = document.getElementById(this.href.substr(this.href.indexOf("#") + 1));
						if (c)
						{
							//reset all tabs before change
							for (var i = 0; i < this.tabs.length; i++)
							{
								document.getElementById(this.tabs[i].href.substr(this.tabs[i].href.indexOf("#") + 1)).style.display = "none";
								this.tabs[i].className = this.tabs[i].className.replace("active", "");
							}
							this.className += " active";
							c.style.display = "block";
							return false;
						}
					}
				}
			}
		}
	}
}

// gallery scroll
function initGallery(){
	// gallery holder
	var _holder = $('div.menu-bar');
	
	// images
	var _imgHolder = $('div.thumbnails-holder');
	var _imgList = $('.thumbnails ul');
	var _imgDiv = $('.thumbnails');
	var _imgItem = _imgList.find('li');
	var _itemWidth = _imgItem.width();
	var _itemCount = _imgItem.length;
	var _holderWidth = _itemWidth*_itemCount;
	var _numbHold = $('.numbers');
	var _currMargin = 0;
	var _currNumb = 0;
	
	// buttons
	var _leftBtn = $('.buttons-box .links a.prev');
	var _rightBtn = $('.buttons-box .links a.next');
	
        _leftBtn.unbind('click');
        _rightBtn.unbind('click');
        _numbHold.find('a').unbind('click');
	// options
	var _step = 10;
	var _duration = 1000;

        if (_itemCount <= 10){
            _imgDiv.css('marginLeft',0);
            $("div.menu-bar div.buttons-box").hide();
        }else{
            $("div.menu-bar div.buttons-box").show();
        }
	
	if(_itemCount>_step) {
		
		var _numb = Math.round(_itemCount/_step);
		var _numbHtml = '<ul>';
		for(i=0;i<_numb;i++){
			_numbHtml += '<li><a href="#">' + (i+1) +'</a></li>';
		}
		_numbHtml += '</ul>';
		_numbHold.html(_numbHtml);
		_numbHold.find('li:eq(' + _currNumb + ')').find('a').addClass('active');
	
		// clone current gallery list object to make gallery circle sliding
		var _imgListBf = _imgList.clone(true).insertBefore(_imgList).addClass('before');
		var _imgListAf = _imgList.clone(true).insertAfter(_imgList).addClass('after');
		
		// set the initial position
		_currMargin = -1*_holderWidth;
		_imgDiv.css('marginLeft',_currMargin);
		
		// click 'left' button
		_leftBtn.click(function(){
			if(_currMargin>-1*_holderWidth){
				_currMargin = -2*_holderWidth;
				_imgDiv.css('marginLeft',_currMargin);
			}
			if(_currNumb==0)_currNumb = _numb;
			_currMargin += _itemWidth*_step;
			_numbHold.find('a').removeClass('active');
			_currNumb--;
			_numbHold.find('li:eq(' + _currNumb + ')').find('a').addClass('active');
			_imgDiv.animate({
				'marginLeft': _currMargin
			},_duration);
		});
		
		// click 'right' button
		_rightBtn.click(function(){
			if(_currMargin<-1*_holderWidth){
				_currMargin = 0;
				_imgDiv.css('marginLeft',_currMargin);
			}
			if(_currNumb==_numb-1)_currNumb = -1;
			_currMargin -= _itemWidth*_step;
			_numbHold.find('a').removeClass('active');
			_currNumb++;
			_numbHold.find('li:eq(' + _currNumb + ')').find('a').addClass('active');
			_imgDiv.animate({
				'marginLeft': _currMargin
			},_duration);
			return false;
		});
		
		// click 'numbers' button
		_numbHold.find('a').click(function(){
			var _th = _numbHold.find('a.active');
			var _oldIndex = _numbHold.find('a').index(_th);
			var _newIndex = _numbHold.find('a').index(this);
			_numbHold.find('a').removeClass('active');
			_numbHold.find('li:eq(' + _newIndex + ')').find('a').addClass('active');
			var _dir = 0; // left
			if (_oldIndex<_newIndex) _dir = 1; // right
			var _st = 0;
			if (_dir==0) _st = _oldIndex - _newIndex;
			if (_dir==1) _st = _newIndex - _oldIndex;
			animation(_dir,_st);
			return false;
		});

		// slide animation
		function animation(_direction,_steps) {
			if (_steps!=0) {
				if(_direction==0) {
					_currNumb = _currNumb - _steps
					_currMargin += _itemWidth*_step*_steps;
				} else {
					_currNumb = _currNumb + _steps
					_currMargin -= _itemWidth*_step*_steps;
				}
				_imgDiv.animate({
					'marginLeft': _currMargin
				},_duration);
			}
		}
	}
	function openSlide(){
		$('#side-area').find('div.members-list').css('overflow','hidden');
		$('span#opener a').click(function(){
			if(!$(this).parent().hasClass('hidden')) {
				$(this).parents('#side-area').find('div.members-list').slideUp();
				$(this).parent().html('Online Now <a href="#">Expand</a> +').addClass('hidden');
			}else{
				$(this).parents('#side-area').find('div.members-list').slideDown();
				$(this).parent().html('Members Online Now <a href="#">Collapse</a> -').removeClass('hidden');
			}
			openSlide();
			return false;
		});
	}
	openSlide();
}

function initGalleryScroll1(){
	// gallery holder
	var _holder = $('div.trophies-area');
	
	// images
	var _imgHolder = $('div.trophies-holder');
	var _imgList = $('.trophies-div ul');
	var _imgDiv = $('.trophies-div');
	var _imgItem = _imgList.find('li');
	//var _itemWidth = _imgItem.width();
	var _itemCount = _imgItem.length;
	var _holderWidth = 368;
	var _numbHold = $('div.trophies-area .numbers');
	var _currMargin = 0;
	var _currNumb = 0;
	
	// buttons
	var _leftBtn = $('div.trophies-area .buttons-box .links a.prev');
	var _rightBtn = $('div.trophies-area .buttons-box .links a.next');
	
	// options
	var _step = 10;
	var _duration = 1000;
	
	if(_itemCount>_step) {
		
		var _numb = Math.round(_itemCount/_step);
		var _numbHtml = '<ul>';
		for(i=0;i<_numb;i++){
			_numbHtml += '<li><a href="#">' + (i+1) +'</a></li>';
		}
		_numbHtml += '</ul>';
		_numbHold.html(_numbHtml);
		_numbHold.find('li:eq(' + _currNumb + ')').find('a').addClass('active');
	
		// clone current gallery list object to make gallery circle sliding
		var _imgListBf = _imgList.clone(true).insertBefore(_imgList).addClass('before');
		var _imgListAf = _imgList.clone(true).insertAfter(_imgList).addClass('after');
		
		// set the initial position
		_currMargin = -1*_holderWidth;
		_imgDiv.css('marginLeft',_currMargin);
		
		// click 'left' button
		_leftBtn.click(function(){
			if(_imgDiv.is(':not(:animated)')){
				if(_currMargin>-1*_holderWidth){
					_currMargin = -2*_holderWidth;
					_imgDiv.css('marginLeft',_currMargin);
				}
				if(_currNumb==0)_currNumb = _numb;
				_currMargin += _holderWidth;
				_numbHold.find('a').removeClass('active');
				_currNumb--;
				_numbHold.find('li:eq(' + _currNumb + ')').find('a').addClass('active');
				_imgDiv.animate({
					'marginLeft': _currMargin
				},_duration);
			}
			return false;
		});
		
		// click 'right' button
		_rightBtn.click(function(){
			if(_imgDiv.is(':not(:animated)')){
				if(_currMargin<-1*_holderWidth){
					_currMargin = 0;
					_imgDiv.css('marginLeft',_currMargin);
				}
				if(_currNumb==_numb-1)_currNumb = -1;
				_currMargin -= _holderWidth;
				_numbHold.find('a').removeClass('active');
				_currNumb++;
				_numbHold.find('li:eq(' + _currNumb + ')').find('a').addClass('active');
				_imgDiv.animate({
					'marginLeft': _currMargin
				},_duration);
			}
			return false;
		});
		
		// click 'numbers' button
		_numbHold.find('a').click(function(){
			if(_imgDiv.is(':not(:animated)')){
				var _th = _numbHold.find('a.active');
				var _oldIndex = _numbHold.find('a').index(_th);
				var _newIndex = _numbHold.find('a').index(this);
				_numbHold.find('a').removeClass('active');
				_numbHold.find('li:eq(' + _newIndex + ')').find('a').addClass('active');
				var _dir = 0; // left
				if (_oldIndex<_newIndex) _dir = 1; // right
				var _st = 0;
				if (_dir==0) _st = _oldIndex - _newIndex;
				if (_dir==1) _st = _newIndex - _oldIndex;
				animation(_dir,_st);
			}
			return false;
		});
		
		// slide animation
		function animation(_direction,_steps) {
			if (_steps!=0) {
				if(_direction==0) {
					_currNumb = _currNumb - _steps
					_currMargin +=_holderWidth;
				} else {
					_currNumb = _currNumb + _steps
					_currMargin -= _holderWidth;
				}
				_imgDiv.animate({
					'marginLeft': _currMargin
				},_duration);
			}
		}
	}
	function openSlide(){
		$('#side-area').find('div.members-list').css('overflow','hidden');
		$('span#opener a').click(function(){
			if(!$(this).parent().hasClass('hidden')) {
				$(this).parents('#side-area').find('div.members-list').slideUp();
				$(this).parent().html('Online Now <a href="#">Expand</a> +').addClass('hidden');
			}else{
				$(this).parents('#side-area').find('div.members-list').slideDown();
				$(this).parent().html('Members Online Now <a href="#">Collapse</a> -').removeClass('hidden');
			}
			openSlide();
			return false;
		});
	}
	openSlide();
}
function initGalleryScroll2(){
	// gallery holder
	var _holder = $('div.photo-area');
	
	// images
	var _imgHolder = $('div.photo-holder');
	var _imgList = $('.photo-div ul');
	var _imgDiv = $('.photo-div');
	var _imgItem = _imgList.find('li');
	//var _itemWidth = _imgItem.width();
	var _itemCount = _imgItem.length;
	var _holderWidth = 360;
	var _numbHold = $('div.photo-area .numbers-g');
	var _currMargin = 0;
	var _currNumb = 0;
	
	// buttons
	var _leftBtn = $('div.photo-area a.prev');
	var _rightBtn = $('div.photo-area a.next');
	
	// options
	var _step = 3;
	var _duration = 1000;

	if(_itemCount>_step) {
		var _numb = Math.round(_itemCount/_step);
		var _numbHtml = '<ul>';
		for(i=0;i<_numb;i++){
			_numbHtml += '<li><a href="#">' + (i+1) +'</a></li>';
		}
		_numbHtml += '</ul>';
		_numbHold.html(_numbHtml);
		_numbHold.find('li:eq(' + _currNumb + ')').find('a').addClass('active');
	
		// clone current gallery list object to make gallery circle sliding
		var _imgListBf = _imgList.clone(true).insertBefore(_imgList).addClass('before');
		var _imgListAf = _imgList.clone(true).insertAfter(_imgList).addClass('after');
		
		// set the initial position
		_currMargin = -1*_holderWidth;
		_imgDiv.css('marginLeft',_currMargin);
		
		// click 'left' button
		_leftBtn.click(function(){
			if(_imgDiv.is(':not(:animated)')){
				if(_currMargin>-1*_holderWidth){
					_currMargin = -2*_holderWidth;
					_imgDiv.css('marginLeft',_currMargin);
				}
				if(_currNumb==0)_currNumb = _numb;
				_currMargin += _holderWidth;
				_numbHold.find('a').removeClass('active');
				_currNumb--;
				_numbHold.find('li:eq(' + _currNumb + ')').find('a').addClass('active');
				_imgDiv.animate({
					'marginLeft': _currMargin
				},_duration);
			}
			return false;
		});
		
		// click 'right' button
		_rightBtn.click(function(){
			if(_imgDiv.is(':not(:animated)')){
				if(_currMargin<-1*_holderWidth){
					_currMargin = 0;
					_imgDiv.css('marginLeft',_currMargin);
				}
				if(_currNumb==_numb-1)_currNumb = -1;
				_currMargin -= _holderWidth;
				_numbHold.find('a').removeClass('active');
				_currNumb++;
				_numbHold.find('li:eq(' + _currNumb + ')').find('a').addClass('active');
				_imgDiv.animate({
					'marginLeft': _currMargin
				},_duration);
			}
			return false;
		});
		
		// click 'numbers' button
		_numbHold.find('a').click(function(){
			if(_imgDiv.is(':not(:animated)')){
				var _th = _numbHold.find('a.active');
				var _oldIndex = _numbHold.find('a').index(_th);
				var _newIndex = _numbHold.find('a').index(this);
				_numbHold.find('a').removeClass('active');
				_numbHold.find('li:eq(' + _newIndex + ')').find('a').addClass('active');
				var _dir = 0; // left
				if (_oldIndex<_newIndex) _dir = 1; // right
				var _st = 0;
				if (_dir==0) _st = _oldIndex - _newIndex;
				if (_dir==1) _st = _newIndex - _oldIndex;
				animation(_dir,_st);
			}
			return false;
		});
		
		// slide animation
		function animation(_direction,_steps) {
			if (_steps!=0) {
				if(_direction==0) {
					_currNumb = _currNumb - _steps
					_currMargin += _holderWidth;
				} else {
					_currNumb = _currNumb + _steps
					_currMargin -= _holderWidth;
				}
				_imgDiv.animate({
					'marginLeft': _currMargin
				},_duration);
			}
		}
	}
	function openSlide(){
		$('#side-area').find('div.members-list').css('overflow','hidden');
		$('span#opener a').click(function(){
			if(!$(this).parent().hasClass('hidden')) {
				$(this).parents('#side-area').find('div.members-list').slideUp();
				$(this).parent().html('Online Now <a href="#">Expand</a> +').addClass('hidden');
			}else{
				$(this).parents('#side-area').find('div.members-list').slideDown();
				$(this).parent().html('Members Online Now <a href="#">Collapse</a> -').removeClass('hidden');
			}
			openSlide();
			return false;
		});
	}
	openSlide();
}
function initPage(){
	initTabs();
	initGallery(); // homepage gallery
	initGalleryScroll1(); // innerpages gallery 1
	initGalleryScroll2(); // innerpages gallery 2
}
//if (window.addEventListener) window.addEventListener("load", initPage, false);
//else if (window.attachEvent) window.attachEvent("onload", initPage);