// abonare mex
function abonare() { 
    window.open("/abonare.php","abonare","width=500px,height=520px");
}

var Phototicker = Class.create();
Phototicker.prototype = {
	initialize: function()
	{
		this.interval = 10000;
		this.pause = 1000;
		this.container = $("partnersbox");
		this.elements  = $A(this.container.getElementsByTagName("li"));
		this.number_of_elements = this.elements.length - 7;
		
		this.current_element = 1;
		this.timer = setInterval(this.tick.bind(this), this.interval);
  	},
	tick: function()
	{
		this.prev_element = this.current_element - 1;
		if(this.current_element > this.number_of_elements){
			this.current_element = 1;
			
		}
		if(this.current_element == 1){
			this.prev_element = this.number_of_elements;
		}
		
		/*
		alert("b_" + this.prev_element);
		alert("b_" + this.current_element);		
		*/
		Effect.Fade("b_" + this.prev_element, { duration: 0.0 });
		Effect.Appear("b_" + this.current_element, { duration: 1.0 });
		this.current_element = this.current_element + 1;
	},
	slide: function(id)
	{
		clearInterval(this.timer);
		$$('li.slide-element').each(function(link){
			$(link).hide();
		})		
		//$("b_" + this.current_element).hide();
		//Effect.Fade("b_" + this.current_element, { duration: 0.0 });
		this.current_element = id;
		Effect.Appear("b_" + id, { duration: 1.0 });
	},
	next: function()
	{
		this.timer = setInterval(this.tick.bind(this), this.interval);
	}
}


var Newsticker = Class.create();
Newsticker.prototype = {
	initialize: function()
	{
		
		this.left = '750';
		
		//alert($('newsscroller').getWidth());
		
		this.interval = 100;
		this.scrollinterval = 100;
		this.pause = 1000;
		this.container = $("newsticker");
		this.content = '';
		this.messages  = new Array();
		messages  = $A(this.container.getElementsByTagName("li"));
		//alert(messages.length);
		for (var index = 0, len = messages.length; index < len; ++index) {
		  this.messages[index] = $('nro_' + index).innerHTML;
		}		

		this.scroller_width = $('scroller-content').getWidth(); //Get scroller width

		this.number_of_messages = this.messages.length;
		this.current_message = 0;
		this.current_char = 1;
		this.timer = setInterval(this.tick.bind(this), this.interval);
		$('scroller-content').style.left = '740px';
		this.timer = setInterval(this.scroll.bind(this), this.scrollinterval);	
		
  	},
	tick: function()
	{
		
		if(this.current_message > this.messages.length-1){
			this.current_message = 0;
		}
		$("newsticker").innerHTML = this.messages[this.current_message].substr(0, this.current_char);
  		if(this.current_char > this.messages[this.current_message].length){
  			this.current_char = 1;
  			this.current_message = this.current_message+1;
  			//setTimeout(this.tick.bind(this),this.pause);
  		}else{
			this.current_char = this.current_char + 1;
			//setTimeout(this.tick.bind(this),this.interval);
	  	}
	},
	scroll: function()
	{
		
		d = {};
		this.left = (this.left-10);
		d.left = this.left  + 'px'
		//$('scroller-content').setStyle(d);
		
		//$('newsticker').update($('scroller-content').style.left);
		
		$('scroller-content').style.left = (parseInt($('scroller-content').style.left) - 2) + 'px';
		
		
		if(1-this.scroller_width > this.left){
			this.left = 740;
		}
		
		
		//$('newsscroller').scrollTop=$('newsscroller').scrollTop+1
	},
	
	getNews: function(){
		
	}
}


var Scroller = Class.create();
Scroller.prototype = {
	initialize: function(left, interval, container, scroller_content)
	{
		this.left = left;
		this.interval = interval;
		this.pause = 1000;
		this.scroller_content = scroller_content;
		this.start_left = left;
		//this.container = $("newsticker");
		this.container = $(container);
		//this.scroller_width = $('scroller-content').getWidth(); //Get scroller width
		this.scroller_width = $(scroller_content).getWidth();
		//alert(this.scroller_width);
		$(scroller_content).style.left = left + 'px';
		this.timer = setInterval(this.scroll.bind(this), this.interval);	
  	},
	scroll: function()
	{
		this.left = (this.left-2);
		//$(this.scroller_content).style.left = (parseInt($(this.scroller_content).style.left) - 2) + 'px';
		$(this.scroller_content).style.left = parseInt(this.left) + 'px';
		if(1-this.scroller_width > this.left){
			this.left = this.start_left;
		}
	}
}

