/*
 * jQuery Mousepotato Library v1.0.0
 * http://www.themousepotatowebsite.co.za
 *
 */
(function($){var methods={clearform:function(){return $(this).each(function(){$(this).find("input").filter("[type='text']").attr("value","").filter("[type='checkbox'||type='radio']]").attr("checked",false).end().find("textarea").html("")})},call:function(fn,args,callback,errorCallback,options){var settings={action:$.mousepotato.call_action,};$.extend(settings,options||{});return jQuery.ajax({url:settings.action,data:{fn:fn,args:args||[]},dataType:"json",type:"post",success:function(data){if(!callback){return}try{if(!data){throw"Recieved empty reponse"}if(data.state!="OK"){throw data.message}if(callback){callback.apply(this,[$.parseJSON(data.result)])}}catch(ex){if(errorCallback){errorCallback.apply(this,[ex])}}},error:errorCallback})},dialog:function(title,content,buttons,options){buttons=buttons||{OK:$.mousepotato.dialog_closeFn};var settings={autoOpen:true,title:title,buttons:buttons,okButton:null,zIndex:9999,};$.extend(settings,options||{});if(settings.okButton&&"OK" in settings.buttons){$.extend(settings.buttons,{OK:function(){settings.okButton.call(this);$.mousepotato.dialog_closeFn.call(this)}})}return $("<div></div>").html(content).dialog(settings)},parseurl:function(url){url=url||"";function parseQuery(url){if((pos=url.search(/\?/g))<0){return null}var query={},e,a=/\+/g,r=/([^&=]+)=?([^&]*)/g,d=function(s){return decodeURIComponent(s.replace(a," "))},q=url.substring(pos+1);while(e=r.exec(q)){query[d(e[1])]=d(e[2])}return query}function getProtocol(url){if((pos=url.search(/\:/g))<0){return""}return url.substring(0,pos)}function getHostAndPath(url){var host=url;if((pos=url.search(/\:\/\//g))<0){return[host,""]}host=host.substring(pos+3);if((pos=host.search(/[\/|\?]+/g))<0){return[host,""]}var path=host.substring(pos+1,host.length);if((pos2=path.search(/[^\/a-zA-Z0-9_\.]/g))>=0){path=path.substring(0,pos2)}return[host.substring(0,pos),path]}function getHash(url){if((pos=url.search(/\#/g))<0){return""}var hash=url.substring(pos+1);if((pos=hash.search(/[^a-zA-Z_]/g))<0){return hash}return hash.substring(0,pos)}hostAndPath=getHostAndPath(url);return{protocol:getProtocol(url),host:hostAndPath[0],query:parseQuery(url),path:hostAndPath[1],hash:getHash(url),url:url}},includescript:function(filename,options){var settings={before:null,baseDir:"./",insertTo:"body"};$.extend(settings,options);var script=document.createElement("script");script.type="text/javascript";script.src=settings.baseDir+filename;var elem=document.getElementsByTagName(settings.insertTo)[0];if(settings.before){beforeNode=$('script[src^="'+settings.baseDir+settings.before+'"]').get(0);if(beforeNode){elem.insertBefore(script,beforeNode);return}}elem.appendChild(script)},parsehash:function(hash){hash=hash||window.location.hash||"#";hash=hash.substring(hash.search("#")+1);parts=hash.split("&");result={__strings:[]};$.each(parts,function(i,item){item=item.split("=",2);if(item.length<2){result.__strings.push(item[0]);return}eval("result."+item[0]+'="'+item[1]+'"')});return result},youtube:function(url,callback){var url=methods.parseurl(url);if(!(url&&url.host&&url.host.search(/youtube\.com/g)>=0&&(url.query&&"v" in url.query&&url.query.v.length>0))){if(callback){callback.apply(this,[null])}return false}if(!callback){return url}var vid=url.query.v;$.ajax({url:"http://gdata.youtube.com/feeds/api/videos/"+vid+"?v=2&alt=json",method:"get",data:{v:2,alt:"json"},success:function(data){if(!data.entry){callback.apply(this,[null]);return}callback.apply(this,[{title:data.entry.title.$t,thumbnails:data.entry.media$group.media$thumbnail,author:data.entry.author[0].name.$t,category:data.entry.media$group.media$category[0].$t,description:data.entry.media$group.media$description.$t,rating:(data.entry.gd$rating)?data.entry.gd$rating.average:NaN,viewcount:(data.entry.yt$statistics)?parseInt(data.entry.yt$statistics.viewCount):NaN,videoId:vid,}])},error:function(){}})},scrolltrack:function(options){var settings={elem:window,scrollIn:null,scrollOut:null,offset:{top:0,bottom:0},};$.extend(settings,options);var $this=this;$(settings.elem).scroll(function(){var windowY=$(settings.elem).scrollTop();var windowHeight=$(settings.elem).height();$this.each(function(i,o){var mid=windowY+(windowHeight/2);var itemHeight=$(this).height();var itemPos=$(this).position();if(mid>itemPos.top+settings.offset.top&&mid<(itemPos.top+itemHeight-settings.offset.bottom)){if(settings.scrollIn){settings.scrollIn.apply(this,[i])}}else{if(settings.scrollOut){settings.scrollOut.apply(this,[i])}}})});return this},gallery:function(options){var settings={random:false,delay:1000,startAt:0,fadeSpeed:700,};$.extend(settings,options||{});return this.each(function(){var gImages=$("img",this).hide();$(gImages.get(settings.startAt)).fadeIn(settings.fadeSpeed/2);var _gallery=function(i){i=(typeof i!="undefined")?i:settings.startAt;setTimeout(function(){var $image=$(gImages.get(i));var changeImg=function(){$image.fadeOut(settings.fadeSpeed);i=(settings.random)?Math.floor(Math.rand()*gImages.length):(i+1)%gImages.length;$(gImages.get(i)).fadeIn(settings.fadeSpeed);_gallery.apply(this,[i])};if($.browser.msie){changeImg.call(this)}else{$("<img></img>").attr("src",$image.attr("src")).load(changeImg)}},settings.delay)};_gallery.call(this)})},};$.fn.mousepotato=function(method){if(methods[method]){return methods[method].apply(this,Array.prototype.slice.call(arguments,1))}if(typeof method==="object"||!method){return methods.init.apply(this,arguments)}$.error("Method "+method+" does not exist on jQuery.mousepotato")};jQuery.mousepotato=$.fn.mousepotato;jQuery.extend(jQuery.mousepotato,methods);jQuery.mousepotato.dialog_closeFn=function(){$(this).dialog("close")};jQuery.mousepotato.call_action="action.php"})(jQuery);Array.prototype.removeAt=function(c,b){if(!$.isArray(this)){return null}var a=this.slice((b||c)+1||this.length);this.length=c<0?this.length+c:c;return this.push.apply(this,a)};console=console||{};console.log=console.log||function(){};
