	function getResults(){

		$("#filter_results").html("").addClass('loading');
		$.post("../funnel.php", {
			filter: "yes", 
			manufecturer: $("#manufecturer").val(),
			processor: $("#processor").val(),
			suitable_for: $("#suitable_for").val(),
			processor_power: $("#processor_power").val(),
			display: $("#display").val(),
			catId: $("#catId").val()
		}, function(data){
			
			$("#filter_results").stop(true,true).html("" + data + "").removeClass('loading');
			
			filterProducts();
			

		});
	}

	function filterProducts(){
			var catId = $("#catId").val();
			_gaq.push(['_trackEvent', 'Laptop Filter', 'Filter', catId]);
			
			$(".quick_links").css({display: "none"});
			var hdd = $("#hdd").val();
			var the_hdd = hdd.split(" - ");
			
			var ram = $("#ram").val();
			var the_ram = ram.split(" - ");
			
			var price_tag = $("#price_tag").val();
			var the_price_tag = price_tag.split(" - ");			
			
			var the_warranty = $("#warranty").val();
			
			var hdmi = $("#hdmi:checked").val();
			var bluetooth = $("#bluetooth:checked").val();
			var hd = $("#fullhd:checked").val();
			var optics = $("#optics:checked").val();

			$('.product_brief').each(function(i){
			var display = true;
				var target_hdd = $(this).children('input[name="hdd"]').attr("value");
				var target_ram = $(this).children('input[name="ram"]').attr("value");
				var target_price = $(this).children('input[name="price"]').attr("value");
				var target_warranty = $(this).children('input[name="warranty"]').attr("value");
				var target_hdmi = $(this).children('input[name="hdmi"]').attr("value");
				var target_hd = $(this).children('input[name="hd"]').attr("value");
				var target_options = $(this).children('input[name="options"]').attr("value");
				var target_bluetooth = $(this).children('input[name="bluetooth"]').attr("value");

				// Compare hard drives
				if(target_hdd >= parseFloat(the_hdd[0]) && target_hdd <= parseFloat(the_hdd[1])){
				}else{
					display = false;
				}				
				
				// Compare rams drives
				if(target_ram >= parseFloat(the_ram[0]) && target_ram <= parseFloat(the_ram[1])){
				}else{
					display = false;
				}			

				// Compare prices
				if(target_price >= parseFloat(the_price_tag[0]) && target_price <= parseFloat(the_price_tag[1])){
				}else{
					display = false;
				}				
				
				// Compare warranty
				if(target_warranty >= parseFloat(the_warranty)){
				}else{
					display = false;
				}
				
				// Compare hdmi,full hd,optics,bluetooth
				if(hdmi=="yes"){
					if(target_hdmi == "yes" ){
					}else{
						display = false;
					}
				}			
				if(hd=="yes"){
					if(target_hd == "yes" ){
					}else{
						display = false;
					}
				}	
				if(optics=="yes"){
					if(target_options == "yes" ){
					}else{
						display = false;
					}
				}				
				if(bluetooth=="yes"){
					if(target_bluetooth == "yes" ){
					}else{
						display = false;
					}
				}
				

					if(display == true){
						$(this).css({display: "block"});
					}else{
						$(this).css({display: "none"});
					}
				
				
			});
			$(".product_brief").removeClass("left right clear");
			$(".product_brief").filter(':visible').filter(":odd").addClass("right");
			$(".product_brief").filter(':visible').filter(":even").addClass("left").addClass("clear");
		
	}
