/******************************************************************************
                  ____ _ _         _     _  __        _  __
                 / ___(_) |_ _   _| |   (_)/ _| ___  | |/ / ____
                | |   | | __| | | | |   | | |_ / _ \ | ' / |_  /
                | |___| | |_| |_| | |___| |  _|  __/_| . \  / /
                 \____|_|\__|\__, |_____|_|_|  \___(_)_|\_\/___|
                             |___/

          2008-2010 (C) Innovation Group, Astana, Kazakhstan
******************************************************************************/

(function(a){a.mouse={x:0,y:0,refresh:function(b){b=(b||window.event);h=a.browser.opera?window.innerHeight:a(window).height();this.x=b.pageX?b.pageX:b.clientX+a(window).scrollLeft()-document.body.clientLeft;this.y=b.pageY?b.pageY:b.clientY+a(window).scrollTop()-h;return this}}})(jQuery);jQuery.extend(jQuery.mouse);(function(jQuery){jQuery.touch={current_slave_e:"",general:{placeout:false,x0:0,y0:0,master_e:Array(),master_o:Array(),slave_e:Array(),slave_o:Array()},sParams:{name:"",type:"",moveby:{x:true,y:true},onTouchStart:null,onTouching:null,onTouchEnd:null},set:function(_master_e,_slave_e,options){var id=jQuery(_master_e).attr("id");this.general.master_e[id]=_master_e;this.general.master_o[id]=jQuery(_master_e);this.general.slave_e[id]=_slave_e;this.general.slave_o[id]=jQuery(_slave_e);jQuery(document).unbind("mousemove").bind("mousemove",function(ev){jQuery.mouse.refresh(ev);jQuery.touch.touching();return false}).unbind("mouseup").bind("mouseup",function(){jQuery.touch.end_touch();return false});if(options!=undefined&&options.type){this.general.slave_o[id].addClass(options.type)}this.general.master_o[id].unbind("mousedown").bind("mousedown",function(){if(options){switch(options.moveby){case"x":_moveby={x:true,y:false};break;case"y":_moveby={x:false,y:true};break;default:_moveby={x:true,y:true}}jQuery.touch.sParams={type:"",moveby:_moveby,onTouchStart:options.onTouchStart,onTouching:options.onTouching,onTouchEnd:options.onTouchEnd};jQuery.extend(jQuery.touch.sParams,jQuery.touch.sParams)}jQuery.touch.current_slave_e=id;return jQuery.touch.start_touch()});return this},start_touch:function(id){var p=this.general.slave_o[this.current_slave_e].offset();this.general.x0=p.left-jQuery.mouse.x;this.general.y0=p.top-jQuery.mouse.y;this.general.placeout=true;this.general.slave_o[this.current_slave_e].css({position:"absolute"}).addClass("ontouch");var o={master:this.general.master_o[this.current_slave_e],slave:this.general.slave_o[this.current_slave_e],listing:this.collision.listing};if(jQuery.touch.sParams.onTouchStart){jQuery.touch.sParams.onTouchStart(o)}return false},end_touch:function(){if(jQuery.touch.general.placeout){this.general.placeout=false;if(this.general.slave_o[this.current_slave_e]){this.general.slave_o[this.current_slave_e].removeClass("ontouch")}var o={master:this.general.master_o[this.current_slave_e],slave:this.general.slave_o[this.current_slave_e],listing:this.collision.listing};if(jQuery.touch.sParams.onTouchEnd){jQuery.touch.sParams.onTouchEnd(o)}}return false},touching:function(){if(this.general.placeout){var _left=jQuery.mouse.x+this.general.x0+"px";var _top=jQuery.mouse.y+this.general.y0+"px";if(this.sParams.moveby.x){this.general.slave_o[this.current_slave_e].css({left:_left})}if(this.sParams.moveby.y){this.general.slave_o[this.current_slave_e].css({top:_top})}var o={master:this.general.master_o[this.current_slave_e],slave:this.general.slave_o[this.current_slave_e],listing:this.collision.listing};this.collision.test();if(jQuery.touch.sParams.onTouching){jQuery.touch.sParams.onTouching(o)}}return false},collision:{types:Array(),collided:false,define:function(_type_a,_type_b,options){if(options!=undefined){if(options.range){with(options){range={left:range,right:range,top:range,bottom:range}}}else{options.range={left:options.left?options.left:0,right:options.right?options.right:0,top:options.top?options.top:0,bottom:options.bottom?options.bottom:0}}}else{with(options){onBlow=onPass=null;range={left:0,right:0,top:0,bottom:0}}}this.types[_type_a]={a:_type_a,b:_type_b,now:options.onBlow,pass:options.onPass,range:options.range}},listing:{a:{left:0,top:0,width:0,height:0},b:{left:0,top:0,width:0,height:0}},test:function(){for(j in this.types){var oA=jQuery.touch.general.slave_o[jQuery.touch.current_slave_e];if(oA.hasClass(this.types[j].a)){var pA=oA.offset();jQuery("."+jQuery.touch.collision.types[j].b).each(function(){if(oA.attr("id")!=jQuery(this).attr("id")){var pB=jQuery(this).offset();var oB=jQuery(this);jQuery.touch.collision.listing={a:{left:pA.left,top:pA.top,width:oA.innerWidth(),height:oA.innerHeight()},b:{left:pB.left,top:pB.top,width:oB.innerWidth(),height:oB.innerHeight()}};if((pA.left>=(pB.left-oA.innerWidth()-jQuery.touch.collision.types[j].range.left))&&((pA.left+oA.innerWidth())<=(pB.left+oB.innerWidth()+oA.innerWidth()+jQuery.touch.collision.types[j].range.right))&&(pA.top>=(pB.top-oA.innerHeight()-jQuery.touch.collision.types[j].range.top))&&((pA.top+oA.innerHeight())<=(pB.top+oB.innerHeight()+oA.innerHeight()+jQuery.touch.collision.types[j].range.bottom))){if(jQuery.touch.collision.collided){return true}var o={master:jQuery.touch.general.master_o[jQuery.touch.current_slave_e],slave:jQuery.touch.general.slave_o[jQuery.touch.current_slave_e],target:oB};if(jQuery.touch.collision.types[j].now){jQuery.touch.collision.types[j].now(o)}return jQuery.touch.collided=true}else{jQuery.touch.collision.collided=false;var o={master:jQuery.touch.general.master_o[jQuery.touch.current_slave_e],slave:jQuery.touch.general.slave_o[jQuery.touch.current_slave_e],target:oB};if(jQuery.touch.collision.types[j].pass){jQuery.touch.collision.types[j].pass(o)}}}})}}return false}}}})(jQuery);jQuery.extend(jQuery.touch);