window.addEvent('domready', function() {
	$$('.hideme').each(function(item) {
		var parents = item.getParent();
		var pupils = parents.getChildren();
		var pre_item = null;
		var pre_found = null;
		pupils.each(function(item2) {
			if(!pre_found) {
				if(item2==item) pre_found = true;
				else pre_item = item2;
			}
		});
		
		var hidelink = new Element('div', {
			'class': 'hidelink',
			'events': {
				'click': function(){
					item.toggleClass('hidden');
					hidelink.setStyle('display','none');
					hidelink2.setStyle('display','block');
				}.bind(this)
			}
		});
		
		var hidelink2 = new Element('div', {
			'class': 'hidelink2',
			'styles': {
				'display': 'none'
			},
			'events': {
				'click': function(){
					item.toggleClass('hidden');
					hidelink2.setStyle('display','none');
					hidelink.setStyle('display','inline');
				}.bind(this)
			}
		});
		hidelink.setHTML('More').injectInside(pre_item);
		hidelink2.setHTML('Minimize').injectAfter(item);
		item.toggleClass('hidden');
		hidelink2.toggleClass('hidden');
	});
	
	if($('horizontal')) {
		var yellow_block = new Element('div', {
			'class': 'open'
		});
		yellow_block.injectInside($E('#horizontal li'));
		var fx = new Fx.Styles($E('#horizontal li'), {duration:200, wait:false});
		$E('#horizontal ul').addEvent('mouseenter', function(){
			$E('#horizontal li div.open').remove();
		});

		$E('#horizontal ul').addEvent('mouseleave', function(){
			var yellow_block = new Element('div', {
				'class': 'open'
			});
			yellow_block.injectInside($E('#horizontal li'));
		});
	}
	
	var Tips4 = new Tips($$('.Tips'), {
		className: 'tool',
		showDelay: 400,
		hideDelay: 400
	});
	
	var Tips4 = new Tips($$('.blue_tip'), {
		className: 'blue',
		fixed: true,
		showDelay: 400,
		hideDelay: 400
	});
	
	
	if($('main').getElement('.redirect')) {
		var column1 = $('main').getElement('.column1');
		var strong_tag = column1.getElement('strong');
		var redirect_link = $('main').getElement('.redirect');
		redirect_link.setStyle('display','none');
		strong_tag.setStyles({
			'display': 'block',
			'position': 'relative',
			'width': '400px'
		});
		var spinner = new Element('img', {
		    'src': 'images/load_spinner.gif',
			'styles': {
				'position': 'absolute',
				'top': '-5px',
				'right': '10px'
			}
		});
		
		spinner.inject(strong_tag,'bottom');
		
		var effect = strong_tag.effect('color', {duration: 800});
		var periodical;

		var fx = function() {
			effect.start('#fff').chain(function() {
				effect.start('#6c5b5d');
			});
		}
		
		fx();
		periodical = fx.periodical(2700);
		(function() {
			window.location = redirect_link.getProperty('href');
			redirect_link.setStyle('display','visible');
		}).delay(2000);
	}
	
	/*
	if($('main').getElements('.redirect_link')) {
		
		var redirect_links = $('main').getElements('.redirect_link');
		redirect_links.each(function(link) {
			redirect_link_effects(link);
		});
		
		$$('a').each(function(a) {
			if(a.href.match('http://buy\.dmp\.com')) {
				if(a.title) redirect_link_effects(a,a.title);
				else redirect_link_effects(a,'Please wait while we redirect you to our buy.dmp.com website.');
			}
			else if(a.href.match('http://')
				&&!a.href.match('http://www-new')
				&&!a.href.match('http://dmp\.localhost')
				&&!a.href.match('http://dmp\.com')
				&&!a.href.match('https://dmp\.com')
				&&!a.href.match('http://www\.dmp\.com')
				&&!a.href.match('https://www\.dmp\.com')) {
				
				if(a.title) redirect_link_effects(a,a.title);
				else redirect_link_effects(a,'Please wait while we redirect off our website.');
			}
		});
		
	}
	*/
});