var ArticleOptions = Class.create();

ArticleOptions.prototype = {

	initialize: function()
	{

  	},
  	
  	zoom: function()
  	{
  		$('article_body').toggleClassName('zoom');
  	},
	
	email: function()
	{
			
	}
	
}

var Clock = Class.create();

Clock.prototype = {

	initialize: function()
	{
		this.adays = new Array('Duminica','Luni','Marti','Miercuri','Joi','Vineri','Sambata');
		this.amonths = new Array('','Ian','Feb','Mar','Apr','Mai','Iun','Iul','Aug','Sep','Oct','Noi','Dec');
		this.timer = setInterval(this.startclock.bind(this), 1000);
  	},
	
	startclock: function()
	{
		var thetime=new Date();

		var nhours=thetime.getHours();
		var nmins=thetime.getMinutes();
		var nsecn=thetime.getSeconds();
		var nday=thetime.getDay();
		var nmonth=thetime.getMonth();
		var ntoday=thetime.getDate();
		var nyear=thetime.getYear();
		var AorP=" ";
		
		if (nhours>=12)
			AorP = "PM";
		else
			AorP = "AM";
		
		if (nhours>=13)
			nhours-=12;
		
		if (nhours==0)
		   nhours=12;
		
		if (nsecn<10)
		 nsecn="0"+nsecn;
		
		if (nmins<10)
		 nmins="0"+nmins;
		/*
		if (nday==0)
		  nday="Duminica";
		if (nday==1)
		  nday="Luni";
		if (nday==2)
		  nday="Marti";
		if (nday==3)
		  nday="Miercuri";
		if (nday==4)
		  nday="Joi";
		if (nday==5)
		  nday="Vineri";
		if (nday==6)
		  nday="Sambata";
		*/
		
		nmonth+=1;
		
		if (nyear<=99)
		  nyear= "19"+nyear;
		
		if ((nyear>99) && (nyear<2000))
		 nyear+=1900;
		
		$('clock').update(this.adays[nday] + ", " + ntoday + " " + this.amonths[nmonth] + " "  + nyear + " " + nhours + ":" + nmins + ":" + nsecn + " " + AorP);
		
		//setTimeout('startclock()',1000);		
	}

}

var VideoPlayer = Class.create();

VideoPlayer.prototype = {

	initialize: function(sid)
	{
		this.section = sid;
		
		this.refresh();
	},
	
	change_section: function(sid)
	{
		this.section = sid;
		this.refresh();
	},
	
	refresh: function()
	{
		new Ajax.Updater(
			"AjaxList", 
			"/videos/ajax_video_list/" + this.section, 
			{
				onCreate:function(){
					//alert('1 ' + this.section);
					$('AjaxList').update('<div style="text-align:center"><img src="/img/loading.gif"></div>');
				},				
				onComplete:function(){ 
					//alert('2' + this.section);
					//new Effect.Highlight('AjaxList');
				},
				asynchronous:true, 
				evalScripts:true
			}
		);
		
	},
	
	play: function(video)
	{
		//alert(video);
		$('VideoPlayer').update('<!--[if !IE]> --><object type="application/x-shockwave-flash" data="' + video + '" width="215" height="200"><!-- <![endif]--><!--[if IE]><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="215" height="200"><param name="movie" value="' + video + '" /><!--><!----><param name="loop" value="true" /><param name="bgcolor" value="#FFFFFF" /><param name="menu" value="false" /><p><a href="http://www.adobe.com" onclick="javascript:window.open(this.href,\'_blank\');return false;"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash Player" /></a> in order to see the animation.</p></object>');
		/*		
		new Ajax.Updater(
			"VideoPlayer", 
			"/videos/ajax_video_play/" + video, 
			{
				onComplete:function(){ 
					new Effect.Highlight('VideoPlayer');
				},
				asynchronous:true, 
				evalScripts:true
			}
		);	
		*/	
	}
	
}

var Photos = Class.create();

