$(document).ready(function(){
	
	//Sidebar Accordion Menu:
		
		$(".main-nav li .ul-content").hide(); // Hide all sub menus
		$(".main-nav li a.current").parent().find(".ul-content").slideToggle("slow"); // Slide down the current menu item's sub menu
		
		$(".main-nav li a.nav-top-item").click( // When a top menu item is clicked...
			function () {
				$(this).parent().parent().find("a").removeClass('current'); // Remove "active" class from all tabs
				$(this).addClass('current'); // Add class "active" to clicked tab
				
				$(this).parent().siblings().find(".ul-content").slideUp("slow"); // Slide up all sub menus except the one clicked
				$(this).next().slideToggle("fast"); // Slide down the clicked sub menu
				return false;
			}
		);
		
		$(".main-nav li a.no-submenu").click( // When a menu item with no sub menu is clicked...
			function () {
				window.location.href=(this.href); // Just open the link instead of a sub menu
				return false;
			}
		); 
		
		
	//tabs
	$('.tab-title h4').click(
		function() {
			$(this).parent().find("h4").removeClass('active'); // Remove "active" class from all tabs
			
			$(this).addClass('active'); // Add class "active" to clicked tab	
				
			var title =	$(this).attr("title");
			
			$(this).parent().parent().find(".tabCont").addClass('noDisplay'); // Remove "active" class from all tabs
			$('#'+title).removeClass('noDisplay');
		}
	);

	
	//alternate rows in add result tabel
	$('#meciuriPending tbody tr:even').addClass("alt-row"); // Add class "alt-row" to even table rows
	
	//adauga rezultat
	$('#meciuriPending form').ajaxForm(function(data) { 
				
				
        data = data.split("_");
				
		$('#notificationContent').html ( data[0] )
		$('#notificationHolder').removeClass();
		$('#notificationHolder').addClass( 'notification png_bg '+data[1] );
		
  		if ( data[1] == 'success' )
		{
		
			idMeci = data[2];
			$('#meci'+idMeci).slideUp();
  			$('#meciuriPending form')[0].reset();
		}
    });
	

	
	//home slider
	$("#slider").easySlider({
		auto: true,
		continuous: true,
		numeric: true,
		speed: 600,
		pause: 6000
	});
	
	//text area limitation
	 $('.txtDescr, .txtKeyW').keyup(function()
		{
	        var max = parseInt( $(this).attr('maxlength') );
	        if($(this).val().length > max){
	            $(this).val($(this).val().substr(0, $(this).attr('maxlength')));
	        }
	 
	        $(this).parent().find('.charsRemaining').html('You have ' + (max - $(this).val().length) + ' characters remaining');
	    });
	
	//form focus effect
	$('#fSubmitSite textarea, #fSubmitSite input, #fSubmitSite select').focus(
		function() {
			$(this).parent().parent().find("input").removeClass('focus'); // Remove "focus" class from all inputs
			$(this).parent().parent().find("textarea").removeClass('focus'); // Remove "focus" class from all textareas
			$(this).parent().parent().find("select").removeClass('focus'); // Remove "focus" class from all selects
			
			$(this).addClass('focus');
		}
	);
	
						   
	 // FORM SUBMIT
	$('#writeComment').ajaxForm(function(data) { 
				
				
        data = data.split("_");
				
		$('#notificationContent').html ( data[0] )
		$('#notificationHolder').removeClass();
		$('#notificationHolder').fadeTo(400,100);
		$('#notificationHolder').slideDown(400);
		$('#notificationHolder').addClass( 'notification png_bg '+data[1] );
  		if ( data[1] == 'success' )
		{
  			$('#writeComment')[0].reset();
		}
    });
	
	 //Close button:
		
		$(".close").click(
			function () {
				$(this).parent().fadeTo(400, 0, function () { // Links with the class "close" will close parent
					$(this).slideUp(400);
				});
				return false;
			}
		);
		
		
	//asian handicap calculator
	

	$('#asianCalculator').ajaxForm(function(data) { 
		
		data = data.split("_");
		
		$('#handicap').html ( '<strong>Your bet was: ' + $('#selBet').val() + ' @ ' + $('#selOdds').val() + ', ' + $('#inpStake').val() + ' units , handicap ' + $('#selHan').val() + '</strong>' );
		
		$('#result').html ( 'Result of the game: ' + $('#selRes').val() );
		
		$('#return').html ( 'Return: '+data[0] );
		
		if ( data[1] >= 0 )
		{
			$('#profit').html ( 'Profit: <strong class="green">+'+data[1]+'</strong>' );
		}
		else
		{
			$('#profit').html ( 'Profit: <strong class="red">'+data[1]+'</strong>' );
		}
		
		$('#resultsHolder').removeClass();
		
		$('#asianCalculator')[0].reset();
		
		
	});
		
	//sure bets calculator
	

	$('#sureBetsCalculator form').ajaxForm(function(data) { 
		
		data = data.split("_");
				
		$('#result'+data[2]).html ( data[0] + "%" );
		
		//filling in the stakes and winnings
		stakes = data[1].split("~");
		odds = data[3].split("~");
		
		var i=0;
		for ( i=0; i<=2; i++)
		{
			$('#stake'+data[2]+i).val ( stakes[i] );
			
			var num = stakes[i] * odds[i];
			var winnings = num.toFixed(2); 
			$('#winnings'+data[2]+i).val ( winnings );
		}
		
		
		//green or red
		if ( data[0] >= 100 )
		{
			$('#result'+data[2]).html ( '<strong class="green">Profit: '+ data[0] + '% ('+data[4]+')</strong>' );
		}
		else
		{
			$('#result'+data[2]).html ( '<strong class="red">Profit: '+ data[0] + '% ('+data[4]+')</strong>' );
		}
		
		//$('#sureBetsCalculator form')[0].reset();
			
	//odds conversion
	function fraction ( num )
	{
		if ( num < 1 && num > 0 )
		{
			var num = num.split(".");
			var numarator = num[1];
			
			return numarator;
		}
	}
	
	 $('#oddsConversion .text-input').change(function()
		{
			if ( $(this).attr('id')=='decimal' )
			{
				if ( $(this).val() < 2 && $(this).val()>1 )
				{
					var american = -100/($(this).val()-1);
					american = american.toFixed(2); // result will equal 10.00
					$('#american').val(american);
					
					var test = $(this).val()-1;
					fractional = fractional.fraction(test);
					$('#fractional').val(fractional);
				}
				if ( $(this).val() >= 2 )
				{
					var american = 100*($(this).val()-1);
					american = american.toFixed(2); // result will equal 10.00
					$('#american').val("+"+american);
					
					var fractional = $(this).val()-1;
					fractional = fraction(fractional);
					$('#fractional').val(fractional);
				}
			}
		});
		
	});
	
});