
(function($){$.fn.extend({defaultValue:function(default_value){return this.each(function(){var obj=$(this);obj.val(default_value);obj.focus(function(){if(obj.val()==default_value){obj.val("");}});obj.blur(function(){if(""==obj.val()){obj.val(default_value);}});});}})})(jQuery);(function($){$.fn.extend({zebra:function(options){var defaults={even:'#fff',odd:'#ccc'}
var final_options=$.extend(defaults,options);return this.each(function(){var obj=$(this);obj.children(":even").css('background-color',final_options['even']);obj.children(":odd").css('background-color',final_options['odd']);});}});})(jQuery);(function($){$.fn.extend({truncate:function(rows){var obj=$(this);var counter=0;obj.children().each(function(){counter++;if(counter>rows){$(this).addClass('truncated');$(this).hide();}});var $new_row=$(document.createElement('tr'));var $new_cell=$(document.createElement('td')).appendTo($new_row);var $show_link=$(document.createElement('a')).appendTo($new_cell);var $hide_row=$new_row.clone();var $hide_link=$hide_row.find('a');$hide_link.text('Show less').attr('href','#').click(function(){obj.children('.truncated').hide();$hide_row.hide();$new_row.show();return false;});$show_link.text('See all '+counter).attr('href','#').click(function(){obj.children().show();$new_row.hide();$hide_row.show();return false;});$new_row.appendTo(obj);$hide_row.appendTo(obj).hide();}});})(jQuery);(function($){$.fn.extend({attribute_link:function(){return $(this).each(function(){var $obj=$(this);$obj.click(function(){var url=$(this).attr('href');return false;});});}});})(jQuery);(function($){$.fn.extend({tooltip:function(){return $(this).each(function(){var $div=$(document.createElement('div'));var $tooltip_icon=$(this);var text=$tooltip_icon.attr('title');$tooltip_icon.attr('title','');$div.text(text);$div.hide();$(this).hover(function(){var $tooltip_icon=$(this);var bottom=$tooltip_icon.position().top+parseInt($tooltip_icon.height())+3;var left=$tooltip_icon.position().left+parseInt($tooltip_icon.width())+3;$div.insertAfter($tooltip_icon);$div.css('display','block').css('position','absolute').css('top',bottom).css('left',left).addClass('tooltip_on');$div.show();},function(){$div.hide();});});}});})(jQuery);(function($){$.fn.extend({setValidation:function(validation_function){return this.each(function(){$(this).data('validation_function',validation_function);});},getValidation:function(){var validate_me=$(this).data('validation_function');if(false==$.isFunction(validate_me)){validate_me=function(value){var valid_field=true;if(""==$.trim(value)){valid_field=false;}
return valid_field;}}
return validate_me;},isValid:function(){var value=$(this).val();return $(this).getValidation()(value);},validate:function(options){var defaults={required_selector:'.required_field',required_failed_class:'validation_failed',error_message:'.form_error',validation_failed:function($failed_field){},callback:null};var final_options=$.extend(defaults,options);return this.each(function(){$(this).find(final_options['error_message']).hide();$(this).unbind('submit');$(this).bind('submit',function(){var valid_form=true;$(this).find(final_options['required_selector']).each(function(){if(true==$(this).is(':not(:disabled)')){if(false==$(this).isValid()){$(this).addClass(final_options['required_failed_class']);final_options['validation_failed']($(this));valid_form=false;}else{$(this).removeClass(final_options['required_failed_class']);}}});$(this).find(final_options['error_message']).hide();if(false==valid_form){var $error_message=$(this).find(final_options['error_message']);$error_message.show();if($error_message.length>0){if($(window).scrollTop()>$error_message.position().top){$(window).scrollTop($error_message.position().top-10);}}}else{if(true==$.isFunction(final_options.callback)){valid_form=final_options.callback();}}
return valid_form;});});}});$.validate_integer=function(){return function(value){var valid=false;if(value.match(/^\-?\d+$/)){valid=true;}
if(false==valid){alert("Value must be an integer.");}
return valid;};};$.validate_decimal=function(){return function(value){var valid=false;if(value.match(/^\-?\d+(\.\d{1,2})?$/)){valid=true;}
if(false==valid){alert("Value must be a decimal number.");}
return valid;};};})(jQuery);$(document).ready(function(){$("a.attribute_link, a.attribute_value_link").attribute_link();});(function($){$.fn.extend({tagName:function(){var tag_name=null;this.each(function(){tag_name=this.tagName.toLowerCase();});return tag_name;}})})(jQuery);(function($){$.htmlPopup=function(html,options){var settings=$.extend({height:'250',width:'500',close_selector:'.close_popup',top:null},options);var $fade=$(document.createElement('div'));$fade.css('position','absolute').css('z-index','999').css('background-color','#aaa').css('width','100%').css('height',$(document).height()+'px').css('opacity','0.6').hide();var $popup=$(document.createElement('div'));var pop_top=parseInt((parseInt($(window).height())-parseInt(settings.height))/2);pop_top+=parseInt($(window).scrollTop());if(null!==settings.top){pop_top=parseInt(settings.top)+parseInt($(window).scrollTop());}
var pop_left=parseInt((parseInt($('body').width())-parseInt(settings.width))/2)-26;$popup.addClass('popup').css('position','absolute').css('left',parseInt(pop_left)+'px').css('width',settings.width+'px').css('background','#fff').css('z-index','1000').css('-moz-border-radius','10px').css('-webkit-border-radius','10px').css('top',pop_top+'px').css('opacity','1.0').prependTo($('body')).hide();$popup.html(html);$popup.fadeIn('fast');$fade.prependTo($('body')).fadeIn('fast');$fade.click(function(){$.closePopup($popup,$fade);});$(document).keyup(function(e){if(e.keyCode==27){$.closePopup($popup,$fade);}});$popup.find(settings.close_selector).live('click',function(){$.closePopup($popup,$fade);return false;});};$.popup=function(url,options){$.get(url,null,function(data){$.htmlPopup(data,options);},'html');};$.closePopup=function($pop,$fade){$($pop).add($fade).fadeOut('fast',function(){$(this).remove();});};})(jQuery);(function($){$.addProduct=function(product_id,quantity,callback){var data={'product_id':product_id,'quantity':quantity};$.post('/cart/add_product_post',data,function(data){if($.isFunction(callback)){callback(data);}},'json');};})(jQuery);(function($){$.fn.extend({paginateData:function(url){return this.each(function(){var $obj=$(this);$obj.load(url,function(){$obj.find('.Paging a, a.sort_link').live('click',function(){var load_url=url+$(this).attr('href');$obj.load(load_url);return false;});});});}});})(jQuery);jQuery.fn.fadeToggle=function(speed,easing,callback){return this.animate({opacity:'toggle'},speed,easing,callback);};
