document.observe("dom:loaded", runAutoFunctions);

function runAutoFunctions() 
{ 	
	autoBlur();
        loadTabs();
        savoMain();
        mainPost();
}


function autoBlur()
{
	$$('a', 'input[type=checkbox]', 'input[type=submit]', 'input[type=image]').each
	(
		function(element) 
		{
			element.observe('focus', blur);
			
		}
	);
}

function blur(event)
{
	Event.element(event).blur();
}



function toggleSubmenu(trigger,submenuId)
{
 var submenu = $(submenuId);
 if (!submenu.visible())
 {	
	//sipka dole
	$(trigger).addClassName('submenu');
 }
 else
 {
	$(trigger).removeClassName('submenu');
	//sipka normal
 }
 Effect.toggle(submenuId,'slide',{ duration: 0.3 });
}

function replyToComment(element, comment_parent)
{
	$(element).insert({'after':$('newCommentForm')});
	
	$$('.replyToComment').each(
		function(element)
		{
			element.show();
		}
	);

        $('comment_parent').value = comment_parent;

	$(element).hide();
}


function toogleTab(trigger, content, contentId)
{
	var $content = $(content + '-' + contentId);
	var $page = $(content + 'Page-' + contentId);
	$$('.'+content).each(
	 function(element)
	 {
		element.hide();
	 }
	 );
	
	$$('.'+content + 'Page').each(
	 function(element)
	 {
		if (element.hasClassName('selected'))
			element.removeClassName('selected');
	 }
	 );
	
	$content.show();
	$page.addClassName('selected');
}

function printPost()
{
    window.print();
}

// tabs
function loadTabs() {

  // most popular
  if($('container_most_popular')) {
      var tabsMostPolular = new tabset('container_most_popular', {
      classNames: {
        tab:        'tab',      // class name used to identify the tabs
        panel:      'panel',    // class name used to identify the tab content
        tabActive:  'selected'  // class name added to the active tab
      },
      ids: {
        tab:        'tab_',     // what to strip off the tab id to get the tab name
        panel:      'panel_'    // what to strip off the tab content id to get the tab name
      },
      onEvent:      'click',    // perhaps you want to activate on mouseover? not recommended
      effects:      true        // set this to false if you do not want to include effects.js
     });

     tabsMostPolular.autoActivate($('tab_week'));
 }

 // social
 if($('container_social')) {
      var tabsSocial = new tabset('container_social', {
      classNames: {
        tab:        'tab',      // class name used to identify the tabs
        panel:      'panel',    // class name used to identify the tab content
        tabActive:  'selected'  // class name added to the active tab
      },
      ids: {
        tab:        'tab_',     // what to strip off the tab id to get the tab name
        panel:      'panel_'    // what to strip off the tab content id to get the tab name
      },
      onEvent:      'click',    // perhaps you want to activate on mouseover? not recommended
      effects:      true        // set this to false if you do not want to include effects.js
     });

     tabsSocial.autoActivate($('tab_facebook'));
 }

}

// search text in imput
function savoDoset(element, value) {
  element.value = value;
}

function savoReset(element) {
  if (element.value == '') {
    savoDoset(element, element.readAttribute('title'));
  }
}

function savoMain() {
	$$('.j-savo input, input.j-savo, .j-savo textarea, textarea.j-savo').each(function(element) {
		element.observe('click', function(event) {
			if (element.value == element.readAttribute('title')) {
				savoDoset(event.element(), '');
			}
		});

		element.observe('blur', function(event) {
			savoReset(event.element())
		});

		savoReset(element, true);
	});
}

// main post in home page
function mainPost() {

    if($('mainPost') != null)
    {
        var main_post_height = $('mainPost').getStyle('height');
        var main_post_height_number = main_post_height.replace('px', '');
        main_post_height = Math.round(main_post_height_number);
        
        var paperclip2_top = main_post_height - 40;
        $('paperclip2').setStyle({top: paperclip2_top + 'px'});
    }

}
