/*--------------------------------------------------------------
# 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);
			});
		});
		$A($$('.bg_switcher')).each(function(element,index){
			element.addEvent('click',function(event){
				var event = new Event(event);
				event.preventDefault();
				changeBg(index);
			});
		});
		new SmoothScroll();
	}
	//
	if($('login')) $('login').addEvent("click",function(e){new Event(e).stop();
		gk_popup('popup_login',600,500);
	});
	
	if($('login_noborder')) $('login_noborder').addEvent("click",function(e){new Event(e).stop();
		gk_popup('popup_login',600,500);
	});
	
	if($('register')) $('register').addEvent("click",function(e){new Event(e).stop();
		gk_popup('popup_register',500,300);
	});
	//
	// users_wrap I
	//
	if($ES('.users_wrap')[0]){
		if($ES('.moduletable_content', $ES('.users_wrap')[0]).length > 0){
			var max = 0;
			$ES('.moduletable_content', $ES('.users_wrap')[0]).each(function(el){ if(el.getSize().size.y > max) max = el.getSize().size.y; });	
			$ES('.moduletable_content', $ES('.users_wrap')[0]).each(function(el){ el.setStyle("height", max+"px"); });	
		}		
	}
	// users_wrap II
	if($ES('.users_wrap')[1]){
		if($ES('.moduletable_content', $ES('.users_wrap')[1]).length > 0){
			var max = 0;
			$ES('.moduletable_content', $ES('.users_wrap')[1]).each(function(el){ if(el.getSize().size.y > max) max = el.getSize().size.y; });	
			$ES('.moduletable_content', $ES('.users_wrap')[1]).each(function(el){ el.setStyle("height", max+"px"); });	
		}			
	}
	// users_wrap III
	if($('bottom1')){
		if($ES('.moduletable_content', $('bottom1')).length > 0){
			var max = 0;
			$ES('.moduletable_content', $('bottom1')).each(function(el){ if(el.getSize().size.y > max) max = el.getSize().size.y; });
			$ES('.moduletable_content', $('bottom1')).each(function(el){ el.setStyle("height", max+"px"); });	
		}			
	}

});

function gk_popup(popup_id, x, y){
	var p = $(popup_id);
 	var overlay = $('gk_overlay');
 	overlay.setStyle("display","block");
 	var overlay_o = new Fx.Opacity(overlay,{duration:300}).set(0);
 
	if(p.getStyle("display") != "block"){
		p.setStyle("display","block");
		p.setStyle("left",((window.getSize().size.x - 40 - x) / 2)+"px");
	  
		var fintop = ((window.getSize().size.y - 40 - y) / 2);
	  
		if(window.opera) p.setStyle("top","50px");
		if(window.opera) fintop = 50;
		
		new Fx.Style(p,'top',{duration:350}).start(0,fintop);
		
		new Fx.Opacity(p,{duration:350}).start(1);
		overlay_o.start(0.7);
		p.setStyles({
			"width":x+40+"px",
			"height":y+40+"px"
		}); 
		
		new Fx.Style($E('.gkp_t',p),'width',{duration:350}).start(0,x);
		new Fx.Style($E('.gkp_b',p),'width',{duration:350}).start(0,x);
		new Fx.Style($E('.gkp_m',p),'width',{duration:350}).start(0,x);
		
		new Fx.Style($E('.gkp_m',p),'height',{duration:350}).start(0,y);
		new Fx.Style($E('.gkp_ml',p),'height',{duration:350}).start(0,y);
		new Fx.Style($E('.gkp_mr',p),'height',{duration:350}).start(0,y);
		
		$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);
			overlay_o.start(0);
			(function(){
				new Fx.Opacity(p, {duration:350}).start(0);
				new Fx.Style(p, 'top',{duration:350}).start(fintop, 0);
				new Fx.Style($E('.gkp_t', p),'width',{duration:350}).start(x, 0);
				new Fx.Style($E('.gkp_b', p),'width',{duration:350}).start(x, 0);
				new Fx.Style($E('.gkp_m', p),'width',{duration:350}).start(x, 0);
				
				new Fx.Style($E('.gkp_m', p),'height',{duration:350}).start(y, 0);
				new Fx.Style($E('.gkp_ml', p),'height',{duration:350}).start(y, 0);
				new Fx.Style($E('.gkp_mr', p),'height',{duration:350}).start(y, 0);
				
				(function(){
				 	p.setStyle("display","none");
				}).delay(350);
			}).delay(350); 
		};
	}
}
// Function to change backgrounds
function changeStyle(style){
	var file = $template_path+'/css/style'+style+'.css';
	new Asset.css(file);
	new Cookie.set('gk30_style',style,{duration: 200,path: "/"});
}
function changeBg(style){
	var file = $template_path+'/css/'+((style == 1) ? 'dark' : 'white')+'.css';
	new Asset.css(file);
	new Cookie.set('gk30_bg',(style == 1) ? 'dark' : 'white',{duration: 200,path: "/"});
};

/* Add functions on window load */
window.addEvent('domready', WarpTemplate.start);
// Sliding Menu Script
// copyright Stephen Chapman, 6th July 2005
// you may copy this code but please keep the copyright notice as well
var speed = 6;

