var Envy = {

	bagHovered : false,

	bagHoverId : 0,

	current_img_id : 1,

	showSlides : function(url) {

		window.open(url, '123', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=775,height=620,left = 137,top = 80');

	},


	isValidEmail : function(str) {

		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
 
	},

	doRegistration : function(email) {

		if (this.isValidEmail(email))	{

			document.location = '/inregistrare/'+email;

			return false;
		}

		else {

			alert('Adresa de email nu este valida!');

		}

		return false;

	},
	
	showImg : function(id) {

		var sImg = 'sImg' + id;

		var current_img = 'sImg' + this.current_img_id;

		current_img_id = id;

		var cimg = document.getElementById(current_img);

		cimg.style.display = "none";

		var cimg = document.getElementById(sImg);

		cimg.style.display = "block";
			
		$('#'+sImg).fadeIn('medium');
		
		this.current_img_id = id;

	},

	Scroller : {
	
		moving : true,

		currentScroll : 0,

		increment : 1,		
	
		speed : 50,
			
		direction : "left",

		scroll: function() {

			if( this.moving == 1 ) {

				var beforeScroll = this.scroller.scrollLeft;

				if (this.direction == "right"){

					this.scroller.scrollLeft -= this.increment;

					var afterScroll = this.scroller.scrollLeft;

					newvalue = this.scroller.scrollLeft/(this.scroller.scrollWidth-this.scroller.clientWidth);

					if (this.currentScroll != newvalue) {

						this.currentScroll = newvalue;

					}

					if(this.scroller.scrollLeft == 0 ) {

						this.direction="left";

					}
				}

				else {

					var beforeScroll = this.scroller.scrollLeft;

					this.scroller.scrollLeft += this.increment;

					var afterScroll = this.scroller.scrollLeft;

					newvalue = this.scroller.scrollLeft/(this.scroller.scrollWidth-this.scroller.clientWidth);

					if (this.currentScroll!= newvalue) {

						this.currentScroll = newvalue;

					}

					if( beforeScroll == afterScroll ) {

						this.direction="right";

					}
				}
			}
		},

		start : function() {

			this.moving = 1;

		},

		stop : function() {

			this.moving = 0;

		},

		init : function(scrollerId) {

			this.scroller = document.getElementById(scrollerId);	
			
			if ((this.scroller == undefined)) {

				return false;
			}

			else {return true}

		}

	},

	vote : function(id,rank) {	
		
		$('.vb').unbind('mouseover');

		$('.vb').unbind('mouseout');
			
		$('a.vb').attr('href','javascript:;');
 
		$.get("/vote/"+id+'/'+rank, function(data){

			var v = eval(data);

			document.getElementById('nrVotes').innerHTML = v.votes + ' voturi';
			
		if ( $.browser.msie) {
			document.getElementById('voteMsg').innerHTML = '<b>Va multumim pentru vot!</b>';
		}
		else {
			$('#voteMsg').fadeOut('medium', function() {

				document.getElementById('voteMsg').innerHTML = '<b>Va multumim pentru vot!</b>';

				$('#voteMsg').fadeIn('medium');

			});
		}	
			
		});
	},

	hoverBag : function(idx) {

		idx = Number(idx.substr(7,idx.length));
		
		for (i=1; i<=idx; i++ ) {

			id = '#votebag'+i;

			$(id).removeClass('votebag');
	
			$(id).addClass('votebag_hover');
			
		}

		this.bagHoverId = idx;

	},

	unhoverBag : function(idx) {
					
		idx = Number(idx.substr(7,idx.length));
		
		if (this.bagHoverId == idx) {

			for (i=1; i<=idx; i++ ) {

				id = '#votebag'+i;

				$(id).removeClass('votebag_hover');

				$(id).addClass('votebag');

			}

		}

		if (this.bagHoverId<idx)	{
					
			for (i=this.bagHoverId+1; i<=idx; i++ ) {

				id = '#votebag'+i;

				$(id).removeClass('votebag_hover');

				$(id).addClass('votebag');

			}
					
			this.bagHoverId = 0;

		}
	},

	reportComment : function(id) {
		
		$.get("/reportComment/"+id, function(){

			document.getElementById('comment'+id).innerHTML = '<b>Comentariul a fost raportat cu succes!</b>';

		});
		
	}

}
var tab_switch_interval = null;

window.onload = function() { 
	$('.votebag').mouseover( function() {
		Envy.hoverBag(this.id);		
	});

	$('.votebag').mouseout( function() {
		setTimeout("Envy.unhoverBag('"+this.id+"')",400);		
	});
		
	if (Envy.Scroller.init('scroller_container')) {
		setInterval("Envy.Scroller.scroll();", Envy.Scroller.speed);
	}
	
	tab_switch_interval = setTimeout('switch_hp_tab(0)', 2000);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function open_slide_window(url) {
	window.open(url, '123', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=775,height=620,left = 137,top = 80');	
}
function slideShowNews(url) {
    window.open(url, '123', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=775,height=700,left = 137,top = 80');    
}    

function switch_hp_tab(tabid, mode) {
	var tabcount = $('#hp_tabs a').size();
	if(mode=='auto') {
		tab_switch_interval = setTimeout('switch_hp_tab(0)',2000);
	} else {
		clearTimeout(tab_switch_interval);
	}
	if(tabid) {
		if(jQuery) {			
			for(i=1;i<=tabcount;i++)  {				
				$('#tab_content'+i).hide();		
				$('#tab'+i).attr('className', 'hp_tab');
			}
				
			$('#tab_content'+tabid).fadeIn();
			$('#tab'+tabid).attr('className', 'hp_current_tab');
		}
	} else {
		tabindex = 0;
		try { 
				$('#hp_tabs a').each(function(tid){
					if($(this).attr('className') == 'hp_current_tab') {
						if(tid+2>tabcount)
							tid = -1;
						switch_hp_tab(tid+2,'auto');
						throw true;
					}
				});
			}			
		catch(e) {}
		
		
	}
}