
(function($)
{$.extend({builder:{keys:[],multi:{two:{th:{regex:/QA|AQ/g,icon:"throw"},fo:{regex:/WS|SW/g,icon:"focus"},ta:{regex:/ED|DE/g,icon:"taunt"},pex:{regex:/QW|WQ|QE|EQ|WE|EW/g,icon:"pex"},kex:{regex:/AS|SA|AD|DA|SD|DS/g,icon:"kex"}},three:{ppp:{regex:/QWE|QEW|WQE|WEQ|EQW|EWQ/g,icon:"ppp"},kkk:{regex:/ASD|ADS|SAD|SDA|DAS|DSA/g,icon:"kkk"}}},interval:100,timestamp:1000,delay:function(obj)
{var o=typeof(obj)=="string"?eval(obj):$(obj);$("#Builder #Delay img").removeClass("on");$("#Builder #Delay img").each(function()
{if($(this).attr("alt")==o.attr("alt"))
{$(this).addClass("on");$.builder.interval=parseInt(o.attr("alt"));}});},stick:function(obj)
{var o=typeof(obj)=="string"?eval(obj):$(obj);var dir=false;if(o.attr("class")=="on")
{o.removeClass("on");dir=o.attr("alt");}
else
{$("#Builder #Directions #Standard img").each(function()
{if($(this).attr("class")=="on")
{dir=$(this).attr("alt");}});$("#Builder #Directions #Standard img").removeClass("on");o.addClass("on");}
this.add(obj,dir);},add:function(obj,dir)
{var o=typeof(obj)=="string"?eval(obj):$(obj);if(!dir||dir!=o.attr("alt")){this.output(o.attr("alt"));}
var item=o.attr("item");var action=o.attr("action");if(!action){action=o.attr("alt");}
this.timestamp+=this.interval;if(!this.keys[this.timestamp]){this.keys[this.timestamp]=[];}
if(item.length>1&&item!="Stick")
{var items=item.split("");for(n=0;n<items.length;n++)
{this.keys[this.timestamp].push({item:items[n],action:action});if(action=="press")
{release=(this.timestamp+99);if(!this.keys[release]){this.keys[release]=[];}
this.keys[release].push({item:items[n],action:"release"});}}
this.combo(this.keys[this.timestamp],this.timestamp);}
else
{if(item=="Stick")
{if(dir)
{var release=(this.timestamp+101);if(!this.keys[release]){this.keys[release]=[];}
this.keys[release].push({item:item,action:"release-"+dir});}}
else if(action=="press")
{this.keys[this.timestamp].push({item:item,action:action});var release=(this.timestamp+99);if(!this.keys[release]){this.keys[release]=[];}
this.keys[release].push({item:item,action:"release"});}}},output:function(icon)
{$("#Builder #Output div").append("<img src=\"images/icons/"+icon+".png\" />");$("#Builder #Output div").css({width:($("#Output div img").length*24)});},combo:function(keys,timestamp)
{var stack="";for(var i in keys)
{stack+=keys[i].item;}
var multi=stack.length==3?this.multi.three:this.multi.two;for(var i in multi)
{if(multi[i].regex.test(stack))
{var icon=multi[i].icon;var length=stack.length;this.keys[timestamp]=Array({item:stack,action:"press",icon:icon});break;}}},backspace:function()
{$("#Builder #Output div img").filter(':last').remove();var last=false;for(var prop in this.keys){last=prop;}
if(last){delete this.keys[last];}},clear:function()
{$("#Builder #Output div img").remove();this.keys=[];},run:function()
{if(this.keys.length>0)
{linkCode="";for(var timestamp in this.keys)
{actions=this.keys[timestamp];for(var action in actions)
{var move=actions[action];switch(move['action'])
{case"press":case"release":var icon=!move["icon"]?false:move['icon'];linkCode+=timestamp+"|"+move['item']+"|"+move['action'];if(icon.length>0){linkCode+="|"+icon;}
break;default:linkCode+=timestamp+"|"+move['item']+"|"+move['action'];break;}
linkCode+=",";}}
linkCode=linkCode.slice(0,-1);$("#Menu .last").trigger('click');var saved=linkCode.split(",");$.fightstick.linked(saved);}
else
{alert("Please enter some actions");}},export:function()
{var htmlCode,bbCode,linkCode;linkCode="";htmlCode=$("#Builder #Output div").html();htmlCode=htmlCode.replace(/(images)/g,"http://fightstick.fakesite.com/images");bbCode=htmlCode;bbCode=bbCode.replace(/(<img src=\")/g,"[IMG]");bbCode=bbCode.replace(/(\">)/g,"[/IMG]");htmlCode=htmlCode.replace(/(<)/g,"&lt;");htmlCode=htmlCode.replace(/(>)/g,"&gt;");$("#Builder #htmlCode").html(htmlCode);$("#Builder #bbCode").html(bbCode);$("#Builder #linkCode").html(linkCode);$("#Builder #Message .super").hide();$("#Builder #Message .save").show();$("#Builder #Message").fadeIn('fast');}}});})(jQuery);
