
jQuery.tableDnD={currentTable:null,dragObject:null,mouseOffset:null,oldY:0,build:function(options){this.each(function(){this.tableDnDConfig=jQuery.extend({onDragStyle:null,onDropStyle:null,onDragClass:"tDnD_whileDrag",onDrop:null,onDragStart:null,scrollAmount:5,serializeRegexp:/[^\-]*$/,serializeParamName:null,dragHandle:null},options||{});jQuery.tableDnD.makeDraggable(this);});jQuery(document).bind('mousemove',jQuery.tableDnD.mousemove).bind('mouseup',jQuery.tableDnD.mouseup);return this;},makeDraggable:function(table){var config=table.tableDnDConfig;if(table.tableDnDConfig.dragHandle){var cells=jQuery("td."+table.tableDnDConfig.dragHandle,table);cells.each(function(){jQuery(this).mousedown(function(ev){jQuery.tableDnD.dragObject=this.parentNode;jQuery.tableDnD.currentTable=table;jQuery.tableDnD.mouseOffset=jQuery.tableDnD.getMouseOffset(this,ev);if(config.onDragStart){config.onDragStart(table,this);}
return false;});})}else{var rows=jQuery("tr",table);rows.each(function(){var row=jQuery(this);if(!row.hasClass("nodrag")){row.mousedown(function(ev){if(ev.target.tagName=="TD"){jQuery.tableDnD.dragObject=this;jQuery.tableDnD.currentTable=table;jQuery.tableDnD.mouseOffset=jQuery.tableDnD.getMouseOffset(this,ev);if(config.onDragStart){config.onDragStart(table,this);}
return false;}}).css("cursor","move");}});}},updateTables:function(){this.each(function(){if(this.tableDnDConfig){jQuery.tableDnD.makeDraggable(this);}})},mouseCoords:function(ev){if(ev.pageX||ev.pageY){return{x:ev.pageX,y:ev.pageY};}
return{x:ev.clientX+document.body.scrollLeft-document.body.clientLeft,y:ev.clientY+document.body.scrollTop-document.body.clientTop};},getMouseOffset:function(target,ev){ev=ev||window.event;var docPos=this.getPosition(target);var mousePos=this.mouseCoords(ev);return{x:mousePos.x-docPos.x,y:mousePos.y-docPos.y};},getPosition:function(e){var left=0;var top=0;if(e.offsetHeight==0){e=e.firstChild;}
while(e.offsetParent){left+=e.offsetLeft;top+=e.offsetTop;e=e.offsetParent;}
left+=e.offsetLeft;top+=e.offsetTop;return{x:left,y:top};},mousemove:function(ev){if(jQuery.tableDnD.dragObject==null){return;}
var dragObj=jQuery(jQuery.tableDnD.dragObject);var config=jQuery.tableDnD.currentTable.tableDnDConfig;var mousePos=jQuery.tableDnD.mouseCoords(ev);var y=mousePos.y-jQuery.tableDnD.mouseOffset.y;var yOffset=window.pageYOffset;if(document.all){if(typeof document.compatMode!='undefined'&&document.compatMode!='BackCompat'){yOffset=document.documentElement.scrollTop;}
else if(typeof document.body!='undefined'){yOffset=document.body.scrollTop;}}
if(mousePos.y-yOffset<config.scrollAmount){window.scrollBy(0,-config.scrollAmount);}else{var windowHeight=window.innerHeight?window.innerHeight:document.documentElement.clientHeight?document.documentElement.clientHeight:document.body.clientHeight;if(windowHeight-(mousePos.y-yOffset)<config.scrollAmount){window.scrollBy(0,config.scrollAmount);}}
if(y!=jQuery.tableDnD.oldY){var movingDown=y>jQuery.tableDnD.oldY;jQuery.tableDnD.oldY=y;if(config.onDragClass){dragObj.addClass(config.onDragClass);}else{dragObj.css(config.onDragStyle);}
var currentRow=jQuery.tableDnD.findDropTargetRow(dragObj,y);if(currentRow){if(movingDown&&jQuery.tableDnD.dragObject!=currentRow){jQuery.tableDnD.dragObject.parentNode.insertBefore(jQuery.tableDnD.dragObject,currentRow.nextSibling);}else if(!movingDown&&jQuery.tableDnD.dragObject!=currentRow){jQuery.tableDnD.dragObject.parentNode.insertBefore(jQuery.tableDnD.dragObject,currentRow);}}}
return false;},findDropTargetRow:function(draggedRow,y){var rows=jQuery.tableDnD.currentTable.rows;for(var i=0;i<rows.length;i++){var row=rows[i];var rowY=this.getPosition(row).y;var rowHeight=parseInt(row.offsetHeight)/2;if(row.offsetHeight==0){rowY=this.getPosition(row.firstChild).y;rowHeight=parseInt(row.firstChild.offsetHeight)/2;}
if((y>rowY-rowHeight)&&(y<(rowY+rowHeight))){if(row==draggedRow){return null;}
var config=jQuery.tableDnD.currentTable.tableDnDConfig;if(config.onAllowDrop){if(config.onAllowDrop(draggedRow,row)){return row;}else{return null;}}else{var nodrop=jQuery(row).hasClass("nodrop");if(!nodrop){return row;}else{return null;}}
return row;}}
return null;},mouseup:function(e){if(jQuery.tableDnD.currentTable&&jQuery.tableDnD.dragObject){var droppedRow=jQuery.tableDnD.dragObject;var config=jQuery.tableDnD.currentTable.tableDnDConfig;if(config.onDragClass){jQuery(droppedRow).removeClass(config.onDragClass);}else{jQuery(droppedRow).css(config.onDropStyle);}
jQuery.tableDnD.dragObject=null;if(config.onDrop){config.onDrop(jQuery.tableDnD.currentTable,droppedRow);}
jQuery.tableDnD.currentTable=null;}},serialize:function(){if(jQuery.tableDnD.currentTable){return jQuery.tableDnD.serializeTable(jQuery.tableDnD.currentTable);}else{return"Error: No Table id set, you need to set an id on your table and every row";}},serializeTable:function(table){var result="";var tableId=table.id;var rows=table.rows;for(var i=0;i<rows.length;i++){if(result.length>0)result+="&";var rowId=rows[i].id;if(rowId&&rowId&&table.tableDnDConfig&&table.tableDnDConfig.serializeRegexp){rowId=rowId.match(table.tableDnDConfig.serializeRegexp)[0];}
result+=tableId+'[]='+rowId;}
return result;},serializeTables:function(){var result="";this.each(function(){result+=jQuery.tableDnD.serializeTable(this);});return result;}}
jQuery.fn.extend({tableDnD:jQuery.tableDnD.build,tableDnDUpdate:jQuery.tableDnD.updateTables,tableDnDSerialize:jQuery.tableDnD.serializeTables});


