var menuSlider=function(){
	var m,e,g,s,q,i; e=[]; q=28; i=8;
	return{
		init:function(j,k){
			m=document.getElementById(j); e=m.getElementsByTagName('li');
			var i,l,w,p; i=0; l=e.length;
			for(i;i<l;i++){
				var c,v; c=e[i]; v=c.value; if(v==1){s=c; w=c.offsetWidth; p=c.offsetLeft}
				c.onmouseover=function(){menuSlider.mo(this)}; c.onmouseout=function(){menuSlider.mo(s)};
			}
			g=document.getElementById(k); g.style.width=w+'px'; g.style.left=p+'px';
		},
		mo:function(d){
			clearInterval(m.tm);
			var el,ew; el=parseInt(d.offsetLeft); ew=parseInt(d.offsetWidth);
			m.tm=setInterval(function(){menuSlider.mv(el,ew)},i);
		},
		mv:function(el,ew){
			var l,w; l=parseInt(g.offsetLeft); w=parseInt(g.offsetWidth);
			if(l!=el||w!=ew){
				if(l!=el){var ld,lr,li; ld=(l>el)?-1:1; lr=Math.abs(el-l); li=(lr<q)?ld*lr:ld*q; g.style.left=(l+li)+'px'}
				if(w!=ew){var wd,wr,wi; wd=(w>ew)?-1:1; wr=Math.abs(ew-w); wi=(wr<q)?wd*wr:wd*q; g.style.width=(w+wi)+'px'}
			}else{clearInterval(m.tm)}
}};}();

jQuery(document).ready(function() {
    var h;
    $("img").each(function() {
        if($(this).width() > 680) {
            h=$(this).height()/$(this).width()*680;
            $(this).attr({height : h });
            $(this).attr({width : "680"});
        }
    });

	//ACCORDION BUTTON ACTION (ON CLICK DO THE FOLLOWING)
	$('.accordionButton').click(function() {

		//NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
		$(".short_descr").show();
	 	$('.accordionContent').slideUp('normal');
   
		//IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
		if($(this).next().is(':hidden') == true) {
			
			$(this).children(".short_descr").hide();
			//OPEN THE SLIDE
			$(this).next().slideDown('normal');
		 } 
		  
	 });
	  
	$('.accordionContent').click(function() {
		$(this).slideUp('normal');
		$(this).prev().children(".short_descr").slideDown('normal');
	 });
	  
	/********************************************************************************************************************
	CLOSES ALL S ON PAGE LOAD
	********************************************************************************************************************/	
	$('.accordionContent').hide();
	$('.short_descr:first').hide();
	$('.accordionContent:first').show();

})


function fullScreen(theURL) {
window.open(theURL, '', 'fullscreen=yes, scrollbars=auto');
}




//contact
function validateFormOnSubmit1(theForm) {
var reason = "";
	reason += validateEmpty(theForm.name);
	reason += validateEmpty(theForm.message);
	reason += validateEmpty(theForm.number);
	reason += validateEmail(theForm.email);
      
  if (reason != "") {
    alert("Полетата, оцветени с жълто трябва да бъдат попълнени.\n" + reason);
    return false;
  }

  return true;
}

//partner
function validateFormOnSubmit2(theForm) {
var reason = "";
	reason += validateEmpty(theForm.company);
	reason += validateEmpty(theForm.name);
	reason += validateEmpty(theForm.city);
	reason += validateEmpty(theForm.country);
	reason += validateEmpty(theForm.address);
	reason += validateEmpty(theForm.phone);
	reason += validateEmpty(theForm.website);
	reason += validateEmpty(theForm.describe_profile);
	reason += validateEmpty(theForm.describe_products);
	reason += validateEmpty(theForm.describe_strategy);
	reason += validateEmpty(theForm.number);
	reason += validateEmail(theForm.email);
      
  if (reason != "") {
    alert("Полетата, оцветени с жълто трябва да бъдат попълнени.\n" + reason);
    return false;
  }

  return true;
}

function validateEmpty(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        error = "\t"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "\nНе сте въвели електронен адрес.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "\nМоля, въведете валиден електронен адрес.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "\nЕлектронният адрес съдържа непозволени символи.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}


