var is_chrome = /chrome/.test(navigator.userAgent.toLowerCase());
$(document).ready(function(){
	menuDrop();
	searchDomeniu();
	solicita();
	clientsSlider();
	correctCss();
	/*Inregistrare domenii*/
	sidebarHover();
	customCheckBox();
	hoverTable();
	/* Gazduire */
	gazduireMore();
	changeOs();
	open_blank();
	
	if($('#loopedSlider').length != 0){
		$('#loopedSlider').loopedSlider();
	}
	
	/*Blog signle*/
	blogComments();
	serverStuff();
	
	if($('#hostingPlanPicker').length > 0){
		new Dragdealer('hostingPlanPicker', {
			steps:10,
			animationCallback:function(x,y){
				var vline = $('#hostingPlansPrices .vLine');
				$('#hostingPlanPicker .greenBar').width($('#hostingPlanPicker').width()*x);
					if(x<1){
						var i = Math.floor((x-1)* 10);
						vline.removeClass('hidden');
						vline.eq(i).addClass('hidden');
						$('div.hostingPlanDetaills div.details').eq(i).show().siblings().hide();
						$('#servers .checkout span').eq(i).css('display','block').siblings().hide();
					}
			}
		});
	}
$('.goUp').unbind().click(function(){
    $('html, body').animate({scrollTop:0}, 'slow');
    return false;
});
	//$('html').css('height','939px');
	inTouch();
});

function menuDrop()
{
	$('#menu li').unbind().filter(function(){ return $(this).find('ul').length }).addClass('drop-down').bind('mouseenter mouseleave', function(e){
		
		
		var t = $(this);
		var sub = t.find('ul');
		/*Remove Url*/
		t.find('> a').attr('href','#').click(function(){ return false; });
	if(e.type==='mouseenter'){
		sub.stop(true, true).show();
	}else {
		sub.stop(true, true).hide();
	}
});
	$('#menu > li.drop-down').hover(function(){
		$(this).addClass('drop-down-hover');
	}, function(){
		$(this).removeClass('drop-down-hover');	
	});

}

function searchDomeniu(){
	eL = $('div#offer > ul > li.second form label input');
	eL.focus(function(){ 
		$(this).parent().addClass('search-focused');
		if($(this).val() == 'Cauta domeniu (ex: domeniulmeu.com)')
		{
			$(this).val('');
		}
	});
	
	eL.blur(function(){
		$(this).parent().removeClass('search-focused');
		if($(this).val() == '')
		{
			$(this).val('Cauta domeniu (ex: domeniulmeu.com)');
		}
	});
	
	//Newsletter
	eL2 = $('div#newsletter div:first-child + div form label input');
	eL2.focus(function(){ 
		$(this).parent().addClass('search-focused');
		if($(this).val() == 'Introdu adresa e-mail')
		{
			$(this).val('');
		}
	});
	
	eL2.blur(function(){
		$(this).parent().removeClass('search-focused');
		if($(this).val() == '')
		{
			$(this).val('Introdu adresa e-mail');
		}
	});
	
	//Inregistrare domenii
	eL3 = $('.domains-wrapper .content .check form span.the-input input');
	eL3.focus(function(){ 
		if($(this).val() == 'Introdu domeniu')
		{
			$(this).val('');
		}
	});
	
	eL3.blur(function(){
		if($(this).val() == '')
		{
			$(this).val('Introdu domeniu');
		}
	});
	
	
	//suport
	eL4 = $('input.user-sup');
	eL4.focus(function(){ 
		if($(this).val() == 'E-mail')
		{
			$(this).val('');
		}
	});
	
	eL4.blur(function(){
		if($(this).val() == '')
		{
			$(this).val('E-mail');
		}
	});	

	eL5 = $('input.pass-sup');
	eL5.focus(function(){ 
		if($(this).val() == 'Parola')
		{
			$(this).val('');
		}
	});
	
	eL5.blur(function(){
		if($(this).val() == '')
		{
			$(this).val('Parola');
		}
	});	
	
	/*Search box*/
	eL6 = $('.search input');
	eL6.focus(function(){ 
		theVal = $(this).val();
		if($(this).val() == theVal)
		{
			$(this).val('');
		}
	});
	
	eL6.blur(function(){
		if($(this).val() == '')
		{
			$(this).val(theVal);
		}
	});
	
	//Index search domeniu
	eL7 = $('.checkIndex input');
	eL7.focus(function(){ 
		theVal = $(this).val();
		if($(this).val() == theVal)
		{
			$(this).val('');
		}
	});
	
	eL7.blur(function(){
		if($(this).val() == '')
		{
			$(this).val(theVal);
		}
	});
	
}