var aDOM = 0, ieDOM = 0, nsDOM = 0; var stdDOM = document.getElementById;
if (stdDOM) aDOM = 1; else {ieDOM = document.all; if (ieDOM) aDOM = 1; else {
var nsDOM = ((navigator.appName.indexOf('Netscape') != -1)
&& (parseInt(navigator.appVersion) ==4)); if (nsDOM) aDOM = 1;}}
function xDOM(objectId, wS) {
if (stdDOM) return wS ? document.getElementById(objectId).style:
document.getElementById(objectId);
if (ieDOM) return wS ? document.all[objectId].style: document.all[objectId];
if (nsDOM) return document.layers[objectId];
}
function objWidth(objectID) {var obj = xDOM(objectID,0); if(obj.offsetWidth) return obj.offsetWidth; if (obj.clip) return obj.clip.width; return 0;}
function objHeight(objectID) {var obj = xDOM(objectID,0); if(obj.offsetHeight) return obj.offsetHeight; if (obj.clip) return obj.clip.height; return 0;}
function setObjVis(objectID,vis) {var objs = xDOM(objectID,1); objs.visibility = vis;}
function moveObjTo(objectID,x,y) {var objs = xDOM(objectID,1); objs.right = x; objs.top = y;}
function pageWidth() {return window.innerWidth != null? window.innerWidth: document.body != null? document.body.clientWidth:null;}
function pageHeight() {return window.innerHeight != null? window.innerHeight: document.body != null? document.body.clientHeight:null;}
function posRight() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset: document.documentElement.scrollRight? document.documentElement.scrollRight: document.body.scrollRight? document.body.scrollRight:0;}
function posTop() {return typeof window.pageYOffset != 'undefined' ? window.pageYOffset: document.documentElement.scrollTop? document.documentElement.scrollTop: document.body.scrollTop? document.body.scrollTop:0;}
var xxx = 0; var yyy = 0; var dist = distX = distY = 0; var stepx = 2; var stepy = 0; var mn = 'smenu';
function distance(s,e) {return Math.abs(s-e)}
function direction(s,e) {return s>e?-1:1}
function rate(a,b) {return a<b?a/b:1}
function start() {xxx = -0; yyy = 250; var eX = 0; var eY = 100; dist = distX = distance(xxx,eX); distY = distance(yyy,eY); stepx *= -direction(xxx,eX) * rate(distX,distY); stepy *= direction(yyy,eY) * rate(distY,distX); moveit();
setObjVis(mn,'visible');}
function moveit() {var x = (posRight()+xxx) + 'px'; var y = (posTop()+yyy) + 'px'; moveObjTo(mn,x,y);}
function mover() {if (dist > 0) {xxx += stepx; yyy += stepy; dist -= Math.abs(stepx);} moveit(); setTimeout('mover()',speed);
}
function slide() {dist = distX; stepx = -stepx; moveit(); setTimeout('mover()',speed*2);return false;}
onload = start;
window.onscroll = moveit;
                  
