/*
 * @author			Daniyal Hamid
 * 
 * @license			This JavaScript file is a commercial file, available for purchase at 
 *					http://codecanyon.net/user/daniyal/portfolio. Any illegal copying, 
 *					distribution, packaging or re-production of this script for commercial or 
 *					personal use is strictly prohibited and will be considered theft.
 *
 * @copyright		The author is the first owner of copyright and reserves all rights to
 *					all written work contained in this file. Distribution, re-production
 *					or commercial use of the written work in this file, without the author's 
 * 					signed permission, prior consent or a valid license, is strictly prohibited.
 *					The author is protected by the "Copyright, Designs and Patents Act 1988" of 
 *					the United Kingdom. Any infringement of the copyright, in or outside of the
 *					United Kingdom, may result in a lawsuit.
 */

var Swap=new Class({Implements:[Options,Events],options:{topElement:"",activeLinkClass:"active",inDisplayAll:{showControls:false,},inDisplayContent:{scrollToContent:true},atStart:{displayAll:false,pointTo:1,scrollToContent:false},onContentSwap:Function.from(),onTrigger:Function.from()},initialize:function(a,b){this.setOptions(b);this.links=document.getElements(a+" a[href^=#]");this.index=this.options.atStart.pointTo-1;this.displayAll=this.options.atStart.displayAll;this.links.each(function(d,c){var e=this.toID(d.get("href"));if(null==document.id(e)){throw new Error('In your set of links, no content block exists for the resource "#'+e+'"')}d.addEvent("click",function(f){f.preventDefault();this.swap(c);this.fireEvent("onTrigger",["show",f.target,a+" a[href^=#]",this.displayAll])}.bind(this))}.bind(this));this.nav={next:null,previous:null};this.toggle();this.activateLink(this.index);if(this.options.atStart.scrollToContent){this.moveIntoView(this.index)}window.addEvent("resize",function(){this.moveIntoView(this.index)}.bind(this))},assign:function(d,b,e,a){if(!(d.test(/\b(?:on)?(?:blur|change|click|dblclick|domready|error|focus|keydown|keypress|keyup|load|mousedown|mouseenter|mouseleave|mousemove|mouseout|mouseover|mouseup|mousewheel|resize|scroll|select|unload)\b/))){throw new Error('The specified event "'+d+'" cannot be recognized!')}var c=(function(){return});switch(e){case"toggle":c=(function(f){this.displayAll=(!this.displayAll)?true:false;this.toggle();this.activateLink(this.index);this.moveIntoView(this.index);this.fireEvent("onTrigger",[e,f,b,this.displayAll])}).bind(this);break;case"previous":if(this.index<=0){document.getElements(b).setStyle("display","none")}this.nav.previous=b;this.updateCtrl();c=(function(f){if(this.index>0){this.swap(this.index-1);this.fireEvent("onTrigger",[e,f,b,this.displayAll])}}.bind(this));break;case"next":if(this.index>=(this.links.length-1)){document.getElements(b).setStyle("display","none")}this.nav.next=b;this.updateCtrl();c=(function(f){if(this.index<(this.links.length-1)){this.swap(this.index+1);this.fireEvent("onTrigger",[e,f,b,this.displayAll])}}.bind(this));break;case"goto":c=(function(f){((null==this.options.topElement||this.options.topElement=="")?document.id(document.body):this.options.topElement).scrollIntoView(true);this.fireEvent("onTrigger",[e,f,b,this.displayAll])}.bind(this));break;default:throw new Error(e+" is not a valid action!");break}document.getElements(b).addEvent(d,function(f){f.preventDefault();c.attempt(f.target)}.bind(this));if(null!=a&&typeof(a)=="object"){document.id(document.body).addEvent("keydown",function(f){a.each(function(h){var g=h.indexOf("+");if(g!=-1){var i=h.split("+");if(i[0]=="ctrl"||i[0]=="control"){if(f.control&&f.key==i[1]){f.stop();c.attempt("control+"+f.key)}}else{if(i[0]=="alt"){if(f.alt&&f.key==i[1]){f.stop();c.attempt("alt+"+f.key)}}else{if(i[0]=="shift"){if(f.shift&&f.key==i[1]){f.stop();c.attempt("shift+"+f.key)}}else{if(i[0]=="meta"){if(f.meta&&f.key==i[1]){f.stop();c.attempt("meta+"+f.key)}}else{throw new Error(h+" is not a valid key combination!")}}}}}else{if(f.key==h&&!(f.control||f.alt||f.shift||f.meta)){f.stop();c.attempt(f.key)}}})})}},swap:function(a){if(typeof(a)!="number"||a>=this.links.length){throw new Error("Either index "+a+" does not exist or is invalid!")}this.activateLink(a);var b=this.toID(this.links[this.index].get("href"));var c=this.toID(this.links[a].get("href"));if(!this.displayAll){document.id(b).setStyle("display","none");document.id(c).setStyle("display","")}this.moveIntoView(a);this.index=a;this.updateCtrl();this.fireEvent("onContentSwap",[document.id(b),document.id(c),this.displayAll])},updateCtrl:function(){if(null!=this.nav.next){if(this.index>=(this.links.length-1)||(this.displayAll&&!this.options.inDisplayAll.showControls)){document.getElements(this.nav.next).setStyle("display","none")}else{document.getElements(this.nav.next).setStyle("display","block")}}if(null!=this.nav.previous){if(this.index<=0||(this.displayAll&&!this.options.inDisplayAll.showControls)){document.getElements(this.nav.previous).setStyle("display","none")}else{document.getElements(this.nav.previous).setStyle("display","block")}}},activateLink:function(a){if(typeof(a)!="number"||a>=this.links.length){throw new Error("Either index "+a+" does not exist or is invalid!")}this.links[this.index].removeClass(this.options.activeLinkClass);this.links[a].addClass(this.options.activeLinkClass)},moveIntoView:function(a){if(typeof(a)!="number"||a>=this.links.length){throw new Error("Either index "+a+" does not exist or is invalid!")}var b=this.toID(this.links[a].get("href"));if(this.displayAll){document.id(b).scrollIntoView(true)}else{if(this.options.inDisplayContent.scrollToContent){document.id(b).scrollIntoView(true)}}},toggle:function(){if(this.displayAll){this.links.each(function(a){var b=this.toID(a.get("href"));document.id(b).setStyle("display","")}.bind(this))}else{this.links.each(function(b,a){var c=this.toID(b.get("href"));document.id(c).setStyle("display",((a==this.index)?"":"none"))}.bind(this))}this.updateCtrl()},toID:function(a){var b=a.lastIndexOf("#");if(b==-1){throw new Error('A resource URL must be in the form "#resource-id"')}return a.substring(b+1,a.length)}});
