function openTodayDoor()
{
  // open the door
  var todayprize = document.getElementById('todayprize');
  var number = todayprize.innerHTML;

  // remove the number
  todayprize.innerHTML = "&nbsp;"

  // set the classname
  todayprize.className = "snowflake";

  // stop clicking again
  todayprize.onclick = "";

  // display the promotion
  document.getElementById('light').style.display='block';
}

function openCheeky()
{
  // display the promotion
  document.getElementById('cheeky').style.display='block';
}

var bannerid = 1;

function changeBanner(id)
{
	switch(id)
	{
		case 1:
			document.getElementById('banner').style.backgroundImage = "url(../images/big-img1.jpg)";
			document.getElementById('banner').href="/virtualisation";
			document.getElementById('switch1').style.background = "url(../images/arrow-white-up.gif) no-repeat 50% 100%";
			document.getElementById('switch2').style.background = "";
			document.getElementById('switch3').style.background = "";
		break;

		case 2:
			document.getElementById('banner').style.backgroundImage = "url(../images/big-img2.jpg)";
			document.getElementById('banner').href="/managed-networks/littlefish-lab";
			document.getElementById('switch1').style.background = "";
			document.getElementById('switch2').style.background = "url(../images/arrow-white-up.gif) no-repeat 50% 100%";
			document.getElementById('switch3').style.background = "";
		break;

		case 3:
			document.getElementById('banner').style.backgroundImage = "url(../images/big-img3.jpg)";
			document.getElementById('banner').href="/virtualisation/exchange-hosting";
			document.getElementById('switch1').style.background = "";
			document.getElementById('switch2').style.background = "";
			document.getElementById('switch3').style.background = "url(../images/arrow-white-up.gif) no-repeat 50% 100%";
		break;
	}

	bannerid = id;
}

function rotateBanner()
{
	bannerid++;
	if(bannerid > 3)
	{
		bannerid = 1;
	}

	changeBanner(bannerid);

	setTimeout('rotateBanner()', 5000);
}

function initTabs()
{
	var sets = document.getElementsByTagName("ul");
	for (var i = 0; i < sets.length; i++)
	{
		if (sets[i].className.indexOf("newstabset") != -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));

					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)
						{
							for (var i = 0; i < this.tabs.length; i++)
							{
								var tab = document.getElementById(this.tabs[i].href.substr(this.tabs[i].href.indexOf("#") + 1));
								if (tab)
								{
									tab.style.display = "none";
								}
								this.tabs[i].className = this.tabs[i].className.replace("active", "");
							}
							this.className += " active";
							c.style.display = "block";
							return false;
						}
					}
				}
			}
		}
	}
}

/* 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
	},_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 _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 _count = _el.index(_el.filter(':last'));
		var _w = _el.outerWidth(true);
		var _wrapHolderW = Math.ceil(_wrap.parent().width()/_w);
		if (((_wrapHolderW-1)*_w + _w/2) > _wrap.parent().width()) _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) _wrap.css({marginLeft: -(_w * _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(){
			_wrap.animate({marginLeft: -(_w * _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();
	});
}

initChat = function() {
    $.ajax( {url: '/chat/isoff', context: document.body, success: function( result ) {
        if( result==0 ) {
        		$( '#chat' ).dialog( 'open' );

//            var d = $('.ui-dialog').position();
//            window.scrollTo(0, 0);
//            $('.ui-dialog').style('height: 0;');

        }
    }} );
}

$(document).ready(function() {

    $('.page24-readmore').click(function(){
        $('.hidden').toggle();
        return false;
    });
	
    $( '.tabs-area' ).tabs();


    $( '#chat' ).dialog( {height: 335, width: 368, resizable: false, autoOpen: false, close: function(event, ui) {
        $.ajax( {url: '/chat/switchoff', context: document.body} );
    }} );

    $('.chat-opener').bind( 'click', function(){
        window.open( 'http://messenger.providesupport.com/messenger/littlefish.html', '', 'width=500, height=550' );
    } )

		if(window.location.href == "http://newlfsite.thruhere.net/" || window.location.href == "http://www.littlefishsupport.com/")
		{
			document.getElementById('switch1').style.background = "url(../images/arrow-white-up.gif) no-repeat 50% 100%";
			setTimeout('rotateBanner()', 15000);
		}

    initTabs();
    setTimeout('initChat()',10000);
} );

closechat = function() {
    $( '#chat' ).dialog( 'close' );
    $.ajax( {url: '/chat/switchoff', context: document.body} );
}

$( '#loading' ).dialog( 'open' );

_ = function(){}

