$(document).ready(function(){
	
	
	/*var ie6=($.browser.msie && $.browser.version=='6.0')?true:false;
	if(ie6){
		location.href='ie6.html';
	}*/
	
	
	$("#join-btn").click(function(){
		$("#login-big").animate({
			"left":"0px"
		});
		
		$("#login").animate({
			"height":"190px"
		});
	});
	
	$("#login-btn").click(function(){
		$("#login-big").animate({
			"left":"-614px"
		});
	});
	
	$("#forgot").click(function(){
		$("#login-big").animate({
			"top":"-142px"
		});
                $("label.error").remove();
                $("input").removeClass("error");
	});
	
	$("#login-intra .login-back").click(function(){
		$("#login-big").animate({
			"left":"-307px"
		});
		
		$("#login").animate({
			"height":"140px"
		});
                $("label.error").remove();
                $("input").removeClass("error");
	});
	
	$("#login-login .login-back").click(function(){
		$("#login-big").animate({
			"left":"-307px"
		});
                $("label.error").remove();
                $("input").removeClass("error");
	});
	
	$("#login-trimite .login-back").click(function(){
		$("#login-big").animate({
			"top":"0px"
		});
                $("label.error").remove();
                $("input").removeClass("error");
	});	

	
	//Go Top button
	$('#go').click(function(){
		$.scrollTo('#logo', { 
		   duration:600, 
		   axis: 'y'
		}); 
	});
	
	
	//Main Menu
	$("#main-nav a").hover(function(){
			$(this).stop().animate({
				'color':'#FF8910'
			}, 200)},
			function(){
				if ($(this).attr("class")!="active"){
					$(this).stop().animate({
						'color':'#fff'
					}, 50)
				}
			}
		
	);
	
	
	//Chat
	$(function() {
		$('a#chat').click(function() {
			var href = $(this).attr('href');
			window.open(href, 'popup', 'height=400,width=500,toolbar=no');
			return false;
			})
	});
	
	
	//background wallpaper
	var h = $(document).height();
	$("#wallpapers").css({
		height: h
	});
	




// index Stiri
$('#stiri').append('<ul>');
$('#stiri div').cycle({ 
    fx:      'fade', 
    speed:    1000, 
    timeout:  3000,
		pause: 		true,
		pauseOnPagerHover: true,
	pager: "#stiri ul",
	pagerAnchorBuilder: function(idx, slide) {
		return '<li><a>' + $(slide).attr('title') +  '</a></li>';
    },
	before: function(idx, slide){
		$("#stiri #stiri-info span").html($(slide).attr("name"));
		u=$(slide).attr("href");
		$("#stiri #stiri-info a").attr("href",u);
	}
});

//index Video
$("#video .thumb a").hover(
	function () {
		$("span", this).stop().animate({opacity: 0}, {queue: false, duration: 300});
	},
	function () {
		$("span", this).stop().animate({opacity: 1}, {queue: false, duration: 200});
	}
)

//index GalerieFoto
/*$('#galerieFoto div').cycle({ 
    fx:      'scrollLeft', 
    speed:    1000, 
    timeout:  3000,
	pager: "#galerieFoto p span",
	pagerAnchorBuilder: function(idx, slide) {
		return '<a></a>';
    },
	after: function(idx, slide){
		$("#galerieFoto p a").html($(slide).attr("title"));
		u=$(slide).attr("href");
		$("#galerieFoto p a").attr("href",u);
	}
});*/


//top40
$('.top40 li').hover(
	function(){
		$("a", this).css({'color': '#fff'});
		$(this).css({
			"background-color": "#111"
		});
	},
	function () {
		$("a", this).css({'color': '#5F5F5F'});
		if ($(this).attr("class").split(' ', 1)=='a') {
			$(this).css({
				"background-color": "#ededed"
			});
		}
		else {
			$(this).css({
				"background-color": "#fff"
			});
		}
	}

);

// add fancybox on all elements with .img class
$(".img").fancybox();


// get track (finally!)

getTrack();
setInterval(getTrack,10000);

function getTrack(){

	$.post("track.php",{} ,function(data){
		if(data){
			$("#asculta_live #live").fadeIn();
			$("#asculta_live #live").html(data);	
		}else{
			$("#asculta_live #live").fadeOut();
		}
	});
}

	


// login
	$("#login_form").submit(function()
	{
		var thusr=$('#luser').val();
		$("#msgbox").removeClass().addClass('messagebox').text('Validating....').fadeIn(1000);
		//check the username exists or not from ajax
			$.post("ajax-login.php",{ user_name:$('#luser').val(),password:$('#lpass').val(),rand:Math.random() } ,function(data)
			{
			  if(data=='yes') //if correct login detail
			  {
				  	$("#login_form input").removeClass('error');
						$("#login_form label.error").remove();
					
					$("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
					{
					  //add message and change the class of the box and start fading
					  $(this).html('Logging in.....').addClass('messageboxok').fadeTo(900,1,
					  function()
					  {
						 //redirect to secure page
						 location.reload(true);
						 $('#login-big').fadeOut();
						 setTimeout(function(){$('#login-big').remove()},500);
						 //$('#sal').html('<p>Bine ai revenit, '+thusr+'.</p>');
						 //$('#sal').fadeIn();
					  });
					});
			  }
			  else
			  {
					
					$("#login_form input").addClass('error');
					$("#login_form p").append('<label class="error">"nume utilizator" sau "parola" incorecte</label>');
					
					$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
					{
					  //add message and change the class of the box and start fading
					  $(this).html('Your login detail sucks...').addClass('messageboxerror').fadeTo(900,1);
					});
			  }
		   });
		   return false;//not to post the  form physically
	});




// register
	$("#join_form").submit(function()
	{
		/* coduri de eroare
		1 - user exista deja
		2 - user e <4
		3 - mail nu e ok
		4 - parola e <5
		5 - parola e diferita de confirmare
		6 - confirmarea parolei e vida
		*/
		
		//check the username exists or not from ajax
			$.post("ajax-signup.php",{ user_name:$('#user').val(),mail:$('#mail').val(),password:$('#pass').val(),retypepass:$('#retypepass').val(),rand:Math.random() } ,function(html)
			{
   			  if(html){
				  html="0,"+html;
				  //alert(html);
				  $("#join_form p input").removeClass('error');
					$("#join_form p label.error").remove();
					
					if(html.search("1")>0){
						$("#join_form p:nth-child(1) input").addClass("error");
						$("#join_form p:nth-child(1)").append('<label class="error">nume utilizator existent!</label>');
					} else{
						$("#join_form p:nth-child(1) input").removeClass("error");
						$("#join_form p:nth-child(1) label.error").remove();
					}
					if(!(html.search("1")>0)){
						if(html.search("2")>0){
							$("#join_form p:nth-child(1) input").addClass("error");
							$("#join_form p:nth-child(1)").append('<label class="error">minim 4 caractere</label>');
						} else{
							$("#join_form p:nth-child(1) input").removeClass("error");
							$("#join_form p:nth-child(1) label.error").remove();
						}
					}
					if(html.search("3")>0){
						$("#join_form p:nth-child(2) input").addClass("error");
						$("#join_form p:nth-child(2)").append('<label class="error">introduceti un email valid!</label>');
					} else{
						$("#join_form p:nth-child(2) input").removeClass("error");
						$("#join_form p:nth-child(2) label.error").remove();
					}
					if(html.search("4")>0){
						$("#join_form p:nth-child(3) input").addClass("error");
						$("#join_form p:nth-child(3)").append('<label class="error">minim 5 caractere</label>');
					} else{
						$("#join_form p:nth-child(3) input").removeClass("error");
						$("#join_form p:nth-child(3) label.error").remove();
					}
					if(!(html.search("6")>0)){
						if(html.search("5")>0){
							$("#join_form p:nth-child(4) input").addClass("error");
							$("#join_form p:nth-child(4)").append('<label class="error">reintroduceti parola</label>');
						} else{
							$("#join_form p:nth-child(4) input").removeClass("error");
							$("#join_form p:nth-child(4) label.error").remove();
						}
					}
					if(html.search("6")>0){
						$("#join_form p:nth-child(4) input").addClass("error");
						$("#join_form p:nth-child(4)").append('<label class="error">nu ati reintrodus parola</label>');
					} else{
						$("#join_form p:nth-child(4) input").removeClass("error");
						$("#join_form p:nth-child(4) label.error").remove();
					}
			  }else{
				  $("#join_form p input").removeClass("error");
					$("#join_form p label.error").remove();
				  location.reload(true);
				  $('#login-big').fadeOut();
				  setTimeout(function(){$('#login-big').remove()},500);
			  }

		   });
		   return false;//not to post the  form physically
	});




// register
	$("#forgot_form").submit(function()
	{
		
		//check the username exists or not from ajax
			$.post("ajax-forgot.php",{ mail:$('#mailf').val(),rand:Math.random() } ,function(html)
			{
   			  if(html){
				  $("#forgot_form p input").removeClass('error');
					$("#forgot_form p:nth-child(1) input").addClass("error");
					$("#forgot_form p:nth-child(1)").append('<label class="error">email inexistent!</label>');
					alert('eroare');
			  }else{
				  $("#forgot_form p input").removeClass("error");
					$("#forgot_form p label.error").remove();
				  //$('#login-big').fadeOut();
				  alert('email trimis');
				  
				  $("#login-trimite").html('<p id="msg">Email-ul cu noua parola a fost trimis. Te rugram verifica si in folder-ul "Junk" sau "Spam". Cand ai parola noua, click aici sa te loghezi.</p>');
				  
				  				  
				  
				  
				  function goToLogin(){
					  $("#login-trimite .login-back").click(function(){
						$("#login-big").animate({
							"top":"0px"
						});
					  });
				  }
				  
				  
			  }

		   });
		   return false;//not to post the  form physically
	});


/*contact button */
var contactPoz = ($(window).height()/2);
$(".btnContact").css({"top":""+contactPoz+"px","display":"block"});
$(".btnContact").animate({"left":0},500);

});



	
	