if ($('hdr_flash')){
	swfobject.embedSWF("_swf/steps.swf", "hdr_flash", "1150", "310", "10.0.0", "","");
}

/* Inner labels */
/*if($('login_form')){
	
	$$('#login_form input').invoke('observe','focus',function(e){
		if(this.readAttribute("title")){
			if(this.value == this.readAttribute("title")){
					this.value = "";
			};
		}
	});
	
	$$('#login_form input').invoke('observe','blur',function(e){
		if(this.readAttribute("title")){
			if(this.value == this.readAttribute("title")){
					this.value = "";
			};
		}
	});

}*/


$$('input').each(function(elm){
	if(elm.readAttribute("title")){
		elm.observe("click",function(event){
			if(this.value == this.readAttribute("title"))
				this.value = "";
		});
		elm.observe("blur",function(event){
			if(this.value == "")
				this.value = this.readAttribute("title");
		});
	}
});


$$('#calenders .cal table').invoke('observe','click',function(){
	if(this.getWidth() < 551){ showCal(this); }
	else if (this.getWidth() == 551){ hideCal(this); }
});

$$('#side_studios li').invoke('observe','click',function(){
	cal=this.previousSiblings().size();
	showCal($$('#calenders .cal table')[cal]);
});

function showCal(calender){
	calender.previous('.getheight').setStyle({'height':calender.getHeight()+'px'});
	openedTable = $$('#calenders .opened table');
	calender.up('.cal').up('.block').addClassName('opened');
	openedBlock = $$('#calenders .opened')[0];

	if(openedTable.size() > 0) {
		openedTable.each(function(e){
			hideCal(e);
		});
	}
	if(calender.up('.block').previousSiblings().size() == 3){		
		new Effect.Morph(calender,{style:'left:-283px;width:551px;font-size:11px;',duration:0.2,
			beforeStart:function(){
				nextTable = calender.up('.block').next('div').down('table');
				if(nextTable) nextTable.addClassName('next');
			},
			afterFinish:function(){
				if(openedBlock.hasClassName('blured')) { openedBlock.removeClassName('blured'); }
				
				$$('#calenders .block').each(function(elem){
					if(!elem.hasClassName('opened')){
						elem.addClassName('blured');
					}
				});				
			}
		});
	} else {
		new Effect.Morph(calender,{style:'width:551px;font-size:11px;',duration:0.2,
			beforeStart:function(){
				nextTable = calender.up('.block').next('div').down('table');
				if(nextTable) nextTable.addClassName('next');
			},
			afterFinish:function(){
				if(openedBlock.hasClassName('blured')) { openedBlock.removeClassName('blured'); }
				
				$$('#calenders .block').each(function(elem){
					if(!elem.hasClassName('opened')){
						elem.addClassName('blured');
					}
				});				
			}
		});
	}
}

function hideCal(calender){
	$$('#calenders .blured').each(function(elem){
		elem.removeClassName('blured');
	});
	if(calender.up('.block').previousSiblings().size() == 3){
		new Effect.Morph(calender,{style:'left:0;right:0;width:268px;font-size:5px;',duration:0.2,
			beforeStart:function(){
				nextTable = $$('#calenders .cal table.next');
				if($$('#calenders .cal table.next')){
					nextTable.invoke('removeClassName','next');
				}
			},
			afterFinish:function(){
				calender.up('.cal').up('.block').removeClassName('opened');
				calender.previous('.getheight').setStyle({'height':'0'});
			}
		});
	} else {
		new Effect.Morph(calender,{style:'width:268px;font-size:5px;',duration:0.2,
			beforeStart:function(){
				nextTable = $$('#calenders .cal table.next');
				if($$('#calenders .cal table.next')){
					nextTable.invoke('removeClassName','next');
				}
			},
			afterFinish:function(){
				calender.up('.cal').up('.block').removeClassName('opened');
				calender.previous('.getheight').setStyle({'height':'0'});
			}
		});
	}
}

$$('#cats_form input[type=checkbox]').invoke('observe', 'click', function(e){
	this.up('form').submit();
});

$$('#c_cats input[type=checkbox]').invoke('observe','click',function(){
	cbox = this;
	upperLi = cbox.up('li').up('li');
	hasChecked = false;
	if(upperLi){
		upperLi.addClassName('selected');
		upperLi.down('ul').childElements('li').each(function(elm){
			if(elm.down('input[type=checkbox]').checked){ hasChecked = true;  }
		});
		if(!hasChecked){
			upperLi.removeClassName('selected');
			upperLi.down('ul').addClassName('visible');
			upperLi.down('input[type=checkbox]').checked = false;
		} else {
			upperLi.addClassName('selected');
			upperLi.down('input[type=checkbox]').checked = true;
		}
	}
	if(cbox.next('ul')){
		cbox.up('li').down('ul').childElements('li').each(function(elm){
			if(cbox.checked){
				cbox.up('li').addClassName('selected');
				elm.down('input[type=checkbox]').checked = true;
			} else {
				cbox.up('li').removeClassName('selected');
				cbox.up('li').down('ul').addClassName('visible');
				elm.down('input[type=checkbox]').checked = false;
			}
		});
	}
});

$$('#tmenu li, #c_cats li').invoke('observe','mouseover',function(e){
	if((!this.hasClassName('selected'))&&(this.down('ul'))){
		submenu = this.down('ul');
		if(submenu){
			submenu.addClassName('visible');
			if(!this.hasClassName('selected')){
				this.observe('mouseout',function(e){
					submenu.removeClassName('visible');
				});
			}
		}
	}
});
/*
$$('.c_cal a.disabled').invoke('observe','click',function(e){
	msg = confirm('Du må være registrert / logged inn for å kjøpe danse timer.');
	if(msg) {
		window.location.href = "register.php";
	} else {
		e.stop();
	}
});
*/

if($('err_alert1')){
	alert($('err_alert1').innerHTML);
	history.back();
}

if($('err_alertl')){
	alert($('err_alertl').innerHTML);
	//history.back();
	window.location.href="register.php";
}

if($('added_to_cart')){
	alert($('added_to_cart').innerHTML);
	history.back();
}

/*if($$('.ikke_fortsett')[0] || $$('.beholde_plass')[0]){
	$$('.ikke_fortsett, .beholde_plass').invoke('observe','click',function(e){
		msg = confirm(this.readAttribute('data-question'));
		if(!msg) {
			e.stop();
		}
	});
}
*/
if($$('.what_todo')[0]){
	$$('.what_todo').invoke('observe','click',function(e){
		msg = confirm(this.readAttribute('data-question'));
		if(!msg) {
			e.stop();
		}
	});
}


if($('blinking_cart_link')){
	//$('blinking_cart_link').
	function blinkingCartLink(){
		if(!$('blinking_cart_link').hasClassName('new_color')){
			newColor = "#f5822b";
			$('blinking_cart_link').addClassName('new_color');
		} else {
			newColor = "#514F4F";
			$('blinking_cart_link').removeClassName('new_color');
		}
		new Effect.Morph('blinking_cart_link',{ style:'color:'+newColor, duration:.1 });
		setTimeout('blinkingCartLink()',1000);
	}
	blinkingCartLink();

	//new PeriodicalExecuter(blinkingCartLink(), 3);
}

if ($('index_page')){
	alert("Våre webprogramerere har jobber med hjemmesiden vår. Det er derfor du ikke klarer å melde deg på. Vi ber deg prøve igjen fra kl. 12.00 i dag 6. desember. \nRegistration for new courses for existing dance students will start around 12 o'clock today.");
}



