window.addEvent("load",function(){
	var $b = $(document.getElementsByTagName('body')[0]);
	// help variables
	var login_opened = false;
	var register_opened = false;
	// animation classes - Fx.Height and Fx.Opacity
	Fx.Height = Fx.Style.extend({initialize: function(el, options){this.parent(el, 'height', options);this.element.setStyle('overflow', 'hidden');},toggle: function(){return (this.element.offsetHeight > 0) ? this.custom(this.element.offsetHeight, 0) : this.custom(0, this.element.scrollHeight);},show: function(){return this.set(this.element.scrollHeight);}});
	Fx.Opacity = Fx.Style.extend({initialize: function(el, options){this.now = 1;this.parent(el, 'opacity', options);},toggle: function(){return (this.now > 0) ? this.start(1, 0) : this.start(0, 1);},show: function(){return this.set(1);}});
	//
	if($('stylearea')){
		$A($$('.style_switcher')).each(function(element,index){
			element.addEvent('click',function(event){
				var event = new Event(event);
				event.preventDefault();
				changeStyle(index+1);
			});
		});
		new SmoothScroll();
	}
	// EQUAL COLUMNS
	var equalizers = $$('.equal_col');
	equalizers.each(function(wrap,i){
		var max = 0;
		var cols = wrap.getElementsBySelector('.equal');
		var col_amount = 0;
		
		cols.each(function(col,j){
			if((col.getParent() == wrap || col.getParent().hasClass("helper"))){ 
				col_amount++;
				if(col.getSize().size.y > max) max = col.getSize().size.y; 
			}
		});
		
		if(col_amount > 1){
			cols.each(function(col){
				if(col.getParent() == equalizers[i] || col.getParent().hasClass("helper")) col.setStyle("min-height", max + "px");
			});
		}
	});
	
	if($('login_btn')){ 
		$('login_btn').addEvent("click",function(e){
			new Event(e).stop();
			(function(){gk_popup('popup_login',600,85);}).delay((register_opened) ? 500 : 0);
			login_opened = true;
			
			if(register_opened){
				$E('.gk_popup_close',$('popup_register')).fireEvent("click");
				register_opened = false;
			}
		});
		
		$E('.gk_popup_close',$('popup_login')).addEvent("click", function(){
			login_opened = false;
		});
	}
	
	if($('register')) {
		$('register').addEvent("click",function(e){
			new Event(e).stop();
			(function(){gk_popup('popup_register',500,321);}).delay((login_opened) ? 500 : 0);
			register_opened = true;
			
			if(login_opened){
				$E('.gk_popup_close',$('popup_login')).fireEvent("click");
				login_opened = false;
			}
		});
		
		$E('.gk_popup_close',$('popup_register')).addEvent("click", function(){
			register_opened = false;
		});
	}
});

function gk_popup(popup_id, x, y){
	var p = $(popup_id);
 	var fintop = (window.getSize().size.y / 2);
 	
	if(p.getStyle("display") != "block"){	  
		if(window.opera){
			fintop = ((window.innerHeight / 2) + window.getScrollTop());
		}  
		
		p.setStyles({
			"overflow":"hidden",
			"width":x + 46 + "px",
			"height":y + 46 + "px",
			"left":((window.getSize().size.x-(x-46)) / 2)+"px",
			"top":(fintop-((y+46)/2)) + 120 +"px",
			"opacity":0
		});
		
		(function(){p.setStyle("display","block");}).delay(25);
		
		$E('.gkp_t',p).setStyle('width',x);
		$E('.gkp_b',p).setStyle('width',x);
		$E('.gkp_m',p).setStyle('width',x);
			
		$E('.gkp_m',p).setStyle('height',y);
		$E('.gkp_ml',p).setStyle('height',y);
		$E('.gkp_mr',p).setStyle('height',y);
		
		(function(){
			new Fx.Opacity(p,{duration:200}).start(1);
			$E('.gkp_m',p).setStyle("display","block");
			new Fx.Style(p,"top",{duration:200}).start((fintop-((y+46)/2))+"px");
			
			$E('.gk_popup_close',p).setStyle("opacity",0);
			(function(){new Fx.Opacity($E('.gk_popup_close',p),{duration:200}).start(1);}).delay(200);
			
			$E('.popup_padding',p).setStyle('opacity',0);
			(function(){new Fx.Opacity($E('.popup_padding',p),{duration:200}).start(0,1);}).delay(500);
		}).delay(125);

		$E('.gk_popup_close',p).addEvent("click", function(){
			new Fx.Opacity($E('.gk_popup_close',p),{duration:200}).start(0);
			new Fx.Opacity($E('.popup_padding',p),{duration:200}).start(0);
			(function(){				
				(function(){
					new Fx.Opacity(p, {duration:200}).start(0);
				 	new Fx.Styles(p,{duration:200}).start({
						"top":(fintop+120)+"px"
					}); 
					
					(function(){p.setStyle("display","none");}).delay(200);
				}).delay(200);
			}).delay(200);
		});
	}
}
// Function to change backgrouns
function changeStyle(style){
	var file = $template_path+'/css/style'+style+'.css';
	new Asset.css(file);
	new Cookie.set('gk33_style',style,{duration: 200,path: "/"});
	if(Cufon) (function(){Cufon.refresh();}).delay(1000);
}