var cartIsAnimating = false;
	function getSearch(prefix){
		$("#liveresults").empty().fadeIn().addClass("loading");

		$.post(prefix + "liveresults.php", { s: $("#s").val()}, function(data){
 
			$("#liveresults").html("" + data + "").fadeIn().removeClass("loading");

		});
	}
	
	$(function(){
		/*
		$('.scroll-laptop div a').click(function(){
			var replacement = $(this).attr('rel');
			if($(this).hasClass("selected_cat")){
			$(this).removeClass("selected_cat");
			$("#catId").attr('value','52');
			}else{
			$(this).addClass("selected_cat");
			$(this).parent().siblings().children("a").removeClass("selected_cat");
			$("#catId").attr('value',replacement);
			}
			getResults();

		return false;
		});
		*/
		var wrapper_right_corner = $("#wrapper").offset();
		var config = {
			timeout: 150,
			over: menuOver,
			out: menuOut
		}
		function menuOver(){
			var nav_item = $(this).offset();
			$(this).addClass("category_item_selected");
			var submenu_width = $(this).children('.top_submenu').width();
			//alert(parseFloat(nav_item.left)+submenu_width);
			if(parseFloat(nav_item.left)+submenu_width >= wrapper_right_corner.left+920 ){
				$(this).children('.top_submenu').stop(true,true).slideToggle('fast').css({right: '0px'});
			}else{
				$(this).children('.top_submenu').stop(true,true).slideToggle('fast');
			}

		}
		function menuOut(){
			$(this).removeClass("category_item_selected");
			$(this).children('.top_submenu').stop(true,true).slideToggle('fast');
		}
		$(".category_item").hoverIntent(config);
		/*
		$('.toggle').click(function(){
		
		if( $(this).parent().parent().hasClass('selected')){
				$(this).parent().siblings('.top_submenu').slideUp('fast',function(){
					$(this).parent().removeClass('selected');
				 });

			}else{
				$('.selected div').slideUp('fast', function(){
						$(this).parent().removeClass('selected');
					});
				$(this).parent().siblings('.top_submenu').slideToggle('fast',function(){
				$(this).parent().toggleClass('selected');  
					});

			}
			return false;
			
		}); */

			$('.drop').click(function(){
				if( $(this).parent().parent().hasClass('selected')){
				 $(this).parent().siblings('ul').slideUp('fast', function(){
					$(this).parent().removeClass('selected');
				 });
				}else{
					$('.selected ul').slideUp('fast', function(){
						$(this).parent().removeClass('selected');
					})
					$(this).parent().siblings('ul').slideToggle('fast',function() {  
						$(this).parent().toggleClass('selected');  
					}).css({'display':'block'});
				}

			return false;
			});

			$('.drop1').click(function(){
				if( $(this).parent().parent().hasClass('selected1')){
				 $(this).parent().siblings('ul').slideUp('fast', function(){
					$(this).parent().removeClass('selected1');
				 });
				}else{
					$('.selected1 ul').slideUp('fast', function(){
						$(this).parent().removeClass('selected1');
					})
					$(this).parent().siblings('ul').slideToggle('fast',function() {  
						$(this).parent().toggleClass('selected1');  
					}).css({'display':'block'});
				}

			return false;
			});
					
	$("#propose-price").click(function(){
		$(this).slideToggle('fast',function(){
			$("#propose").slideToggle('slow');
		});
		return false;
	});
	$("#close").click(function(){
		$("#propose").slideToggle('fast',function(){
			$("#propose-price").slideToggle('slow');
		});
		return false;
	});
		
	// Add supplement javascript code
	$(".add_supplement").click(function(){
		if($(this).siblings('.supplement_list').css('display') == "block"){
			$(this).css({
			backgroundPosition: '0 0'
			});
			$(this).siblings('.supplement_list').slideToggle('fast');
		}else{
			$(this).css({
			backgroundPosition: '0 -33px'
			});
			$(this).siblings('.supplement_list').slideToggle('fast');
		}
		return false;
	});
	// Change component with it's supplement
	$(".supplement_list a").click(function(){
		var new_addtocart = $(this).attr('rel');
		var new_component_title = $(this).children('span').html();
		var add_to_price = $(this).children('strong').html();

		//Change component title
		$(this).parent().siblings('p').html(new_component_title);
		//Close Supplements list
		$('.add_supplement').css({
			backgroundPosition: '0 0'
		});
		$('.supplement_list').slideToggle('fast');
		//Change the add to cart url
		$("#product_buy").attr('href',new_addtocart);
		//Add supplement price to total price
		var base_price = parseFloat($("#base_price").attr("value"));
		if($("#supplement_added_price").length){
			var current_supplement_added = parseFloat($("#supplement_added_price").html());
			}else{
			var current_supplement_added = 0;
		}
		
		var add = parseFloat(add_to_price);

		var new_price = base_price + add;

		
		$("#supplement_added_price").remove();
		$(".current_price").before('<span class="price_discount" id="supplement_added_price">+'+add_to_price+'</span>');
		$(".current_price").html(new_price+'лв.');

		return false;
	});
	
	});
	
	$(document).ready(function() {

	$("#s").blur(function(){
		$("#liveresults").fadeOut();
	});
	$("#processor").change(function(){
		getResults();
	});
	
});
function simple_tooltip(target_items, name){
 $(target_items).each(function(i){
		$("body").append("<div class='"+name+"' id='"+name+i+"'><p>"+$(this).attr('alt')+"</p></div>");
		var my_tooltip = $("#"+name+i);

		$(this).removeAttr("title").mouseover(function(){
				my_tooltip.css({opacity:0.8, display:"none"}).fadeIn(400);
		}).mousemove(function(kmouse){
				my_tooltip.css({left:kmouse.pageX+15, top:kmouse.pageY+15});
		}).mouseout(function(){
				my_tooltip.fadeOut(400);
		});
	});
}
$(document).ready(function(){
	 simple_tooltip(".badge","tooltip");
	 
	 $("a[rel^='prettyPhoto']").prettyPhoto({theme:'light_rounded'});
});



	$(function(){
		$('.badge').hover(function(){
			
			var tooltip = $(this).attr('alt');
			
			$("#tooltip").html(tooltip).stop().fadeIn();
			
		},function(){
			$("#tooltip").stop().fadeOut();
		});
	
	});
	
	$(function(){
	$('.firm').toggle();
		$("#optFirm").change(function(){
			$('.firm').toggle();
			$('.phys').toggle();
		});
	});
	
	$(function(){
		
	$('.required').change(function(){
	
		var curVal = $(this).attr('value');
		
			if(curVal != ""){
				if(curVal.indexOf("@") == -1 && $(this).hasClass("email") == true){
				
				}else{
					$(this).removeClass('input-error');
					$(this).addClass('completed');
				}
			}else{
				$(this).removeClass('input-error')
				$(this).addClass('required');
			}
		
		}); 
	});
	
	$(function(){
	$("#errorMessage").hide();
		$('.checkoutfrm').submit(function(){
			$("#errorMessage").empty();
			var choice = $("#optFirm").attr('value');
			if(choice=="lice"){
			if($('#FirstName').attr('value')==""){
				$('#errorMessage').append("Моля въведете Име <br/>");
				var error = true;
			}
			if($('#LastName').attr('value')==""){
				$('#errorMessage').append("Моля въведете Фамилия <br/>");
				var error = true;
			}
			if($('#egn').attr('value')==""){
				$('#errorMessage').append("Моля въведете Egn <br/>");
				var error = true;
			}
			}else{
			if($('#FirmName').attr('value')==""){
				$('#errorMessage').append("Моля въведете Име на фирмата<br/>");
				var error = true;
			}
			if($('#FirmMol').attr('value')==""){
				$('#errorMessage').append("Моля въведете МОЛ на фирмата <br/>");
				var error = true;
			}
			if($('#FirmBulstat').attr('value')==""){
				$('#errorMessage').append("Моля въведете Булстат на фирмата <br/>");
				var error = true;
			}
			}
			if($('#Phone').attr('value')==""){
				$('#errorMessage').append("Моля въведете Телефон за връзка<br/>");
				var error = true;
			}
			if($('#Email').attr('value')==""){
				$('#errorMessage').append("Моля въведете E-mail <br/>");
				var error = true;
			}
			if($('#City').attr('value')==""){
				$('#errorMessage').append("Моля въведете Град<br/>");
				var error = true;
			}
			if($('#Address').attr('value')==""){
				$('#errorMessage').append("Моля въведете Адрес<br/>");
				var error = true;
			}
			if(error == true){
			$("#errorMessage").fadeIn();
			return false;
			}else{
			$("#errorMessage").fadeOut();
			}
		});
	
	});
	
	$(function(){
	$("#errorMessage").hide();
		
		$("#credit_egn").mask("9999999999",{placeholder:" "});
		$("#credit_id_card").mask("999999999",{placeholder:" "});
		$("#credit_id_card_date").mask("99/99/9999",{placeholder:" "});

		
		$('.required').change(function(){
			if($(this).attr('value')==""){
				$(this).addClass('input-error');
			}else if($(this).text==""){
				$(this).addClass('input-error');
			}else{
				$(this).removeClass('input-error');
			}
		});
	
		$('.frmCredit').submit(function(){
			$("#errorMessage").empty();
			var error = false;
			$('.required').each(function(index) {
				if($(this).attr('value')==""){
					$(this).addClass('input-error');
					error = true;
				}else{
					$(this).removeClass('input-error');
				}
			  });
			  
			$('.required_checkbox').each(function(index) {
				if($(this).is(':checked') == false){
				error = true;
				}
			});
			
			if(error == true){
			$('#errorMessage').append("Моля въведете всички полета правилно<br/>");
			$("#errorMessage").fadeIn();
			return false;
			}else{
			$("#errorMessage").fadeOut();
			}
		});
	
	});

	$(function(){
	
		$('#grid_link').click(function(){
			$('.product_brief').animate({width:"303px"});
			$('.product_card').removeClass('align_left');
			return false;
		});
		$('#list_link').click(function(){
			$('.product_brief').animate({width:"643px",minHeight:"180px"});
			$('.product_card').addClass('align_left');
			return false;
		});
	
	$("#s").focus(function(){
		$(this).attr("value","");
	
		});
	});
	