/* Index */
function solicita()
{
	$('#solicita a').hover(function(){
		if($(this).parent().hasClass('solicita-active'))
		{
			$(this).parent().removeClass('solicita-active');
			$(this).parent().addClass('solicita-hover');
		}else{
			$(this).parent().addClass('solicita-hover');
		}
		
	},function(){
		$(this).parent().removeClass('solicita-hover');
	});
	
	$('#solicita a').mousedown(function() {
		if($(this).parent().hasClass('solicita-hover'))
		{
			$(this).parent().removeClass('solicita-hover');
			$(this).parent().addClass('solicita-active');
		}
	}).mouseleave(function() {
 		$(this).parent().removeClass('solicita-active');
	});
}

/* Footer index */
function clientsSlider()
{
	$('#newsletter  div:first-child + div + div > div.holder ul li:nth-child(2n+2)').addClass('no-border');


    $('#newsletter div.controls a.up').unbind().click(function() {
    	if($('#newsletter .holder ul').is(':animated')) {
    		return false;
    	}
    	
    	if(parseInt($('.holder ul').css('top'))<0){
    		$('.holder ul').animate({top:'+=25'});
		}
    	return false;
    });


	
    $('#newsletter div.controls').delegate('a.down','click',function() {
    	if($('#newsletter .holder ul').is(':animated')) {
    		return false;
    	}
    	
    	  	var t=$(this),
  			topPos = parseInt($('#newsletter .holder ul').css('top'), 10) || 0,
  			totalEl = $('#newsletter .holder ul li').length,
  			elHeight = $('#newsletter .holder ul li:first-child').innerHeight(),
  			maxH = totalEl * elHeight - elHeight - 25;
    	
    	
    	//if((-( (parseInt($('.holder ul').css('top'))/50)-1) )<(Math.ceil($('.holder li').length/2))){
    	
    	if((-topPos < maxH)){
    		$('.holder ul').animate({top:'-=25'});	
		}
		
    	return false;
    });

}

function correctCss()
{
	if(is_chrome){
		$('div#newsletter div:first-child + div button, div#offer > ul > li.second form button').css('padding-top','3px');
		$('#blog .search form button').css('margin-left','-28px');
	
	$('.category-certificate-ssl .packages-information ul li.promoted fieldset').css('padding-bottom','10px');		
		
	}
	
	if($.browser.msie)
	{
		$('.packages-information ul li').append('<i class="ie-after-hack"/>');
	}
	
	$('.wp-pagenavi a.page:nth-child(7n+1)').css('border-right','none');
	
	$('#newsletter div:first-child ul li:last-child a').css('border-bottom', 'none');
	$('#hostingPlansPrices li:last-child').addClass('last');
	$('#footer > ul > li:last-child').css('magrin-right', '0px');

}


/* Inregistrare domenii*/
function sidebarHover(){
	$('.links .repeat ul li:last-child, .links .repeat dl dd:last-child').css('border-bottom','none');
	$('.links .repeat ul li:not(.links .repeat ul li.current_page_item, .links .repeat ul li.me-inreg):not(.links .repeat ul li.head)').hover(function(){
		$(this).addClass('hover');
	},function(){
		$(this).removeClass('hover');
	});
	
	//search input
	
	$('.domains-wrapper .content .check form span.the-input input').focus(function(){
		$(this).parent().addClass('focused');
	});
	
		$('.domains-wrapper .content .check form span.the-input input').blur(function(){
			$(this).parent().removeClass('focused');
		});
	
}

function customCheckBox()
{
	$('.custom-checkbox li').find('input:radio').hide().wrap('<span />');
	
	$('.custom-checkbox li span, .bg-check').live('click', function(){
	
 		$(this).closest('.custom-checkbox').find('span').each(function(){
    		$(this).removeClass('checked').find('input:radio').attr('checked',false);
 		 });
 		 
 		 $(this).addClass('checked').find('input:radio').attr('checked',true);
  return false;
  
	});
	
}

