window.addEvent('domready', function() 
{
	//setForm();
	//loadXML();
	loadAccordion();
	//setToolTips();
	
	
	

	$$('ul.webnav').addEvent('mouseenter', webnavEnter = function() 
	{
		this.setStyle('background-position','0 -35px');													
	});
	
	$$('ul.webnav').addEvent('mouseleave', webnavLeave = function() 
	{
		this.setStyle('background-position','0px 0px');													
	});
	
	$$('ul.webnav').addEvent('mousedown', webnavDown = function() 
	{
		this.setStyle('background-position','0px -70px');													
	});
	
	$$('a.btn_comment').addEvent('click', showComment);
	
	
});

var xmlDoc;

function loadXML() {
  
 
}

function processReqChange() {
   
  
}


function readXML()
{
	
}


function loadSlideShow(name, imgs, url) {
	
}

function loadAccordion() {
		
	var CookieAutoAccordion = Accordion.extend({
														   
	  initialize: function(togglers, elements, options) {
		this.options.cookieName = 'accordion-place';
		this.options.cookieOptions = {path: '/', duration: 30};	
		this.setOptions(options);
		this.options.allowMultipleOpen = false;
		this.options.opacity = false;
		this.options.openAll = false;
		this.options.wait = false;
		var cookieValue = false;
			
		if (cookieValue != false) {
		  this.options.show = cookieValue.toInt();
		  this.addEvent('onActive', function(toggler, element) {
				toggler.addClass('webnav_active');
			});							 
		} else {
		  this.addEvent('onActive', function(toggler, element) {
				toggler.addClass('webnav_active');
			});
		}

		this.parent.apply(this, arguments);
		this.addEvent('onActive', function(toggler, element) {
		  Cookie.set(this.options.cookieName, this.togglers.indexOf(toggler), this.options.cookieOptions);
		  toggler.addClass('webnav_active');
		});
		this.addEvent('onBackground', function(toggler, element) {
			$$('p.web_comment').addClass('hide');
			if (toggler.hasClass('webnav_active')) {
				toggler.removeClass('webnav_active');
			}
		});
	  }
	});
			
	var accordion = new CookieAutoAccordion($$('ul.webnav'), $$('div.web_content'));	
		
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  var styleCookieOptions = {path: '/', duration: 1};
  Cookie.set('style', title, styleCookieOptions);
}

function setForm() {
	
}
function resetForm() {
	
}


function setTheme(){
	
}

function setActiveStyleSheet(title) {
	
		loadStyle('light');	
	
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == title) a.disabled = false;
		}
	}
}

function loadStyle(theme) {
	
			
			$$('a.style_light').setStyle('background-position','0 -38px');
			$$('a.style_dark').setStyle('background-position','0 0');
			$$('a.style_sunrise').setStyle('background-position','0 0');
			
			$$('a.style_dark').addEvent('mouseenter', themeBtnOver);
			$$('a.style_dark').addEvent('mouseleave', themeBtnOut);
			$$('a.style_dark').addEvent('mousedown', themeBtnDown);
			
			$$('a.style_sunrise').addEvent('mouseenter', themeBtnOver);
			$$('a.style_sunrise').addEvent('mouseleave', themeBtnOut);
			$$('a.style_sunrise').addEvent('mousedown', themeBtnDown);

			$$('div.themeselector p').setHTML('<strong>Current theme: </strong><span>Day</span><br />It will change to the night theme at 6PM.');
			$$('p.web_header img').setProperty('src','images/light/link_arrow_green.gif');
			
		
	
	$$('a.style_'+theme).removeEvent('mouseenter', themeBtnOver);
	$$('a.style_'+theme).removeEvent('mouseleave', themeBtnOut);
	$$('a.style_'+theme).removeEvent('mousedown', themeBtnDown);
	
		
	
	$$('div.web_footer a.btn_comment').setStyle('background-image','url(images/'+theme+'/btn_comment.gif)');
	$$('div.web_footer a.btn_comment').setStyle('background-image','url(images/'+theme+'/btn_comment.gif)');
	
}

function themeBtnOver() {
	this.setStyle('background-position','0 -19px');
}

function themeBtnOut() {
	this.setStyle('background-position','0 0');
}

function themeBtnDown() {
	this.setStyle('background-position','0 -38px');
}

function setToolTips() {

	
	var tip_light = new Tips($$('a.style_light img'), {
		showDelay: 200,
		hideDelay: 100,
		className: 'tt_day',
		offsets: {'x': 2, 'y': -17},
		fixed: true
	});	
	
	var tip_desc = new Tips($$('a.btn_comment'), {
		showDelay: 200,
		hideDelay: 100,
		className: 'tt_desc',
		offsets: {'x': 1, 'y': -17},
		fixed: true
	});	

}

function showComment() {
	objElement = $$('p.web_comment');
	objElement.toggleClass('hide')
};

function addBtnAction(id, url,  mouseleave, mouseenter, mousedown) {
	
	id.setStyle('background-image', 'url('+url+')');
	
	id.addEvent('mouseenter', function()
	{
		id.setStyle('background-position','0 '+mouseenter);
	});
	
	id.addEvent('mouseleave', function()
	{
		id.setStyle('background-position','0 '+mouseleave);
	});
	
	id.addEvent('mousedown', function()
	{
		id.setStyle('background-position','0 '+mousedown);
	});
	
	id.addEvent('mouseup', function()
	{
		id.setStyle('background-position','0 '+mouseenter);
	});
}
function setClock() {
	
}