$slideshow = {
    context: false,
    tabs: false,
    timeout: 5000,      // 5000 time before next slide appears (in ms)
    tabSpeed: 300,      // time it takes to slide in each slide (in ms) when clicking through tabs
    fx: 'fade',   // the slide effect to use
    
    init: function() {
        // set the context to help speed up selectors/improve performance
        this.context = $('#slideshow');
        
        // set tabs to current hard coded navigation items
        this.tabs = $('ul.slides-nav li', this.context);
        
        // remove hard coded navigation items from DOM 
        // because they aren't hooked up to jQuery cycle
        this.tabs.remove();
        
        // prepare slideshow and jQuery cycle tabs
        this.prepareSlideshow();
    },
    
    prepareSlideshow: function() {
        // initialise the jquery cycle plugin -
        // for information on the options set below go to: 
        // http://malsup.com/jquery/cycle/options.html
        $("div.slides > ul", $slideshow.context).cycle({
            fx: $slideshow.fx,
            timeout: $slideshow.timeout,
            speed: $slideshow.slideSpeed,
            fastOnEvent: $slideshow.tabSpeed,
            pager: $("ul.slides-nav", $slideshow.context),
            pagerAnchorBuilder: $slideshow.prepareTabs,
            before: $slideshow.activateTab,
            pauseOnPagerHover: true,
            pause: true
        });            
    },
    
    prepareTabs: function(i, slide) {
        // return markup from hardcoded tabs for use as jQuery cycle tabs
        // (attaches necessary jQuery cycle events to tabs)
        return $slideshow.tabs.eq(i);
    },

    activateTab: function(currentSlide, nextSlide) {
        // get the active tab
        var activeTab = $('a[href="#' + nextSlide.id + '"]', $slideshow.context);
        
        // if there is an active tab
        if(activeTab.length) {
            // remove active styling from all other tabs
            $slideshow.tabs.removeClass('on');
            
            // add active styling to active button
            activeTab.parent().addClass('on');
        }            
    }            
};

