/*--------------------------------------------------------------
# Pulse - October 2009 (for Joomla 1.5)
# Copyright (C) 2007-2009 Gavick.com. All Rights Reserved.
# License: Copyrighted Commercial Software
# Website: http://www.gavick.com
# Support: support@gavick.com  
---------------------------------------------------------------*/

window.addEvent("load",function(){
	var $b = $(document.getElementsByTagName('body')[0]);
	// smoothscroll init
	new SmoothScroll();
	// 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();
	}
	//
	//if($('joinButton')) $('joinButton').addEvent("click",function(e){new Event(e).stop();
	//	gk_popup('popup_join',450,400);
	//});
	//
	
	// 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");
			});
		}
	});

	// FLOATING PANEL
	if($('floating_panel') && $('floating_panel').hasClass('animate')){
		var panel = $('floating_panel');
		var topAnim = new Fx.Style(panel,'top',{duration:500,wait:false,transition:Fx.Transitions.Back.easeOut});
		var limit = panel.getParent().getCoordinates().top;
		var bottomLimit = panel.getParent().getSize().size.y - panel.getSize().size.y - 20;
		window.addEvent("scroll",function(){
			var pos = window.getScrollTop();
			if(pos <= limit) topAnim.start(36);
			else if(pos <= bottomLimit) topAnim.start(pos-limit+40);
			else topAnim.start(bottomLimit);
		});
	}

});

function gk_popup(popup_id, x){
	var p = $(popup_id);
 
	if(p.getStyle("display") != "block"){
		p.setStyle("display","block");
		y = $E('.popup_padding',p).getSize().size.y + 30;

		var fintop = ((window.getSize().size.y - 90) / 2);

		p.setStyles({
			"left" : ((window.getSize().size.x - 40 - x) / 2)+"px",
			"top" : (fintop) + "px"
		});

	  
		if(window.opera) p.setStyle("top","250px");
		if(window.opera) fintop = 250;
		
		new Fx.Opacity(p,{duration:500}).start(1);
		
		p.setStyles({
			"width" : x+40+"px",
			"height" : "90px"
		}); 
		
		$E('.gkp_t',p).setStyle("width",x+"px");
		$E('.gkp_b',p).setStyle("width",x+"px");
		$E('.gkp_m',p).setStyles({
			"width":x+"px",
			"height":90+"px"
		});
		
		(function(){
			new Fx.Style($E('.gkp_m',p),'min-height',{duration:350}).start(90,y);
			new Fx.Style(p,'top',{duration:350}).start(fintop, fintop - ((y+40)/2));	
		}).delay(500);
		
		$E('.gk_popup_close',p).setStyle("opacity",0);
		(function(){new Fx.Opacity($E('.gk_popup_close',p),{duration:350}).start(1);}).delay(350);
		
		$E('.popup_padding',p).setStyle('opacity',0);
		(function(){new Fx.Opacity($E('.popup_padding',p),{duration:350}).start(0,1);}).delay(350);
		
		$E('.gk_popup_close',p).onclick = function(){
			new Fx.Opacity($E('.gk_popup_close',p),{duration:350}).start(0);
			new Fx.Opacity($E('.popup_padding',p),{duration:350}).start(0);
			new Fx.Opacity(p,{duration:350}).start(0);	
			(function(){
		 		p.setStyle("display","none");
		 		$E('.gkp_m',p).setStyle('min-height',0);
			}).delay(350); 
		};
	}
}
// Function to change backgrouns
function changeStyle(style){
	var file = $template_path+'/css/style'+style+'.css';
	new Asset.css(file);
	new Cookie.set('gk31_style',style,{duration: 200,path: "/"});
}