(function(jQuery){jQuery.each(['backgroundColor','borderBottomColor','borderLeftColor','borderRightColor','borderTopColor','color','outlineColor'],function(i,attr){jQuery.fx.step[attr]=function(fx){if(fx.state==0){fx.start=getColor(fx.elem,attr);fx.end=getRGB(fx.end);}
fx.elem.style[attr]="rgb("+[Math.max(Math.min(parseInt((fx.pos*(fx.end[0]-fx.start[0]))+fx.start[0]),255),0),Math.max(Math.min(parseInt((fx.pos*(fx.end[1]-fx.start[1]))+fx.start[1]),255),0),Math.max(Math.min(parseInt((fx.pos*(fx.end[2]-fx.start[2]))+fx.start[2]),255),0)].join(",")+")";}});function getRGB(color){var result;if(color&&color.constructor==Array&&color.length==3)
return color;if(result=/rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
return[parseInt(result[1]),parseInt(result[2]),parseInt(result[3])];if(result=/rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
return[parseFloat(result[1])*2.55,parseFloat(result[2])*2.55,parseFloat(result[3])*2.55];if(result=/#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
return[parseInt(result[1],16),parseInt(result[2],16),parseInt(result[3],16)];if(result=/#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
return[parseInt(result[1]+result[1],16),parseInt(result[2]+result[2],16),parseInt(result[3]+result[3],16)];return colors[jQuery.trim(color).toLowerCase()];}
function getColor(elem,attr){var color;do{color=jQuery.curCSS(elem,attr);if(color!=''&&color!='transparent'||jQuery.nodeName(elem,"body"))
break;attr="backgroundColor";}while(elem=elem.parentNode);return getRGB(color);};})(jQuery);


(function($){function toIntegersAtLease(n)
{return n<10?'0'+n:n;}
Date.prototype.toJSON=function(date)
{return date.getUTCFullYear()+'-'+
toIntegersAtLease(date.getUTCMonth()+1)+'-'+
toIntegersAtLease(date.getUTCDate());};var escapeable=/["\\\x00-\x1f\x7f-\x9f]/g;var meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'}
$.quoteString=function(string)
{if(escapeable.test(string))
{return'"'+string.replace(escapeable,function(a)
{var c=meta[a];if(typeof c==='string'){return c;}
c=a.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+(c%16).toString(16);})+'"'}
return'"'+string+'"';}
$.toJSON=function(o,compact)
{var type=typeof(o);if(type=="undefined")
return"undefined";else if(type=="number"||type=="boolean")
return o+"";else if(o===null)
return"null";if(type=="string")
{return $.quoteString(o);}
if(type=="object"&&typeof o.toJSON=="function")
return o.toJSON(compact);if(type!="function"&&typeof(o.length)=="number")
{var ret=[];for(var i=0;i<o.length;i++){ret.push($.toJSON(o[i],compact));}
if(compact)
return"["+ret.join(",")+"]";else
return"["+ret.join(", ")+"]";}
if(type=="function"){throw new TypeError("Unable to convert object of type 'function' to json.");}
ret=[];for(var k in o){var name;var type=typeof(k);if(type=="number")
name='"'+k+'"';else if(type=="string")
name=$.quoteString(k);else
continue;val=$.toJSON(o[k],compact);if(typeof(val)!="string"){continue;}
if(compact)
ret.push(name+":"+val);else
ret.push(name+": "+val);}
return"{"+ret.join(", ")+"}";}
$.compactJSON=function(o)
{return $.toJSON(o,true);}
$.evalJSON=function(src)
{return eval("("+src+")");}
$.secureEvalJSON=function(src)
{var filtered=src;filtered=filtered.replace(/\\["\\\/bfnrtu]/g,'@');filtered=filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']');filtered=filtered.replace(/(?:^|:|,)(?:\s*\[)+/g,'');if(/^[\],:{}\s]*$/.test(filtered))
return eval("("+src+")");else
throw new SyntaxError("Error parsing JSON, source is not valid.");}})(jQuery);


jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1;}
var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}
expires='; expires='+date.toUTCString();}
var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}
return cookieValue;}};


submit_feedback=function(){data={view:'ajax',xaction:'submit_feedback',email:$('#feedback_form_email').val(),comment:$('#feedback_form_comment').val(),yname:$('#feedback_form_yname').val()}
$('#feedback_form_elements').fadeOut('def',function(){$('#feedback_form_waiting').fadeIn();$.ajax({type:'POST',url:'index.html',data:data,success:function(msg){rv=$.evalJSON(msg);if(rv.status!='SUCCESS'){alert(rv.message);$('#feedback_form_waiting').fadeOut('def',function(){$('#feedback_form_elements').fadeIn();});}else{$('#feedback_form_waiting').fadeOut('def',function(){$('#feedback_form_success').fadeIn('def',function(){$('#feedback_form_comment').val(' ');setTimeout("$('#feedback_form').ht_lightbox('close');",3000);setTimeout("$('#feedback_form_success').hide();",3300);setTimeout("$('#feedback_form_elements').show();",3300);});});}}});});}
$.fn.ht_lightbox=function(options){if(options=='close'){$('.ht_lightbox_show_button').remove();$('#zoofade').fadeOut();$('.ht_lightbox').fadeOut();return $(this);}
var opts=$.extend({},$.fn.ht_lightbox.defaults,options);var $doc=$(document);$('#zoofade').css({width:$doc.width(),height:$doc.height(),opacity:0.7}).fadeIn();return this.each(function(){var $this=$(this);$this.addClass('ht_lightbox');$this.addClass(opts.class_name);if(opts.show_button){$this.append('<div class="ht_lightbox_buttons ht_lightbox_show_button"><input type="button" value="'+
opts.button_value+'" onclick="$(this).ht_lightbox(\'close\');" /></div>');}
$this.css({left:$doc.width()/2-$this.width()/2,top:$(window).scrollTop()+100,zIndex:$('#zoofade').css('zIndex')+1}).fadeIn();});}
$.fn.ht_lightbox.defaults={button_value:'Ok',class_name:'',show_button:1};$.fn.ht_flow=function(options){var opts=$.extend({},$.fn.ht_flow.defaults,options);var $doc=$(document);var heading=$(this).children('ul:first');heading.addClass('ht_flow_heading');var list_items=heading.children('li');list_items.addClass('ht_flow_heading');list_items.removeClass('ht_flow_heading_selected');var first_list_item=heading.children('li:first');first_list_item.addClass('ht_flow_heading_first');var flow_steps=$(this).children('div');var _step_offset=0;if(opts.show_step=='_next'){var _visible=$(this).children('div:visible');opts.show_step=_visible.attr('id');_step_offset=1;}else if(opts.show_step=='_prev'){var _visible=$(this).children('div:visible');opts.show_step=_visible.attr('id');_step_offset=-1;}
var current_step_index=0;var step_ids=new Array;for(var i=0;i<flow_steps.length;i++){step_ids.push(flow_steps[i].id);if(flow_steps[i].id==opts.show_step){current_step_index=i;}}
current_step_index=current_step_index+_step_offset;var current_step_id=step_ids[current_step_index];_flow_current_step=current_step_id;preload_function='preload_'+_flow_current_step;if(typeof(window[preload_function])=='function'){window[preload_function]();}
flow_steps.hide();var current_step=$(this).children('div:eq('+current_step_index+')');heading.children('li:eq('+current_step_index+')').addClass('ht_flow_heading_selected');current_step.css({'marginTop':20}).show();postload_function='postload_'+_flow_current_step;if(typeof(window[postload_function])=='function'){window[postload_function]();}
return this.each(function(){var $this=$(this);$this.addClass('ht_flow');});}
$.fn.ht_flow.defaults={show_step:''};var _help_lightbox;var _help_lightbox_html;jQuery.fn.help_lightbox=function(options){if(options=='close'){$('.help_lightbox_blackout').fadeOut().remove();$('.help_lightbox_wrapper').fadeOut().remove();_help_lightbox.html(_help_lightbox_html);return $(this);}
var opts=$.extend({},$.fn.help_lightbox.defaults,options);return this.each(function(){$('body').append('<div class="help_lightbox_blackout">&nbsp;</div>'+'<div class="help_lightbox_wrapper">'+' <div class="help_lightbox_close"><a href="javascript:void(0);" class="help_lightbox_close_link">Close X</a></div>'+' <div class="help_lightbox_top">BookFresh Help Topics</div>'+' <div class="help_lightbox_title">'+opts.title+'</div>'+' <div class="help_lightbox_content"></div>'+'</div>');$('.help_lightbox_close_link').bind('click',function(){$(this).help_lightbox('close');});$('.help_lightbox_blackout').css({'height':$(document).height(),'width':$(document).width()});_help_lightbox=$(this);_help_lightbox_html=$(this).html();$('.help_lightbox_content').html(_help_lightbox_html);_help_lightbox.html('&nbsp;');var _left=Math.round(($(document).width()-opts.width)/2);if(_left<0){_left=50;}
$('.help_lightbox_wrapper').css({'width':opts.width,'top':$(window).scrollTop()+50,'left':_left}).fadeIn('def',function(){});});}
$.fn.help_lightbox.defaults={width:750,title:'This is the help title'};


jQuery.fn.carousel=function(options){return this.each(function(){var carousel=$(this);var slides=carousel.find("li");var tabs=$(options.nav).find(".link");var currentIndex=0;var locked=false;var autostart_interval;var autostart_counter=0;var moveToSlide=function(index){locked=true;var l=(slides[0].clientWidth)*index;carousel.animate({marginLeft:"-"+l+"px"},"slow","swing");currentIndex=index;activateTab(index);};var activateTab=function(index){if(options.navSelected){index+=2;$(options.nav).find("dd a").show();$(options.nav).find("dd:nth-child("+index+") a").fadeOut("fast");$(options.navSelected).find("dd").animate({marginTop:"0px"},"fast","swing");var activeTab=$(options.navSelected).find("dd:nth-child("+index+")");activeTab.animate({marginTop:"-100px"},"fast","swing").animate({marginTop:"-75px"},"fast","swing").animate({marginTop:"-85px"},"fast","swing",function(){locked=false;});}else{index++;$("dd.selected").removeClass("selected");$(options.nav).find("dd:nth-child("+index+")").addClass("selected");locked=false;}};var next=function(){if(currentIndex==tabs.length-1){currentIndex=0;autostart_counter++;if(autostart_interval&&autostart_counter>=options.autostart){clearInterval(autostart_interval);}}else{currentIndex++;}
moveToSlide(currentIndex);return false;}
if(options.previous){$(options.previous).click(function(){clearInterval(autostart_interval);if(locked==true){return false;}
if(currentIndex==0){currentIndex=tabs.length-1;}else{currentIndex--;}
moveToSlide(currentIndex);return false;});}
if(options.next){$(options.next).click(function(){clearInterval(autostart_interval);if(locked==true){return false;}
next();return false;});}
if(options.autostart){autostart_interval=setInterval(function(){next();},6000);}
tabs.click(function(){clearInterval(autostart_interval);for(i=0;i<tabs.length;i++){var tab=tabs[i];if(tab==this){moveToSlide(i);return false;}}
return false;});});};

