/*
 * @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 popups={active:[],total:0,reposition:function(){Array.each(popups.active,function(a,b){a.position(a.pos)})}};var Popup=new Class({Implements:[Options,Events],options:{fade:true,showOpacity:1,onBeforeShow:Function.from(),onAfterShow:Function.from(),onBeforeHide:Function.from(),onAfterHide:Function.from(),onRegionClick:Function.from(),onRegionOver:Function.from(),onRegionOut:Function.from(),onTrigger:Function.from()},initialize:function(c,b,a){this.setOptions(a);if(null==c||typeOf(c)!="element"){throw new Error('Specified Popup structure block "'+c+'" could not be located in the document!')}if(typeof this.options.showOpacity!=="number"||this.options.showOpacity<0||this.options.showOpacity>1){throw new Error('Expecting decimal value for "opacity" between 0 and 1; encountered "'+this.options.showOpacity+'" which is of type: '+typeof(this.options.showOpacity))}if(typeof this.options.fade!=="boolean"){throw new Error('Expecting boolean value for "fade"; encountered '+typeof(this.options.fade))}popups.total+=1;this.uid="popup_"+popups.total;this.container=c;this.htmlBlock=(null==b)?null:this.container.getElement(b);this.pos=null;this.transition=false;this.showing=false;this.fx=new Fx.Tween(this.container,{duration:"normal",transition:"expo:out"});this.container.set("opacity",0).setStyles({display:"block",position:"absolute",top:0,left:0,"z-index":10000}).inject(document.id(document.body),"top");this.fx.addEvents({start:function(){this.transition=true;if(!this.showing){this.fireEvent("onBeforeShow")}else{this.fireEvent("onBeforeHide")}}.bind(this),complete:function(){this.transition=false;if(this.showing){this.fireEvent("onAfterShow")}else{this.fireEvent("onAfterHide");this.container.setStyles({width:"",height:"",top:"",left:""})}}.bind(this)});this.container.addEvents({click:function(){this.fireEvent("onRegionClick")}.bind(this),mouseenter:function(){this.fireEvent("onRegionOver")}.bind(this),mouseleave:function(){this.fireEvent("onRegionOut")}.bind(this)})},assign:function(b,d,e,c){if(typeOf(b)!="element"&&typeOf(b)!="elements"&&typeOf(b)!="window"&&typeOf(b)!="document"){throw new Error('"'+handler+'" is not a valid event handler object! An event handler object must either be an HTML element, window or document!')}if(!/\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/.test(d)){throw new Error('The specified event "'+d+'" cannot be recognized!')}if(!/toggle|show|hide/i.test(e)){throw new Error('You must specify action as "show", "hide" or "toggle" only!')}if(typeOf(b)!="elements"){var a=b;b=new Array(a)}Array.each(b,function(f){f.addEvent(d,function(k){if(f!==window){k.preventDefault()}if(null==c){c={}}var j=e;var h=(null==c.position)?{}:c.position;var m=(null==c.condition||typeOf(c.condition)!="function")?null:c.condition;var i=this.container.retrieve("lockTo",null);var g=true;if(null==i){this.container.store("lockTo",f);g=false}else{if(null!=f){if(i!==f){this.container.store("lockTo",f);this.hide();g=false}}}if(e=="toggle"){var l=(g)?this.showing:false;j="hide";if(!l){j="show"}}if(j=="show"){if(typeOf(m)=="function"){if(!this.showing&&m.attempt([this,j])){this.position(h);this.show()}}else{if(!this.showing){this.position(h);this.show()}}}else{if(typeOf(m)=="function"){if(this.showing&&!m.attempt([this,j])){this.hide()}}else{if(this.showing){this.hide()}}}this.fireEvent("onTrigger",[f,d,e,this])}.bind(this))}.bind(this))},show:function(a){if(null==a){a=this.options.showOpacity}if(this.transition){this.fx.cancel()}if(this.options.fade){this.fx.start("opacity",a)}else{this.fx.set("opacity",a).start("opacity",a)}this.showing=true;popups.active.push(this)},hide:function(){if(this.transition){this.fx.cancel()}if(this.options.fade){this.fx.start("opacity",0)}else{this.fx.set("opacity",0).start("opacity",0)}this.showing=false;Array.each(popups.active,function(a,b){if(a.uid==this.uid){popups.active.splice(b,1)}}.bind(this))},position:function(e){if(null==e){e={}}var d=(null==e.relativeTo||(/^(?:body|html)$/i).test(e.relativeTo.tagName))?window:e.relativeTo;var u=(null==e.position)?"absolute":e.position;var j=(null==e.x)?"left":e.x;var h=(null==e.y)?"top":e.y;var g=(null==e.z)?"auto":e.z;var q=(null==e.offsetX)?0:e.offsetX;var p=(null==e.offsetY)?0:e.offsetY;var m=(null==e.inBoundX)?true:e.inBoundX;var l=(null==e.inBoundY)?true:e.inBoundY;var a=(null==e.injectIn)?null:(e.injectIn==window||(/^(?:body|html)$/i).test(e.injectIn.tagName))?document.body:e.injectIn;if(document.compatMode!="CSS1Compat"){throw new Error("This script only works in standards mode!")}if(typeOf(d)!="element"&&typeOf(d)!="window"&&typeOf(d)!="document"){throw new Error("The object to position your popup relative to must either be an HTML element, window or document!")}if(!/\b(?:absolute|fixed|relative|static|inherit)\b/.test(u)){throw new Error('"'+u+'" is not a valid CSS position property value!')}if(g!="auto"&&typeof g!="number"){throw new Error('"'+g+'" is not a valid CSS z-index property value!')}if(typeof q!="number"){throw new Error('Expecting numeric value for "offsetX"; encountered '+typeof(q))}if(typeof p!="number"){throw new Error('Expecting numeric value for "offsetY"; encountered '+typeof(p))}if(typeof m!="boolean"){throw new Error('Expecting boolean value for "inBoundX"; encountered '+typeof(m))}if(typeof l!=="boolean"){throw new Error('Expecting boolean value for "inBoundY"; encountered '+typeof(l))}if(null!=a&&typeOf(a)!="element"){throw new Error("The block you want to inject the popup into must be an HTML element!")}this.pos={relativeTo:d,position:u,x:j,y:h,z:g,offsetX:q,offsetY:p,inBoundX:m,inBoundY:l,injectIn:a};var b=this.container;b.setStyles({width:(Browser.ie)?(document.id(this.container).getStyle("width").toInt()||document.id(this.container).get("width")||""):"",height:(Browser.ie)?(document.id(this.container).getStyle("height").toInt()||document.id(this.container).get("height")||""):"",left:"",top:""});var t=document.id(d).getCoordinates(),s={width:(d==window)?t.width:(document.id(d).getStyle("width").toInt()||document.id(d).get("width")),outerWidth:t.width,height:(d==window)?t.height:(document.id(d).getStyle("height").toInt()||document.id(d).get("height")),outerHeight:t.height,left:(d==window)?0:t.left,top:(d==window)?0:t.top};var f=b.getCoordinates(),r={width:document.id(this.container).getStyle("width").toInt()||document.id(this.container).get("width"),outerWidth:f.width,height:document.id(this.container).getStyle("height").toInt()||document.id(this.container).get("height"),outerHeight:f.height,left:f.left,top:f.top};var v=0,i=0;var o=r.width,n=r.height;var k={width:((Browser.ie)?((u=="absolute")?(document.body||document.documentElement).scrollWidth:(document.body||document.documentElement).clientWidth):((u=="absolute")?(document.documentElement||document.html).scrollWidth:(document.documentElement||document.html).clientWidth)),height:((Browser.ie)?((u=="absolute")?(document.body||document.documentElement).scrollHeight:(document.html||document.documentElement).clientHeight):((u=="absolute")?(document.documentElement||document.html).scrollHeight:(document.documentElement||document.html).clientHeight))};if(null!=a&&document.id(a)!=b.getParent()){var c=b.dispose();b=c.inject(document.id(a),"bottom")}switch(j){case"left":v=s.left-(o+(r.outerWidth-r.width));break;case"leftEdge":v=s.left;break;case"right":v=(d==window)?k.width:(s.left+s.outerWidth);break;case"rightEdge":v=((d==window)?k.width:(s.left+s.outerWidth))-(o+(r.outerWidth-r.width));break;case"center":v=s.left-((o/2)-((((d==window)?k.width:s.outerWidth)-(r.outerWidth-r.width))/2));break;case"overlay":v=s.left;o=((d==window)?k.width:s.outerWidth)-(r.outerWidth-r.width);break;default:throw new Error('"'+j+'" is not a valid horizontal/x position value!');break}if(null!=v){v+=q}if(m){if(v<0){v=0}else{if((v+o)>k.width){v=k.width-(o+(r.outerWidth-r.width))}}}switch(h){case"top":i=s.top-(n+(r.outerHeight-r.height));break;case"topEdge":i=s.top;break;case"bottom":i=(d==window)?k.height:(s.top+s.outerHeight);break;case"bottomEdge":i=((d==window)?k.height:(s.top+s.outerHeight))-(n+(r.outerHeight-r.height));break;case"center":i=s.top-((n/2)-((((d==window)?k.height:s.outerHeight)-(r.outerHeight-r.height))/2));break;case"overlay":i=s.top;n=((d==window)?k.height:s.outerHeight)-(r.outerHeight-r.height);break;default:throw new Error('"'+h+'" is not a valid vertical/y position value!');break}if(null!=i){i+=p}if(l){if(i<0){i=0}else{if((i+n)>k.height){i=k.height-(n+(r.outerHeight-r.height))}}}if(o<0){o="auto"}if(n<0){n="auto"}b.setStyles({width:o,height:n,position:u,left:v,top:i,"z-index":(((Browser.ie6||Browser.ie7)&&g=="auto")?null:g)})},setStackIndex:function(a){this.container.setStyle("z-index",a)},setHTML:function(b,a){if(null==this.htmlBlock){throw new Error('Cannot set HTML for Popup (uid: "'+this.uid+'") because no popup HTML block/tag was specified.')}if(null==a){a=false}this.htmlBlock.set("html",b);if(a){this.container.setStyles({width:"",height:""})}},getHTML:function(){return((null==this.htmlBlock)?null:this.htmlBlock.get("html"))},});