Photos.prototype = {

	initialize: function(sid)
	{
           new Control.Modal(
				$('lightbox_link_one'),
				{
					ajax:true,
					requestOptions:{evalScripts:true},
					opacity: 0.7,
					width: 640, 
					height: 500
				}
			);
		   
		   $$('a.thumbs').each(function(link){
			   new Control.Modal(link,
						{
							ajax:true,
							requestOptions:{evalScripts:true},
							opacity: 0.7,
							width: 640, 
							height: 500
						}	   		
			   );
		   });		   
		   
	},
	
	zoom: function(id)
	{
		$$('div.photo').each(function(link){
			$(link).hide();
		});
		Effect.Appear("photo_" + id, { duration: 0.5 });
		//$('photo_' + i).show();
	}
}

// Effect.Tooltip 
// Nick Stakenburg
// Usage: 
// new Effect.Tooltip(element, content, {title : 'title', className: 'class', offset: {x:0, y:0}});

Effect.Tooltip = Class.create();
Object.extend(Object.extend(Effect.Tooltip.prototype, Effect.Base.prototype), {
  initialize: function(element, content) {
    this.element = $(element);
    if(!this.element) throw(Effect._elementDoesNotExistError);
    var options = Object.extend({
      content: content,
      title: false,
      className: 'tooltip',
      offset: {'x':16, 'y':16}
    }, arguments[2] || {});
    this.start(options);
  },
  setup: function() {
    // create a wrapper
    this.wrapper = document.createElement('div');
    this.wrapper.className = this.options.className;
    Element.setStyle(this.wrapper, {
      position: 'absolute',
      display: 'none'
    });
    // add the title
    if(this.options.title) {
      var title = document.createElement('div');
      title.className = 'title';
      Element.update(title, this.options.title);
      this.wrapper.appendChild(title);
    }
    // create the actual tooltip
    this.tip = document.createElement('div');
    this.tip.className = 'content';
    Element.update(this.tip, this.options.content);
    this.wrapper.appendChild(this.tip);

    // add wrapper to the body
    document.body.appendChild(this.wrapper);

    // add observers
    this.element.observe('mousemove', this.showTip.bind(this));
    this.element.observe('mouseout', this.hideTip.bind(this));
  },
  showTip: function(event){
    this.positionTip(event);
    this.wrapper.show();
  },
  hideTip: function(){
    this.wrapper.hide();
  },
  positionTip: function(event){
    var offsets = {'x': this.options.offset['x'],'y': this.options.offset['y']};
    var mouse = {'x': Event.pointerX(event), 'y': Event.pointerY(event)};
    var page = {'x':this.viewportSize()['x'], 'y':this.viewportSize()['y']};
    var tip = {'x': mouse['x'] + this.options.offset['x'] + this.wrapper.getWidth(),
    'y' : mouse['y'] + this.options.offset['y'] + this.wrapper.getHeight()};

    // inverse x or y to keep tooltip within viewport
    if(tip['x']>page['x']) { offsets['x'] = 0-(this.wrapper.getWidth() + this.options.offset['x']); }
    if(tip['y']>page['y']) { offsets['y'] = 0-(this.wrapper.getHeight() + this.options.offset['y']); }

    this.wrapper.setStyle({
      left: mouse['x'] + offsets['x'] + 'px',
      top: mouse['y'] + offsets['y'] + 'px'
    });
  },
  viewportSize : function(){
    if (self.innerHeight) return {'x': self.innerWidth, 'y': self.innerHeight};
    else if (document.documentElement && document.documentElement.clientHeight)
    return {'x': document.documentElement.clientWidth, 'y': document.documentElement.clientHeight};
    else if (document.body) return {'x': document.body.clientWidth, 'y': document.body.clientHeight};
  }
});

// lang javascript
Ajax.Responders.register({
	onCreate: function() {
		if($('busy') && Ajax.activeRequestCount>0)
		//Effect.Appear('busy',{duration:0.5,queue:'end'});
		$('busy').show();
	},
	onComplete: function() { 
		if($('busy') && Ajax.activeRequestCount==0) 
		//Effect.Fade('busy',{duration:0.5,queue:'end'});
		$('busy').hide();
	}
});

//functia de abonare la mex si bst
function abonare() { 
    window.open("http://www.moneyline.ro/ofertaspeciala/","abonare","width=500px,height=570px");
}

// abonare mex
function abonareMEX() { 
    window.open("/abonare.php","abonare","width=500px,height=560px");
}


function abonareSpeciala() {
	window.open("http://www.standard.ro/ofertaspeciala","abonare","width=660px,height=670px");
}