function redirect_link_effects(el,text) {
	var redirect_link_height = 40;
	var redirect_link_width = 350;
	
	var redirect_div = new Element('div', {
		'id': 'redirect_div',
		'styles': {
			'line-height': (redirect_link_height)+'px',
			'font-size': '12px',
			'background-color': '#fff',
			'color': '#6c5b5d',
			'border': '1px solid #000',
			'padding': '0 10px',
			'white-space': 'nowrap',
			'overflow': 'hidden',
			'position': 'fixed',
			'top': ((document.documentElement.clientHeight/2)-(redirect_link_height/2))+'px',
			'left': ((document.documentElement.clientWidth/2)-(redirect_link_width/2))+'px'
		}
	});
	
	var spinner = new Element('img', {
	    'src': 'http://www-new.dmp.com/images/load_spinner.gif',
		'styles': {
			'position': 'absolute',
			'float': 'right',
			'top': ((redirect_link_height/2)-12)+'px',
			'right': '10px'
		}
	});
	
	
	// box opening effects
	var box_open = new Fx.Styles(redirect_div, {duration: 1000, transition: Fx.Transitions.Quart.easeOut});
	
	// fade effects
	var effect = redirect_div.effect('color', {duration: 800});
	var periodical;

	var fx = function() {
		effect.start('#fff').chain(function() {
			effect.start('#6c5b5d');
		});
	}
	
	el.addEvent('click', function(e){
		new Event(e).stop();
		
		img_title = false;
		if(el.nodeName=='IMG') img_title = el.title;
		
		if(el.nodeName!='A') el = el.getParent();
		if(el.title) redirect_div.setHTML(el.title);
		else if(text||img_title) redirect_div.setHTML((img_title?img_title:text));
		else redirect_div.setHTML('Please wait while we redirect off our website.');

		redirect_div.injectInside($('wrapper'));
		spinner.injectInside(redirect_div);
		
		box_open.start({
			'font-size': [0,12],
			'line-height': [0,redirect_link_height],
		    'height': [0, redirect_link_height],
		    'width': [0, redirect_link_width],	
			'top': [(document.documentElement.clientHeight/2),((document.documentElement.clientHeight/2)-(redirect_link_height/2))],
			'left': [(document.documentElement.clientWidth/2),((document.documentElement.clientWidth/2)-(redirect_link_width/2))]
		});
		
		// start effects
		fx();
		periodical = fx.periodical(2700);
		//(function() {
			window.location = el.getProperty('href');
		//}).delay(2000);
	});
}


function formmated_table_move(direction,link) {
	var box = link.getParent().getParent().getParent().getElement('.formatted_feed_div');
	var box_inner = box.getElement('.formatted_feed');
	var comment_box_height = box.getStyle('height').toInt();
	var comment_height = box_inner.getStyle('height').toInt();
	var comment_margin_top = box_inner.getStyle('margin-top').toInt();
	var space = Math.floor(comment_box_height*0.55);
	if(comment_height > comment_box_height) {
		var arrows_effect = new Fx.Style(box_inner, 'margin-top', { duration: 700, transition: Fx.Transitions.Cubic.easeOut });
		if(direction == 'up') {
			if(comment_margin_top<0) {
				if((comment_margin_top+space)>0) amount = 0;
				else amount = comment_margin_top+space;
				arrows_effect.start(amount);
				
				if(amount>=0) {
					link.getParent().getElement('.advance').removeClass('move');
					link.setStyle('visibility','hidden');
				}
			}
			else {
				link.getParent().getElement('.advance').removeClass('move');
				link.setStyle('visibility','hidden');
			}
			
			if(link.hasClass('move2')) {
				link.removeClass('move2');
				link.getParent().getElement('.advance').setStyle('visibility','visible');
			}
		}
		if(direction == 'down') {
			if(Math.abs(comment_margin_top)<(comment_height-comment_box_height)) {
				arrows_effect.start(comment_margin_top-space);
				if(!link.hasClass('move')) {
					link.addClass('move');
				}	
				link.getParent().getElement('.retract').setStyle('visibility','visible');
				
				//alert((comment_box_height+comment_margin_top)+'#'+comment_height);
				if(comment_height<=(comment_box_height+comment_margin_top)) {
					link.setStyle('visibility','hidden');
					link.getParent().getElement('.retract').addClass('move2').setStyle('visibility','visible');
				}
				//alert((Math.abs(comment_margin_top)+comment_box_height+space)+"#"+comment_height);
				if(Math.abs(comment_margin_top)+comment_box_height+space>comment_height) {
					link.setStyle('visibility','hidden');
					link.getParent().getElement('.retract').addClass('move2').setStyle('visibility','visible');
				}
				
				
			}
			else {
				link.setStyle('visibility','hidden');
				link.getParent().getElement('.retract').addClass('move2');
			}
		}
	}
}
