	var theRules = {
	    
		'#box1 h2' : function(el){
			el.onclick = function(){   
				if (Element.hasClassName(this, 'invisible')) {
					new Effect.BlindDown('box1-body'); 
					Element.removeClassName(this, 'invisible');
					setCookie(this.parentNode.id, '', 365);   
				} else {
					new Effect.BlindUp('box1-body');
					Element.addClassName(this, 'invisible'); 
					setCookie(this.parentNode.id, 'invisible', 365);
				}  
			}		
		},
		
	
	
		
		'#box2 h2' : function(el){
			el.onclick = function(){
				if (Element.hasClassName(this, 'invisible')) {
					new Effect.BlindDown('box2-body');
					Element.removeClassName(this, 'invisible');
					setCookie(this.parentNode.id, '', 365);
					// alert('Ukljucen Box, kliknite ponovo da iskljucite');
				} else {
					new Effect.BlindUp('box2-body');
					Element.addClassName(this, 'invisible');
					setCookie(this.parentNode.id, 'invisible', 365);
					// alert('Iskljucen Box, kliknite ponovo da ukljucite');
				}
			}		
		},
		
		
		'#box3 h2' : function(el){
			el.onclick = function(){
				if (Element.hasClassName(this, 'invisible')) {
					new Effect.BlindDown('box3-body');
					Element.removeClassName(this, 'invisible');
					setCookie(this.parentNode.id, '', 365);
				} else {
					new Effect.BlindUp('box3-body');
					Element.addClassName(this, 'invisible');
					setCookie(this.parentNode.id, 'invisible', 365);
				}
			}		
		},
		'#box4 h2' : function(el){
			el.onclick = function(){
				if (Element.hasClassName(this, 'invisible')) {
					new Effect.BlindDown('box4-body');
					Element.removeClassName(this, 'invisible');
					setCookie(this.parentNode.id, '', 365);
				} else {
					new Effect.BlindUp('box4-body');
					Element.addClassName(this, 'invisible');
					setCookie(this.parentNode.id, 'invisible', 365);
				}
			}		
		},	
		
			'#box5 h2' : function(el){
			el.onclick = function(){
				if (Element.hasClassName(this, 'invisible')) {
					new Effect.BlindDown('box5-body');
					Element.removeClassName(this, 'invisible');
					setCookie(this.parentNode.id, '', 365);
				} else {
					new Effect.BlindUp('box5-body');
					Element.addClassName(this, 'invisible');
					setCookie(this.parentNode.id, 'invisible', 365);
				}
			}		
		},
		
		
	'#box6 h2' : function(el){
			el.onclick = function(){
				if (Element.hasClassName(this, 'invisible')) {
					new Effect.BlindDown('box6-body');
					Element.removeClassName(this, 'invisible');
					setCookie(this.parentNode.id, '', 365);
				} else {
					new Effect.BlindUp('box6-body');
					Element.addClassName(this, 'invisible');
					setCookie(this.parentNode.id, 'invisible', 365);
				}
			}		
		},

	'#box7 h2' : function(el){
			el.onclick = function(){
				if (Element.hasClassName(this, 'invisible')) {
					new Effect.BlindDown('box7-body');
					Element.removeClassName(this, 'invisible');
					setCookie(this.parentNode.id, '', 365);
				} else {
					new Effect.BlindUp('box7-body');
					Element.addClassName(this, 'invisible');
					setCookie(this.parentNode.id, 'invisible', 365);
				}
			}		
		},
		
		
	'#box8 h2' : function(el){
			el.onclick = function(){
				if (Element.hasClassName(this, 'invisible')) {
					new Effect.BlindDown('box8-body');
					Element.removeClassName(this, 'invisible');
					setCookie(this.parentNode.id, '', 365);
				} else {
					new Effect.BlindUp('box8-body');
					Element.addClassName(this, 'invisible');
					setCookie(this.parentNode.id, 'invisible', 365);
				}
			}		
		}

	}
	
	Behaviour.register(theRules);
	Behaviour.addLoadEvent(hideBoxes);
	
	function hideBoxes() {
		
		// Id names of all the "boxes"
		boxIds = $("box1","box2","box3","box4","box5","box6","box7","box8");	
		
		
		for (i = 0; i < boxIds.length; i++) {
			if (boxIds[i]) {
				cookieValue = readCookie(boxIds[i].id);
				if (cookieValue == 'invisible') {
					var h2 = boxIds[i].getElementsByTagName('h2');
					Element.addClassName(h2[0], 'invisible');
					var kids = boxIds[i].childNodes;
					for (j = 1; j < kids.length; j++) {
						if (kids[j].id) {
							Element.hide(kids[j]);
						}
					}
				}
			}		
		}	
	}
	
	function setCookie(name,value,days) {
	
	 if (days) {
		 var date = new Date();
		 date.setTime(date.getTime()+(days*24*60*60*1000));
		 var expires = ";expires="+date.toGMTString();
	 } else {
		 expires = "";
	 }
	 document.cookie = name+"="+value+expires+";path=/";
	}
		
	function readCookie(name) {
	 var needle = name + "=";
	 var cookieArray = document.cookie.split(';');
	 for(var i=0;i < cookieArray.length;i++) {
		 var pair = cookieArray[i];
		 while (pair.charAt(0)==' ') {
			 pair = pair.substring(1, pair.length);
		 }
		 if (pair.indexOf(needle) == 0) {
			 return pair.substring(needle.length, pair.length);
		 }
	 }
	 return null;
	}
	
