var IE = !window.getComputedStyle && !!document.getElementById;
var IE6 = IE && navigator.appVersion.indexOf('MSIE 7') == -1 && navigator.appVersion.indexOf('MSIE 8') == -1;
window.onload = function(){
	init_news();	
	init_menu_hover();
	init_category();
	init_scroll();
	init_title_news();
	init_help_hover();
};
function init_news(){
	var root = $('news-content');
	if(!root){
		return false;
	}
	var items = $C('item', root, 'DIV');
	items.each(function(item){
		var links = $T('A', item);
		links.each(function(link){
			link.onmouseover = function(){
				this.addClass('over');
			}.bind(item);
			link.onmouseout = function(){
				this.removeClass('over');
			}.bind(item);
		});
	});
}
function init_menu_hover(){
	var root = $('menu');
	if(!root){
		return false;
	}
	var items = $C('item', root, 'DIV');
	items.each(function(item){
		item.img = $T('IMG', item, 1);
		item.img.style.visibility = 'visible';
		var h = Math.floor(Number(item.img.height) / 2);
		item.style.height = h + 'px';
		//item.style.width = Number( item.img.width ) + 15 + 'px';
		item.style.overflow = 'hidden';
		item._height = h;
		if(IE6){
			fix_png(item.img);
		}
		item.link = $T('A', item, 1);
		item.link.onmouseover = function(){
			this.addClass('over');
			if(this.hasClass('here')){
				return false;
			}
			this.img.style.top = - this._height + 'px';
		}.bind(item);
		item.link.onmouseout = function(){
			this.removeClass('over');
			if(this.hasClass('here')){
				return false;
			}
			this.img.style.top = 0;
		}.bind(item);
		if(item.hasClass('here')){
			item.img.style.top = - item._height + 'px';
		}
	});
}
function init_category(){
	var root = $('category');
	if(!root){
		return false;
	}
	var items = $C('item', root, 'DIV');
	items.each(function(item){
		var link = $T('A', item, 1);
		link.onmouseover = function(){
			this.addClass('over');
		}.bind(item);
		link.onmouseout = function(){
			this.removeClass('over');
		}.bind(item);
		if(IE6){
			var img = $T('IMG', item, 1);
			fix_png(img);
		}
	});
}
function png_filter(src){
	return 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + src + '", sizingMethod="crop")';
}
function fix_png(img){
	img.style.width = img.width + 'px';
	img.style.height = img.height + 'px';
	var src = img.src;
	var name = img.nameProp;
	img.src = img.src.replace('t/' + img.nameProp, 'blank.gif');
	img.style.filter = png_filter(src);

}

function init_scroll(){

	var root = $('scroll-holder');
	if(!root){
		return false;
	}
	var tim = new Timer(100);
	tim.start();
	var content = $('scroll-content');

	var bar = $('scroll-bar');
	var bPlus = $('b-plus');
	var bMinus = $('b-minus');
	var track = $('track');
	var thumb = $('thumb');

	var scroll = new Scroll(root, content, {X: null, Y: {
		bar: bar,
		bPlus: bPlus, 
		bMinus: bMinus,
		track: track,
		thumb: thumb
	}}, tim);
}
function init_title_news(){
	var root = $('news');
	if(!root){
		return false;
	}
	var items = $C('item', root, 'DIV');
	items.each(function(item){
		var links = $T('A', item);
		links.each(function(link){
			link.onmouseover = function(){
				this.addClass('over');
			}.bind(item);
			link.onmouseout = function(){
				this.removeClass('over');
			}.bind(item);
		});
	});
}
function init_help_hover(){
	var root = $('help');
	if(!root){
		return false;
	}
	var imgs = $T('IMG', root);
	imgs.each(function(img){
		img.onmouseover = function(){
			var name = this.src.substr(this.src.lastIndexOf('\/') + 1);
			var name2 = '';
			if(name.match(/\d/)){
				name2 = name.replace(/\d/, '');
			}else{
				name2 = name.replace('.gif', '2.gif');
			}
			img.src = img.src.replace(name, name2);
		};
		img.onmouseout = function(){
			var name = this.src.substr(this.src.lastIndexOf('\/') + 1);
			var name2 = '';
			if(name.match(/\d/)){
				name2 = name.replace(/\d/, '');
			}else{
				name2 = name.replace('.gif', '2.gif');
			}
			img.src = img.src.replace(name, name2);
		};
	});
}