$(function() {
    // initialise the slideshow when the DOM is ready
     $slideshow.init();
});


$.fn.infiniteCarousel = function () {

    function repeat(str, num) {
        return new Array( num + 1 ).join( str );
    }
  
    return this.each(function () {
        var $wrapper = $('> div', this).css('overflow', 'hidden'),
            $slider = $wrapper.find('> ul'),
            $items = $slider.find('> li'),
            $single = $items.filter(':first'),
            
            singleWidth = $single.outerWidth(), 
            visible = Math.ceil($wrapper.innerWidth() / singleWidth), // note: doesn't include padding or border
            currentPage = 1,
            pages = Math.ceil($items.length / visible);            


        // 1. Pad so that 'visible' number will always be seen, otherwise create empty items
        if (($items.length % visible) != 0) {
            $slider.append(repeat('<li class="empty" />', visible - ($items.length % visible)));
            $items = $slider.find('> li');
        }

        // 2. Top and tail the list with 'visible' number of items, top has the last section, and tail has the first
        $items.filter(':first').before($items.slice(- visible).clone().addClass('cloned'));
        $items.filter(':last').after($items.slice(0, visible).clone().addClass('cloned'));
        $items = $slider.find('> li'); // reselect
        
        // 3. Set the left position to the first 'real' item
        $wrapper.scrollLeft(singleWidth * visible);
        
        // 4. paging function
        function gotoPage(page) {
            var dir = page < currentPage ? -1 : 1,
                n = Math.abs(currentPage - page),
                left = singleWidth * dir * visible * n;
            
            $wrapper.filter(':not(:animated)').animate({
                scrollLeft : '+=' + left
            }, 500, function () {
                if (page == 0) {
                    $wrapper.scrollLeft(singleWidth * visible * pages);
                    page = pages;
                } else if (page > pages) {
                    $wrapper.scrollLeft(singleWidth * visible);
                    // reset back to start position
                    page = 1;
                } 

                currentPage = page;
            });                
            
            return false;
        }
        
        $wrapper.after('<a class="arrow back">&lt;</a><a class="arrow forward">&gt;</a>');
        
        // 5. Bind to the forward and back buttons
        $('a.back', this).click(function () {
            return gotoPage(currentPage - 1);                
        });
        
        $('a.forward', this).click(function () {
            return gotoPage(currentPage + 1);
        });
        
        // create a public interface to move to a specific page
        $(this).bind('goto', function (event, page) {
            gotoPage(page);
        });
    });  
};

$(document).ready(function () {
  $('.carousel').infiniteCarousel();
});
function storeAddress() {
	// Update user interface
	var email = $('#email').attr('value');
	$.get("library/store-address.php", {ajax: "true", email: $('#email').val()}, function(data){
	
			$("#response").stop().fadeOut('fast').html("<strong>" + data + " </strong>").fadeIn();
	
	});
}
$(document).ready(function () {
	$("#subscribe").click(function(){
		storeAddress();
		return false;
	})

});


