
DD_roundies.addRule('.round-bot', '0 0 20px 20px');
$(document).ready(function() {
		 $('.plink').click(function() {
			window.location = "/products/";
		});
		$('.slink').click(function() {
			window.location = "/support/";
		});		
		$('.alink').click(function() {
			window.location = "/about/";
		});
			$(".nav").clickMe({
        activeMenu: "current",
        moveIt: "#container",
        moveItMargin : 20,
        aniShow: { opacity: "show", height: "show"},
        aniHide: { opacity: "hide", height: "hide"},
        speed: "slow"
});
			
	$(window).scroll(function() {
		if($(this).scrollTop() != 0) {
			$('#toTop').fadeIn();	
		} else {
			$('#toTop').fadeOut();
		}
	});


	$('#toTop').click(function() {
		$('body,html').animate({scrollTop:0},800);
	});	
		 $( "#tags" ).autocomplete({
	  open: function(event, ui) { $("a.nivo-imageLink ").css("z-index", -1); },
	  close: function(event, ui) { $("a.nivo-imageLink ").css("z-index", 60); }
	});

	var searchDefault = "Search for Nulon products...";
    $("#search-field").focus(function(){
		if($(this).attr("value") == searchDefault) $(this).attr("value", "");
		$(this).addClass("active");
	});
	$("#search-field").blur(function(){
		if($(this).attr("value") == "") $(this).attr("value", searchDefault);
		$(this).removeClass("active");
	});
	var newsletterDefault = "Enter your email address here...";
    $("#mskut-mskut").focus(function(){
		if($(this).attr("value") == newsletterDefault) $(this).attr("value", "");
		$(this).addClass("active");
	});
	$("#mskut-mskut").blur(function(){
		if($(this).attr("value") == "") $(this).attr("value", newsletterDefault);
		$(this).removeClass("active");
	});


		$("#search-form span.glass").click(function () { 
      window.location.href = "/result.php?search="+$("#search-field").val();

    });
	
		$( "#search-field" ).autocomplete({
			  open: function(event, ui) { $(".ui-autocomplete").css("z-index", 80); },
			  close: function(event, ui) { $(".ui-autocomplete").css("z-index", 2); },
			minLength: 0,
			source: "/autosuggest.php",
			focus: function( event, ui ) {
				//$( "#search-field" ).val( ui.item.value );

				return false;
			},
			select: function( event, ui ) {
				//$( "#search-field" ).val( ui.item.label);
			//	$( "#search-field-id" ).val( ui.item.value );
				var tname = ui.item.fullvalue;
				var urlName = tname.replace(/ /gi,'_');
				var pgname = ui.item.groupName;
				var pgnameUS = pgname.replace(/ /gi,'_');
				window.location.href='/products/'+pgnameUS+'/'+urlName+'/';
				
			//	$( "#search-field-description" ).html( ui.item.desc );
			//	$( "#search-field-icon" ).attr( "src", "images/" + ui.item.icon );

				return false;
			},
			change: function(event, ui) {
				
				return false;
			}

		})
		.data( "autocomplete" )._renderItem = function( ul, item ) {
			return $( "<li></li>" )
				.data( "item.autocomplete", item )
				.append( "<a><img src='/files/images/"+item.group+"/"+item.part_no.toUpperCase()+"-thumb.jpg'/><span class='autoTitle'>" + item.label + "</span><span class='autoDesc'>" + item.desc + "</span></a>" )
				.appendTo( ul );
		}
});


	$(window).load(function() {    

        var theWindow        = $(window),
            $bg              = $("#bg"),
            aspectRatio      = $bg.width() / $bg.height();

        function resizeBg() {

                if ( (theWindow.width() / theWindow.height()) < aspectRatio ) {
                    $bg
                        .removeClass()
                        .addClass('bgheight');
                } else {
                    $bg
                        .removeClass()
                        .addClass('bgwidth');
                }

        }

        theWindow.resize(function() {
                resizeBg();
        }).trigger("resize");

});
