// controls.js - last modified: February 05 2012 03:47:25.


$(document).ready
(function()
{var urlRegex=/^.*\.\w{2,4}([^\#\?]*).*$/;if($.browser.msie&&$.browser.version<7)
$('#mini-quote li').hover
(function(){$(this).addClass('hover')},function(){$(this).removeClass('hover')});$.xui=$.xui||{};$.xui.currentQuery='';var registerMiniquoteControls=function()
{$('#mini-quote a.remove-from-quote').click(function()
{$.getJSON(this.href+"&method=jsonp&jsoncallback=?",updateQuote);return false;});};var updateQuote=function(data)
{$('#mini-quote').replaceWith(data['mini-quote']);registerMiniquoteControls();if(data['added'])
{var frm=$('#quote-item'+data['added']['product_id']);$('input[value=add]',frm).hide();$('input[value=remove]',frm).show();}
else if(data['updated'])
{$('#quote-items').html(data['quote-items']);registerProductListControls();}
else if(data['removed'])
{var itm='#quote-item'+data['removed']['product_id'];var frm=$(itm);frm.find('input[value=add]').show();frm.find('input[value=remove]').hide();if($('#quote_form').length)
{$(itm).remove();if(data['QuoteRequest']['count']==0)
$('#quote-empty').show();}}};var registerProductListControls=function()
{$('input.modify-quote').click(function()
{var vars=$(this).parents('form').serialize();$.getJSON("/quote-request?"+vars+"&action="+this.value+"&method=jsonp&jsoncallback=?",updateQuote);return false;});$('#quote_form a.remove-quote-item').click(function()
{$.getJSON(this.href+"&method=jsonp&jsoncallback=?",updateQuote);return false;});$('input.update-item, select.update-item','#quote_form').blur(function()
{var num=$(this).attr('name').replace(/^.*\[(\d+)\].*$/,'$1');var frm=$('#quote_form');$('#quote_form').oneTime(500,'update',function()
{$.post(window.location+"?action=update&method=jsonp&jsoncallback=?",$('input.update-item, select.update-item',frm).serialize(),updateQuote,'jsonp');});return false;}).focus(function()
{$('#quote_form').stopTime('update');});};var navigate=function(args,add,scroll)
{if(/\?/.test(args))args=args.replace(/^.*\?(.*$)/g,'$1');var href=window.location.href.replace(urlRegex,'$1');$.getJSON(href+'?'+args+"&method=jsonp&jsoncallback=?",function(data)
{$('#search-filters').replaceWith(data['search-filters']);$('#current-filters').replaceWith(data['current-filters']);$('#product-list').replaceWith(data['product-list']).ready(function(){if(scroll)$.scrollTo('#product-list',400);});registerProductListControls();registerPagingControls();$.xui.currentQuery=$.str.urldecode(data['currentQuery']);if(add)$.historyLoad($.xui.currentQuery,true);});};$.xui.navigate=navigate;var registerPagingControls=function()
{$('a.search-filter-link').click(function(evt)
{evt.preventDefault();var href=this.href.replace(urlRegex,'$1');if(href!=window.location.href.replace(urlRegex,'$1'))
{window.location.href=href;return false;}
navigate(this.href.replace(/^.*\?(.*$)/g,'$1'),true,false);return false;});$('form.search-nav-form').submit(function(evt)
{evt.preventDefault();navigate($(this).serialize(),true,false);return false;});$('a.search-nav-link').click(function(evt)
{evt.preventDefault();var href=this.href.replace(urlRegex,'$1');if(href!=window.location.href.replace(urlRegex,'$1'))
{window.location.href=href;return false;}
navigate(this.href.replace(/^.*\?(.*$)/g,'$1'),true,true);return false;});};$.historyInit(null,function(hash)
{if($.xui.currentQuery!=hash)
navigate(hash,true,false);});registerMiniquoteControls();registerProductListControls();registerPagingControls();});
