var ArticleManager = new Class( {
	initialize:function()
	{
	    if( ArticleManager.inited)
	        return;
	    ArticleManager.inited = true;
	    $$( '.artheader').each( function( el, idx) {
	    	el.addEvent( 'mouseover', function() 
	    	{ 
	    		if(this.hasClass( 'artselected'))
	    		    return;
	    		$$('.artselected').each( function( el,idx) { el.toggleClass( 'artselected')});
	    		this.toggleClass( 'artselected');
	    		ArticleManager.current.select( this);
	    	});
	    });
	    this.image = $( 'topimage');
	    this.stopRotation = false;
	    $('mainholder').addEvent( 'mouseover', function(){ $clear( ArticleManager.current.timerId)});
	    $('mainholder').addEvent( 'mouseleave', function(){ ArticleManager.current.timerId = ArticleManager.current.rotate.periodical( 8000, ArticleManager.current)});
	    ArticleManager.current = this;
	    this.timerId = this.rotate.periodical( 8000, this);
	},
	rotate:function()
	{
	    var selected = $$('.artselected')[0];
	    selected.toggleClass( 'artselected');
	    var el = selected.getNext();
	    if( !el)
	        el = $$('.artheader')[0];
	    el.toggleClass( 'artselected');
	    this.select( el);
    },
	select:function( el)
	{
		var curr = ArticleManager.current;
		var img = $( 'image_'+el.getAttribute( 'id')).value;
		curr.image.src = img;
	}
});

window.addEvent( 'domready',function() {
    $$( "input, textarea").each( function( el, idx) 
    {    
        if( el.getParent().hasClass( 'input'))
        {
            el.addEvent( 'focus', function() { this.getParent().toggleClass( 'input_focus')});
            el.addEvent( 'blur', function() { this.getParent().toggleClass( 'input_focus')});
        }
        if( el.getParent().hasClass( 'textarea'))
        {
            el.addEvent( 'focus', function() { this.getParent().toggleClass( 'textarea_focus')});
            el.addEvent( 'blur', function() { this.getParent().toggleClass( 'textarea_focus')});
        }
        if( el.getParent().hasClass( 'textarea_big'))
        {
            el.addEvent( 'focus', function() { this.getParent().toggleClass( 'textarea_big_focus')});
            el.addEvent( 'blur', function() { this.getParent().toggleClass( 'textarea_big_focus')});
        }
        
    });
});

/** tinymce */
function convertWord(type, content) 
{
      switch (type) 
      {
          // Gets executed before the built in logic performes it's cleanups
          case "before":
              // do nothing
              break;
          // Gets executed after the built in logic performes it's cleanups
          case "after":
              content = content.replace(/<(!--)([\s\S]*)(--)>/gi, "");
              break;
    }
    return content;
}

function pollVote( pollId)
{
    $$('.vg_input').each( function( el, idx) {
        if( el.checked)
        {
            new Ajax( '/polls/vote.xl?poll='+pollId+"&choice="+el.value, {method:'get',update:$('pollcontent')}).request();            
        }
    });
    //
}
