var addthis_pub				= '[Site name]'; 
var addthis_logo			= '[add_this_logo]';
var addthis_logo_background	= 'ffffff';
var addthis_logo_color		= '201910';
var addthis_brand			= 'IUC';
var addthis_options			= 'favorites, email, delicious, google, digg, reddit, facebook, live, more';

CD3.FontSwitcher = Class.create({
	initialize: function(element, panel, options){
		options = Object.extend({
			classname:	'text-size-',
			max: 		5,
			plus:		'span.big_text',
			reset:		'span.normal_text',
			minus:		'span.small_text'
		}, options || {});

		var buttons = {};

		if (options.plus)	buttons[options.plus]	= this.change.bind(this, 1);
		if (options.reset)	buttons[options.reset]	= this.change.bind(this, 0);
		if (options.minus)	buttons[options.minus]	= this.change.bind(this, -1);

		this.size		= 0;
		this.maxsize	= options.max;
		this.classname	= options.classname;
		this.element	= $(element);
		this.panel		= $(panel).observe('click', function(e){
			for(var b in buttons)
				if (e.findElement(b))
					return buttons[b]();
		});
	},
	change: function(value){
		this.element.removeClassName(this.classname + this.size);

		var size = value == 0 ? 0 : this.size + value;

		this.size = size < 0 ? 0 : ( size > this.maxsize ? this.maxsize : size );

		if (this.size != 0) this.element.addClassName(this.classname + this.size);
	}
});

CD3.Behaviors({
	'body': {
		'focus:in': {
			'input[type=text]': function(){
				if(this.getValue() == this.getAttribute('title')){
					this.setValue('');
					this.addClassName('oppp');
				} else {
					this.addClassName('oppp');

				}
			}
		},
		'focus:out': {
			'input[type=text]': function(){
				if(this.getValue().length == 0){
					this.setValue(this.getAttribute('title'));
					this.removeClassName('oppp');
				}
			}
		}
	},
    '#text_size': function(sizer){
		new CD3.FontSwitcher($$('.inner').first(), sizer, {
			plus:	'span.big_text a',
			reset:	'span.normal_text a',
			minus:	'span.small_text a'
		});
	},
	'#bookmark': {
		mouseover: function(){
			addthis_open(this, '', location.href, addthis_pub);
		},
		mouseout: addthis_close,
		click: addthis_sendto
	},
	'.print_this_page:click': function(){
		print();
	}
});

// TOPMENU
CD3.Behaviors({
	'#topmenu li.toplevel': {
        'mouseover': function(){
            this.addClassName('hover');
        },
        'mouseout': function(){
            this.removeClassName('hover');
        }
    }
});

// NEWS GALLERY
CD3.Behaviors({
	'#thumbs': function(cats){
		var ul = cats.down('ul'), selected = ul.down('.selected');
	    
		if(ul.select('li').size() > 6){
			var lar = $$('.gallery_arrows a#prev').first();
			var rar = $$('.gallery_arrows a#next').first();
			var pages = 1;
			
			new CD3.Sliderr(ul,{
				scrollBy: 216,
				scrollType: 'vertical',
				prev: lar,
				next: rar
			});
		
		}
	    
		var selected = ul.down('li.selected').down('a').href;
	    
		
		$('mainimage').setStyle({
			backgroundImage: 'url('+ selected +')'
		});
		
	},
	'#thumblist li a:click': function(a){
		a.stop();
		var url = this.href;
		
		$('thumblist').down('li.selected').removeClassName('selected');
		this.up('li').addClassName('selected');
		
		
		$('mainimage').setStyle({
			backgroundImage: 'url('+ url +')'
		});
		
	}
});

// If the resolution is too small < 800 px , then resize the important containers
CD3.Behaviors({
    '#outer_center': function(){
        if(parseInt(this.getHeight()) < 800){
            //alert(parseInt(this.getHeight()));
            if($('flash')){
                $('flash').writeAttribute('height', '800px');    
            }
            $('main_main').writeAttribute('height', '800px');
        }    
    },
    '#index_page .right a': {
        mouseover: function(){
                $('index_flash_plane').btnRollOver(this.identify());
			
        },
        mouseout: function(){
                $('index_flash_plane').btnRollOut(this.identify());
        }
    },
	'#index_page .left a': {
        mouseover: function(){
                //console.log(this.identify());
				$('index_flash_plane').selectPlane(this.identify());
        }
    }
});

function setSelectedPlane(id){
	selectedPlane = id;
	$('lang').select('a').each(function(l){
        l.writeAttribute('href', '/' + l.readAttribute('rel') + '/info_pages/10' + '?selected=' + selectedPlane);
        
    });
}