


$(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);









            text = '';

            text += ('<div style="display: block; position: relative;background-color: #FFFFFF;width: 200px;">');






            $(msg).find("model").each(function()
              {

                style_heigh = 60;
                style_img_width = 60;

                text += '<a href="?id=' + ($(this).attr("url")) + '" >';

                text += ('<div style="height: '+style_heigh+'px;margin:3px 5px 0px;">  <div style="width: 60px;height: '+style_heigh+'px;width: 60px;float: left;"><center>  <img src="');

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

                text += ('" style="max-width: '+style_heigh+'px;max-height:'+style_heigh+'px; border:0;vertical-align:middle;" /> </center></div>  <div style="margin-left:10px;float: left;height: '+style_heigh+'px; width:120px;font-size:10pt;">');

				text += ($(this).attr("marka")+'<br>');	
				
                text += ($(this).attr("name"));





                text  += '</div> </div> </a>';


              });

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


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



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


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

              text += ('<br><a href="#" onclick="search_ajax_close(\''+koe_ime+'\');return false;">x</a>');

              koe.html(text);





           //koe.html(msg);

            //zarejdane_finish();

       }
    });

}


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);
		});
	}
}
