window.addEvent('domready', function(){
	// smooth anchor scrolling
	new SmoothScroll(); 
	// style area
	if(document.id('gkStyleArea')){
		$$('#gkStyleArea a').each(function(element,index){
			element.addEvent('click',function(e){
	            e.stop();
				changeStyle(index+1);
			});
		});
	}
	// font-size switcher
	if(document.id('gkTools') && document.id('gkComponentWrap')) {
		var current_fs = 100;
		var content_fx = new Fx.Tween(document.id('gkComponentWrap'), { property: 'font-size', unit: '%', duration: 200 }).set(100);
		document.id('gkToolsInc').addEvent('click', function(e){ 
			e.stop(); 
			if(current_fs < 150) { 
				content_fx.start(current_fs + 10); 
				current_fs += 10; 
			} 
		});
		document.id('gkToolsReset').addEvent('click', function(e){ 
			e.stop(); 
			content_fx.start(100); 
			current_fs = 100; 
		});
		document.id('gkToolsDec').addEvent('click', function(e){ 
			e.stop(); 
			if(current_fs > 70) { 
				content_fx.start(current_fs - 10); 
				current_fs -= 10; 
			} 
		});
	}
	// login popup
	if(document.id('gkButtonLogin') && document.id('gkLoginPopup')) {
        var popup_enabled = false;
        var popup_over = false;
        var overlay_opacity = 0.75;
        var overlay_fx = new Fx.Morph(document.id('gkLoginPopupOverlay'), {
            duration: 450,
            transition: Fx.Transitions.Expo.easeInOut
        });
        overlay_fx.set({ 'opacity': 0 });
        var popup_fx = new Fx.Morph(document.id('gkLoginPopup'), {
            duration: 450,
            transition: Fx.Transitions.Expo.easeInOut
        });
        document.id('gkLoginPopupOverlay').addEvent('click', function() {
            (function() {
                if(!popup_over) {
                    popup_enabled = false;
                    popup_fx.start({ 'top': -1000, 'opacity': [1, 0] });
                    overlay_fx.set({ 'height' : window.getSize().y });
                    overlay_fx.start({ 'opacity' : 0 });
                }
            }).delay(100);
        });
        document.id('gkLoginPopup').addEvent('click', function() {
            popup_over = true;
        });
        document.id('gkButtonLogin').addEvent('click', function(e) {
			e.stop();
			document.id('gkLoginPopup').setStyle( 'left', (window.getSize().x - 400) / 2 );
            if(popup_enabled) {
                popup_fx.start({ 'top': -1000, 'opacity': [1,0] });
                overlay_fx.set({ 'height' : window.getSize().y });
                overlay_fx.start({ 'opacity' : [overlay_opacity, 0] });
			} else {
                popup_fx.start({ 'top': 260, 'opacity': [0, 1] });
                overlay_fx.set({ 'height' : window.getSize().y });
                overlay_fx.start({ 'opacity' : [0, overlay_opacity] });
			}
			popup_enabled = !popup_enabled;
		});
		document.id('gkLoginPopup').addEvents({
            "mouseenter" : function() { popup_over = true; },
            "mouseleave" : function() { popup_over = false; }
		});
	}
});
// function to set cookie
function setCookie(c_name, value, expire) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expire);
	document.cookie=c_name+ "=" +escape(value) + ((expire==null) ? "" : ";expires=" + exdate.toUTCString());
}
// Function to change styles
function changeStyle(style){
	var file1 = $GK_TMPL_URL+'/css/style'+style+'.css';
	var file2 = $GK_TMPL_URL+'/css/typography.style'+style+'.css';
	new Asset.css(file1);
	new Asset.css(file2);
	Cookie.write('gk1_style',style, { duration:365, path: '/' });
}
