$(document).ready(function(){
    $("#menu li").hover(
//        function(){ $("ul", this).fadeIn("fast"); }, 
        function(){ $("ul", this).show(150); },
        function() { } 
    );
    if (document.all) {
        $("#menu li").hoverClass ("sfHover");
    }
    
    
    /*$("#homeTabs li").click(
    	function(){
    		$("#container div p").fadeIn("normal");
    	}
    );*/
});

$.fn.hoverClass = function(c) {
    return this.each(function(){
        $(this).hover( 
            function() { $(this).addClass(c);  },
            function() { $(this).removeClass(c); }
        );
    });
};


function switch_gallery(current){
	
	var elm = document.getElementById('single_' + current);
	
	for(i=0; i < 3; i++) {
		document.getElementById('single_' + i).style.display = 'none';
	}
	
	elm.style.display = 'block';	
}

function switch_video(pos){
	
	var meta = document.getElementById('meta_' + pos);
	var title = document.getElementById('title_' + pos);
	var video = document.getElementById('video_top_' + pos);
	var sub = document.getElementById('sub_' + pos);
	
	for(i=0; i<3; i++){
		document.getElementById('sub_' + i).style.display = 'none';
		document.getElementById('meta_' + i).style.display = 'none';
		document.getElementById('title_' + i).style.display = 'none';
		document.getElementById('video_top_' + i).style.display = 'none';
	}
	
	meta.style.display = title.style.display = video.style.display = sub.style.display = 'block';
}


function search(){
	
	var elm = document.getElementById("options");
	var btn = document.getElementById("search");
	
	elm.style.display = (elm.style.display == 'block') ? 'none' : 'block';
	btn.style.backgroundPosition = (elm.style.display == 'block') ? '-22px top' : 'left top';
	
}

//buletin form validation
//Валидира e-mail
function validate_email(field,alerttxt)
{
    with (field)
    {
        apos=value.indexOf("@");
        dotpos=value.lastIndexOf(".");
        if (apos<1||dotpos-apos<2)
        {alert(alerttxt);return false;}
         else {return true;}
    }
}

//Проверява текстовите полета
function validate(field,alerttxt){
    with(field)
    {
        if(value== null || value =="")
         {alert(alerttxt); return false;}
    }
    return true;
}

//Проверява Checkbox
function validate_ch(field,alerttxt){
    with(field)
    {
      if(field.checked==false)
       {alert(alerttxt); return false;}
    }
    return true;
}

//функция проверяваща валидноста на полето сектор!
function validate_se(field,alerttxt){
    with(field)
    {
      if(value=="default")
       {alert(alerttxt); return false;}
    }
    return true;
}

//Валидация на картинката
function anti_spam(field_1,field_2,alerttxt){
    
    var real= field_1.value;
    var hid = field_2.value;
    
    if(real!=(hid*3-159))
    {alert(alerttxt);  return false;}
    
   return true; 
}

//Главна валидираща
function validate_form(thisform)
{
    with (thisform)
    {
	
        if (validate_email(email,"E-mail адресът, който сте въвели е невалиден!")==false)
            {email.focus();return false;}
        if(validate(position,"Полето \"Позиция\" не е попълнено!")==false)
            {position.focus(); return false;}
        if(validate(company,"Полето \"Компания\" не е попълнено!")== false)
            {company.focus(); return false;}
	if(validate_se(sector,"Не е избран сектор на дейност!")==false)
            {sector.focus(); return false;}
        if(validate_ch(terms,"Не е потвърдено съгласие с общите условия!")==false)
            {terms.focus(); return false;}
	if(anti_spam(val,cs,"Кодът който сте въвели е грешен!")==false)
	{val.focus(); return false;}
	 
    }
}

//check quiz answers
function validate_answer(thisfield)
{
    for (i = 0; i < thisfield.length; i++){
	if(thisfield[i].checked == true){
		return true;
	}
    }
    
    alert('Не сте отговорили на въпроса');
    thisfield[0].focus();
    return false;
}