function hoverTable()
{
	$('.prices table tr').hover(function(){
		$(this).find('td').css('background-color','#f1f1f1');
	}, function(){
		$(this).find('td').css('background-color','#fff');
	});
	
	$('.to-expand table tr').hover(function(){
		$(this).find('td').css('background-color','#f1f1f1');
	}, function(){
		$(this).find('td').css('background-color','#fff');
	});
	
	$('.to-expand table tr').find('td:first,th:first').css('padding-left','30px');
	
}

/* Gazduire */
function gazduireMore()
{
	$('#show-me a').hover(function(){
		if($(this).parent().hasClass('more-active'))
		{
			$(this).parent().removeClass('more-active');
			$(this).parent().addClass('more-hover');
		}else{
			$(this).parent().addClass('more-hover');
		}
		
	},function(){
		$(this).parent().removeClass('more-hover');
	});
	
	$('#show-me a').mousedown(function() {
		if($(this).parent().hasClass('more-hover'))
		{
			$(this).parent().removeClass('more-hover');
			$(this).parent().addClass('more-active');
		}
	}).mouseleave(function() {
 		$(this).parent().removeClass('more-active');
	});
	
	
	//Show more/less
	$('#show-me a').live('click', function(){
	
		if($('.to-expand').hasClass('expanded')){
			$('.to-expand').slideUp();
			$('.to-expand').removeClass('expanded');
			$('#show-me').addClass('expand');
			$('#show-me').removeClass('more');
		}else{
			$('.to-expand').slideDown();
			$('.to-expand').addClass('expanded');
			
			$('#show-me').removeClass('expand');
			$('#show-me').addClass('more');
			
		}
		
		
		return false;
	});
}

function changeOs()
{
	$('.control-pachets').find('li').live('click', function(){
			if($(this).attr('rel') == '1'){
				$('#pachets').find('div.windows').hide();
				$('#pachets').find('div.linux').show();
				$('.control-pachets').find('li.active').removeClass('active');

				$('.to-expand').find('table.w').hide();				
				$('.to-expand').find('table:not(.w)').show();
				$(this).addClass('active');
				$('.scripts').css('visibility','visible');
			}
				
			if($(this).attr('rel') == '2'){
				$('#pachets div.linux').hide();
				$('#pachets div.windows').show();
				$('.control-pachets').find('li.active').removeClass('active');
				$('.to-expand').find('table.w').show();				
				$('.to-expand').find('table:not(.w)').hide();
				$(this).addClass('active');
				$('.scripts').css('visibility','hidden');
			}	
		return false;
	});
}

/* Blog single*/
function blogComments()
{
	
	/*Search blog*/
	$('.search form span input').hover(function(){
		//in
		$(this).parent().addClass('hover');
	},function(){
		//Out
		$(this).parent().removeClass('hover');
	});

	$('.search form span input').focus(function(){
		$(this).parent().addClass('focused');
	});
	
	$('.search form span input').blur(function(){
		$(this).parent().removeClass('focused');
	});

	
	/*--Suport Tehnic--*/
	$('.intouch form').delegate('input:text','focusin', function(){
		$(this).parent().addClass('focused');
	});
	
	
	$('.intouch form').delegate('input:text','focusout', function(){
		$(this).parent().removeClass('focused');
	});
	
	
	
	
	$('.new-comment form span.bg-input input').hover(function(){
		//in
		$(this).parent().addClass('hover');
	},function(){
		//Out
		$(this).parent().removeClass('hover');
	});
	
	$('.new-comment form span.bg-input input').focus(function(){
		$(this).parent().addClass('bg-focused');
	});
	
	$('.new-comment form span.bg-input input').blur(function(){
		$(this).parent().removeClass('bg-focused');
	});
	
	
	$('.new-comment form span.bg-textarea textarea').focus(function(){
		if($(this).val() == 'Introdu mesajul...'){
			$(this).val('','');
		}
	
		$(this).parent().addClass('bg-textarea-focused');
	});
	
	$('.new-comment form span.bg-textarea textarea').blur(function(){

		if($(this).val() == ''){
			$(this).val('Introdu mesajul...');
		}
	
		$(this).parent().removeClass('bg-textarea-focused');
	});
	
}

/*Server*/
function serverStuff(){
	$('.button-next-story,.button-prev-story').hover(function(){
		$(this).find('span').css('visibility','visible');
	},function(){
		$(this).find('span').css('visibility','hidden');	
	});
	
}

function inTouch()
{
	$('.intouch input:text').wrap('<span class="bg-in"/>');
	$('.intouch input:submit').addClass('button');
}

function open_blank()
{
	$('a.open_blank').attr('target', '_blank');
}
