


$(function() {
	$('.lightbox').lightBox({
            fixedNavigation:true,
            containerResizeSpeed: 10,
            txtImage: 'Снимка',
            txtOf: 'от'
            

    });
});



function language_set(lang){


//alert('waaa');
document.cookie = 'language = '+lang;
location.reload(true);
}


function vapros_mail_send(){

    

    text = $('#vapros_mail_text').val();

    mail = $('#vapros_mail_mail').val();


    if(text.length < 5) {
        alert('Въведете запитване');
        return;
    }

    if(mail.length < 5) {
        alert('Въведете email');
        return;
    }


    $('#vapros_mail').html('Пращам...');

    $.ajax({
        url:"ajax/mail.php",
        type:"POST",
        data:"text="+urlencode_po_taka(text)+'&mail='+urlencode_po_taka(mail)+'&tema='+urlencode_po_taka('запитване за продукт '+mail_subject),
        success:function(){
        $('#vapros_mail').html('Запитването изпратено');
        }
    });
    
}








function search_ajax(a){


koe = $('#suggestions');
koe_ime = '#suggestions';

koe.html('');

koe.fadeIn(500);
    


    $.ajax({
        url:"ajax/search.php",
        type:"GET",
        data:"search="+urlencode_po_taka(a),
        success:function(msg){
        //$('#suggestions').html(msg);
		rez=false;








            txt = '';

            txt += ('<div style="width: 1000px;padding-top:10px;position: absolute;z-index: 2;background: url(\'template/en2/images/srchtransprt.png\');"><div id="panes" class="panes"><div class="scrollbar"><div class="track"><div class="thumb"><div class="end"></div></div></div></div><div class="viewport">						<div class="overview"><table>');



		tabs='';

		tmpi=0;
            $(msg).find("model").each(function()
              {
		tmpi++;
		if(tmpi==1){			
			txt += '<tr>';
			tabs+='	<li><a href="#"></a></li>';
		}		rez=true;
				
                style_heigh = 50;
                style_img_width = 60;

                txt += '<td><a href="index.php?id=' + ($(this).attr("url")) + '" >';

                txt += ('<div style="height: '+style_heigh+'px;">  <div style="width: 65px;height: '+style_heigh+'px;text-align:center;float: left;">  <img src="');

                txt += ($(this).attr("image"));

                txt += ('" style="max-width: '+style_heigh+'px;max-height:'+style_heigh+'px; border:0;vertical-align:middle;" /> </div>  <div style="font-size:10pt;float: left;height: '+style_heigh+'px; width:130px;color:#FFFFFF">');
				
				txt += ($(this).attr("marka")+'<br>');	

                txt += ($(this).attr("name"));





                txt  += '</div> </div> </a></td>';

		if(tmpi==5){
			tmpi=0;
			txt += '</tr>';
		}


              });
		tabs+='';
		txt += '</table></div></div></div>';
		//text += tabs;

             /* $(msg).find("nextpage").each(function()
              {


                text += ($(this).attr("code"));
              	koe.append($(this).attr("url"));



             	text += ('<br><br>');
              });*/



              txt += ('</div>');

             /* text += ('<br><a href="#" style="color:#FFFFFF;text-decoration:none;font-weight:bold;float:right;" onclick="search_ajax_close(\''+koe_ime+'\');return false;"> X</a>');
			*/	
			  txt += ('<div class="clear"></div>');
			
			  //txt +="<script type='text/javascript'>$('#panes').tinyscrollbar();</script>";
			  if(rez){
				koe.html(txt);
				//var t=setTimeout("addscroll()",300);
			  }




           //koe.html(msg);

            //zarejdane_finish();

	

		
	

       }
    });
    
    


    
	$("ul.tabs").tabs("div.panes > div");
}

function addscroll()
{
	$('#panes').tinyscrollbar();
	alert('fs');
}

function search_ajax_close(a){
    a = $(a);
    a.fadeOut(200);
    a.html('');
}




function urlencode_po_taka(str) {
return encodeURIComponent(str);
}




function makeScrollable(wrapper, scrollable){
	// Get jQuery elements
	var wrapper = $(wrapper), scrollable = $(scrollable);

	// Hide images until they are not loaded
	scrollable.hide();
	var loading = $('<div class="loading">Loading...</div>').appendTo(wrapper);

	// Set function that will check if all images are loaded
	var interval = setInterval(function(){
		var images = scrollable.find('img');
		var completed = 0;

		// Counts number of images that are succesfully loaded
		images.each(function(){
			if (this.complete) completed++;
		});

		if (completed == images.length){
			clearInterval(interval);
			// Timeout added to fix problem with Chrome
			setTimeout(function(){

				loading.hide();
				// Remove scrollbars
				wrapper.css({overflow: 'hidden'});

				scrollable.slideDown('slow', function(){
					enable();
				});
			}, 1000);
		}
	}, 100);

	function enable(){
		// height of area at the top at bottom, that don't respond to mousemove
		var inactiveMargin = 100;
		// Cache for performance
		var wrapperWidth = wrapper.width();
		var wrapperHeight = wrapper.height();
		// Using outer height to include padding too
		var scrollableHeight = scrollable.outerHeight() + 2*inactiveMargin;
		// Do not cache wrapperOffset, because it can change when user resizes window
		// We could use onresize event, but it's just not worth doing that
		// var wrapperOffset = wrapper.offset();

		//When user move mouse over menu
		wrapper.mousemove(function(e){
			var wrapperOffset = wrapper.offset();
			// Scroll menu
			var top = (e.pageY -  wrapperOffset.top) * (scrollableHeight - wrapperHeight) / wrapperHeight - inactiveMargin;

			if (top < 0){
				top = 0;
			}

			wrapper.scrollTop(top);
		});
	}
}

