var halt_hide_submit = false; var firstFocus = true; function setItem(text) { $('#search_text_input').val(text); $('#day_list').hide(); $('#week_list').hide(); firstFocus = false; $('#search_text_input').css('color', 'black') .css('font-weight', 'normal') .css('font-size', '15px'); } function showTop(URL, item) { var options = ""; $.getJSON(URL, function(data) { $.each(data, function(id, product) { options += ""; }); $(item).html(""); $(item).show(); }); } function init_auto_name() { $("#search_text_input, #card_search_text_input").unbind('change'); $("#search_text_input, #card_search_text_input").unbind('keydown'); $("#search_text_input, #card_search_text_input").unbind('keypress'); $("#search_text_input, #card_search_text_input").unbind('keyup'); $("#search_text_input, #card_search_text_input").autocomplete("http://telesputnik.lv/php/ajax_products.php", { delay:250, minChars:3, cacheLength:0, matchSubset:1, autoFill:false, selectFirst:false, maxItemsToShow:50, width: 418 }); } function init_auto_code() { $("#search_text_input, #card_search_text_input").unbind('change'); $("#search_text_input, #card_search_text_input").unbind('keydown'); $("#search_text_input, #card_search_text_input").unbind('keypress'); $("#search_text_input, #card_search_text_input").unbind('keyup'); $("#search_text_input, #card_search_text_input").autocomplete("http://telesputnik.lv/php/ajax_codes.php", { delay:250, minChars:3, cacheLength:0, matchSubset:1, autoFill:false, selectFirst:false, maxItemsToShow:50, width: 418 }); } $(document).ready(function(){ $('#a_day').click( function() { showTop("http://telesputnik.lv/php/ajax_products.php?a=day", '#day_list'); }); $('#a_week').click( function() { showTop("http://telesputnik.lv/php/ajax_products.php?a=week", '#week_list'); }); $('#day_list').click( function() { $('#day_list').hide(); $('#week_list').hide(); }); $('#week_list').click( function() { $('#day_list').hide(); $('#week_list').hide(); }); $('#search_text_input').click( function() { $('#day_list').hide(); $('#week_list').hide(); }); var focus_value = ''; if(focus_value == '') focus_value = 'Search'; var card_focus_value = ''; if(card_focus_value == '') card_focus_value = 'Search'; setDefaultValue(); function setDefaultValue() { if(document.getElementById('search_text_input')) { if($('#search_text_input').val() == '') { $('#search_text_input').val(focus_value); $('#search_text_input').css('color', '#DDDDDD'); $('#search_text_input').css('font-weight', 'bold'); $('#search_text_input').css('font-size', '13px'); firstFocus = true; } else firstFocus = false; } else if(document.getElementById('card_search_text_input')) { if($('#card_search_text_input').val() == '') { $('#card_search_text_input').val(card_focus_value); firstFocus = true; } else firstFocus = false; } } $('#search_text_input, #card_search_text_input').focus( function() { if(firstFocus) { $(this).val(''); $(this).css('color', 'black'); $(this).css('font-weight', 'normal'); $(this).css('font-size', '15px'); firstFocus = false; } $(this).parent().css('border-left', 'solid 2px #61BF9A'); $(this).parent().css('border-top', 'solid 2px #61BF9A'); $(this).parent().css('border-right', 'solid 1px #D1DCD8'); $(this).parent().css('border-bottom', 'solid 1px #D1DCD8'); $('#card_search_button').show(); }); $('#search_text_input, #card_search_text_input').blur( function() { if(!halt_hide_submit) { $(this).parent().css('border-left', 'solid 1px #cfcecc'); $(this).parent().css('border-top', 'solid 1px #cfcecc'); $(this).parent().css('border-right', 'solid 1px #cfcecc'); $(this).parent().css('border-bottom', 'none'); $('#card_search_button').hide(); setDefaultValue(); } }); $('#search_submit').mouseover( function() { halt_hide_submit = true; }); $('#search_submit').mouseout( function() { halt_hide_submit = false; }); $('#search_submit').mousedown( function() { if(firstFocus) { $('#search_text_input').val(''); $('#search_text_input').css('color', 'black'); $('#search_text_input').css('font-weight', 'normal'); firstFocus = false; } }); $('#search_submit').click( function() { $('#form_search').submit(); }); $('.icon_descr').hover( function () { this.src = "i/descrh.png"; }, function () { this.src = "i/descr.png"; } ); }); function stick($menu, $wrapper){ var wrapper = $wrapper.get(0); var rect = wrapper.getBoundingClientRect(); if(rect.top < 0) $menu.attr("sticky", "true"); else if(rect.top >= 0) $menu.attr("sticky", "false"); } $(function(){ var menu = $("#menu"); var menuWrapper = $("#menuWrapper"); $(window).scroll(function(){stick(menu, menuWrapper)}); });