/*
 * Initialization
 */
var onloadFuncs = new Array();

function execOnloadFuncs(){
}


jQ(document).ready(function() {
	for(var i=0;i<onloadFuncs.length;i++)
		onloadFuncs[i]();
	
	jQ(".sitenav li a").hover(
		function() {
			jQ(this).parent().find("ul.subnav").slideDown('fast').show();
			jQ(this).parent().hover(
				function() {},
				function(){  
					jQ(this).parent().find("ul.subnav").slideUp('fast');
				}
			); 
		},
		function(){}
	);
});         


function getCookie(c_name)
{
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");

		if (c_start!=-1) { 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);

			if (c_end==-1)
				c_end=document.cookie.length;
					
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
		
	return "";
}

function setCookie(c_name,value,expiredays)
{
	var pos = document.domain.indexOf('.');
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString()+";path=/;domain="+document.domain.substr(pos));
}



function hasSignedIn()
{
	var clogged_in = getCookie('logged_in');
	return (clogged_in && clogged_in > 0) ? true : false;
}


function ModalDialog()
{
	this.close = simpleModalClose;
	this.open = simpleModalOpen;
	this.show = simpleModalShow;
}

function simpleModalClose(dialog) {
	if (dialog && dialog.data) {
		dialog.data.fadeOut('fast', function () {
			dialog.container.hide('fast', function () {
				dialog.overlay.slideUp('fast', function () {
					jQ.modal.close();
				});
			});
		});
	}
}

function simpleModalOpen(dialog) {
	if (dialog && dialog.data) {
		dialog.overlay.fadeIn('fast', function () {
			dialog.container.fadeIn('fast', function () {
				dialog.data.slideDown('fast');
			});
		});
	}
}

function simpleModalShow(dialog) {
	if (dialog && dialog.data) {
		dialog.data.find('input.animate').one('click', function () {
			dialog.data.slideUp('fast', function () {
				dialog.data.slideDown('fast');
			});
		});
	}
}

function closeModal()
{
	if (jQ.modal)
		simpleModalClose(jQ.modal.impl.dialog);
}
/*
 * End Simple Modal Dialog
 */




/*
 * Slide box
 */
function Slider(delay, root_id)
{
	this.delay = delay;
	this.root_id = root_id;
	this.root_elem = null;
	this.current_index = 0;
	this.next_index = 1;
	this.timer = 0;
	this.slides = new Array();
	this.dots = new Array();
	this.init = slideInit;
	this.forward = slideForward;
	this.backward = slideBackward;
	this.slide = slideNext;
	this.start = slideStart;
	this.slideto = slideTo;
	this.stop = slideStop;
	this.pause = slidePause;
}

function slideInit()
{
	var slides = jQ('#' + this.root_id + ' .slide');
	var dots = jQ('#' + this.root_id + ' .slide_dot');

	for (var i=0; i<slides.length; i++) {
		this.slides.push(jQ(slides[i]).css('z-index', String(slides.length-i)).css('position', 'absolute').hide());
		this.dots.push(jQ(dots[i]));
	}
}

function slideForward()
{
	var next_index = (this.current_index + this.slides.length + 1) % this.slides.length;
	this.slideto(this.next_index);
}

function slideBackward()
{
	var next_index = (this.current_index + this.slides.length - 1) % this.slides.length;
	this.slideto(next_index);
}

function slideNext()
{
	this.slides[this.current_index].fadeOut('slow');
	this.dots[this.current_index].attr('src', BIU + 'but-dot-white.png');
	this.slides[this.next_index].find('.slide_drop').hide();
	this.slides[this.next_index].find('.slide_info').hide();
	var nidx = this.next_index;
	this.dots[nidx].attr('src', BIU + 'but-dot-orange.png');
	this.current_index = this.next_index;
	this.next_index = (this.current_index + 1) % this.slides.length;
	this.slides[nidx].fadeIn('slow', function(){
		jQ(this).find('.slide_drop').slideDown('slow');
		jQ(this).find('.slide_info').hide().slideDown('show');
	});
}

function slideTo(n)
{
	if (n < 0 || n >= this.slides.length) {
		return false;
	}
	
    if (n != this.indexCurrent){
        this.pause(5000);
        this.next_index = n;
        this.slide();
    }
    
    return false;
}

function slideStart(n)
{
    //in ms
    this.timer = setInterval('slidebox.slide()',this.delay);
    
    //lets you start at some other slide
    if (typeof n == "number"){
        this.slideto(n);
    }
    
    return true;	
}

function slideStop()
{
    if ((typeof this.timer) == "number") {
    	clearInterval(this.timer);
    }
    
    return true;
}

function slidePause(msecs)
{
    this.stop();
    this.timer = setTimeout('slidebox.start()', msecs);
}

var slidebox = null;

function init_slider()
{
	slidebox = new Slider(4000, 'slide_bx');
	slidebox.init();
	slidebox.start(0);
}
/*
 * End slide box
 */
 
 
