/*
 * @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 Popup=new Class({Implements:[Options,Events],options:{fade:true,showOpacity:1,onBeforeShow:$empty,onAfterShow:$empty,onBeforeHide:$empty,onAfterHide:$empty,onRegionClick:$empty,onRegionOver:$empty,onRegionOut:$empty},initialize:function(b,f,a){try{this.setOptions(a);if(typeof b!="string"||null==document.id(b)){throw new Error('Specified Popup structure block "'+b+'" could not be located in the document!')}if(null!=f&&(typeof f!="string"||null==document.getElement("#"+b+" "+f))){throw new Error('CSS Selector "#'+b+" "+f+'" returned no matches!')}if(document.id(b).getStyle("display")!="none"){document.id(b).setStyle("display","none")}this.container=document.id(b).clone(true,true);var c=document.getElements(document.id(b).get("tag")+"[id^="+b+"]").length;this.container.set("id",this.container.get("id")+"_"+c).set("opacity",0).setStyles({display:"block",position:"absolute",top:0,left:0,"z-index":10000}).inject(document.id(document.body),"top");this.innerHTML=(null==f)?null:"#"+this.container.get("id")+" "+f;this.transition=false;this.showing=false;this.fx=new Fx.Tween(this.container,{duration:"normal",transition:((Browser.Engine.gecko)?"cubic:in:out":"expo:out")});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")}}.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)})}catch(d){alert(d.name+": "+d.message);return}},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},hide:function(a){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},position:function(g){try{if(null==g){g="undefined"}var f=(typeof g.relativeTo=="undefined"||(/^(?:body|html)$/i).test(g.relativeTo.tagName))?window:g.relativeTo;var B=(typeof g.position=="undefined")?"absolute":g.position;var k=(typeof g.x=="undefined")?"left":g.x;var j=(typeof g.y=="undefined")?"top":g.y;var h=(typeof g.z=="undefined")?"auto":g.z;var v=(typeof g.offsetX=="undefined")?0:g.offsetX;var t=(typeof g.offsetY=="undefined")?0:g.offsetY;var p=(typeof g.inBoundX=="undefined")?true:g.inBoundX;var o=(typeof g.inBoundY=="undefined")?true:g.inBoundY;var a=(typeof g.injectIn=="undefined")?null:(g.injectIn==window||(/^(?:body|html)$/i).test(g.injectIn.tagName))?document.body:g.injectIn;if(document.compatMode!="CSS1Compat"){throw new Error("This script only works in standards mode!")}if(typeof f!="object"){throw new Error("Relative to element must be an object!")}if(!(B.test(/absolute|fixed|relative|static|inherit/))){throw new Error('"'+B+'" is not a valid CSS Position property!')}if(!(k.test(/left|leftEdge|right|rightEdge|center|overlay/))){throw new Error('"'+k+'" is not a valid horizontal positioning value!')}if(!(j.test(/top|topEdge|bottom|bottomEdge|center|overlay/))){throw new Error('"'+j+'" is not a valid vertical positioning value!')}if(h!="auto"&&typeof h!="number"){throw new Error('"z-index" value must be a number!')}if(typeof v!="number"){throw new Error("Offset X value must be a number!")}if(typeof t!="number"){throw new Error("Offset Y value must be a number!")}if(typeof p!="boolean"||typeof o!="boolean"){throw new Error('Allowing/preventing clipping must be specified in "true/false"!')}if(typeof a!="object"){throw new Error("The place you want to inject the popup into must be a DOM Element object!")}var b=this.container;b.setStyles({width:null,height:null,left:null,top:null});var A=document.id(f).getCoordinates();var w=b.getCoordinates();var C=0,l=0;var r=w.width,q=w.height;var s=b.getStyle("borderLeft").toInt()+b.getStyle("borderRight").toInt();var m=b.getStyle("paddingLeft").toInt()+b.getStyle("paddingRight").toInt();var i=b.getStyle("borderTop").toInt()+b.getStyle("borderBottom").toInt();var d=b.getStyle("paddingTop").toInt()+b.getStyle("paddingBottom").toInt();var n={width:((Browser.Engine.trident)?((B=="absolute")?(document.body||document.documentElement).scrollWidth:(document.body||document.documentElement).clientWidth):((B=="absolute")?(document.documentElement||document.html).scrollWidth:(document.documentElement||document.html).clientWidth)),height:((Browser.Engine.trident)?((B=="absolute")?(document.body||document.documentElement).scrollHeight:(document.html||document.documentElement).clientHeight):((B=="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(k){case"left":C=A.left-(r+s+m);break;case"leftEdge":C=A.left;break;case"right":C=(f==window)?n.width:A.right;break;case"rightEdge":C=((f==window)?n.width:A.right)-(r+s+m);break;case"center":C=A.left-((r/2)-((((f==window)?n.width:A.width)-(s+m))/2));break;case"overlay":C=A.left;r=((f==window)?n.width:A.width)-(s+m);break}if(null!=C){C+=v}if(p){if(C<0){C=0}else{if((C+r+s+m)>n.width){C=n.width-(r+s+m)}}}switch(j){case"top":l=A.top-(q+i+d);break;case"topEdge":l=A.top;break;case"bottom":l=(f==window)?n.height:A.bottom;break;case"bottomEdge":l=((f==window)?n.height:A.bottom)-(q+i+d);break;case"center":l=A.top-((q/2)-((((f==window)?n.height:A.height)-(i+d))/2));break;case"overlay":l=A.top;q=((f==window)?n.height:A.height)-(i+d);break}if(null!=l){l+=t}if(o){if(l<0){l=0}else{if((l+q+i+d)>n.height){l=n.height-(q+i+d)}}}if(r<0){r="auto"}if(q<0){q="auto"}b.setStyles({width:r,height:q,position:B,left:C,top:l,"z-index":((Browser.Engine.trident&&Browser.Engine.version<=5&&h=="auto")?null:h)})}catch(u){alert(u.name+": "+u.message);return}},resetCoordinates:function(){this.container.setStyles({width:null,height:null,left:null,top:null})},setStackIndex:function(a){this.container.setStyle("z-index",a)},setHTML:function(b,a){try{if(null==this.innerHTML){throw new Error('Cannot set HTML for Popup "'+this.getID()+'" because no Popup innerHTML tag was specified.')}if(null==a){a=true}document.getElement(this.innerHTML).set("html",b);if(a){this.container.setStyles({width:null,height:null})}}catch(c){alert(c.name+": "+c.message);return}},getHTML:function(){return document.getElement(this.innerHTML).get("html")},getID:function(){return this.container.get("id")}});var PopupHandler=new Class({Implements:[Options,Events],options:{onTrigger:$empty},initialize:function(b,a){this.setOptions(a);this.popups=b},assign:function(f,c,d,a){var b=null;if(typeof f=="string"&&null!=document.id(f)){b=document.id(f)}else{if(typeof f=="string"&&null!=document.getElement(f)){b=document.getElement(f)}else{if(typeof f=="object"&&f!=window){b=document.id(f)}else{if(typeof f=="object"&&f==window){b=window}else{throw new Error('The specified handler "'+f+'" cannot be recognized!')}}}}if(!(c.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 "'+c+'" cannot be recognized!')}if(!d.test(/toggle|show|hide/)){throw new Error('The specified action "'+d+'" cannot be recognized!')}if(null==a){a="undefined"}var g=(typeof a.condition=="undefined")?null:a.condition;var e=(typeof a.toIndex=="undefined")?null:a.toIndex;if(null!=g&&typeof g!="function"){throw new Error("Condition must be a function that returns true/false!")}if(null!=e&&typeof e!="number"){throw new Error("Popup to assign handler to must be a number!")}b.addEvent(c,function(h){if(b!=window){h.preventDefault()}if(null==e){this.popups.each(function(j,k){this.popupAt(k,d,g)}.bind(this))}else{this.popupAt(e,d,g)}this.fireEvent("onTrigger",[b,c,d,e,this.popups])}.bind(this))},popupAt:function(b,d,g){try{var a=this.popups[b];if(null==this.popups[b]||!(a instanceof Popup)){throw new Error('"'+a+'" is not a valid Popup object!')}if(!d.test(/toggle|show|hide/)){throw new Error('The specified action "'+d+'" cannot be recognized!')}var c=d;if(d=="toggle"){if(!a.showing){c="show"}else{c="hide"}}if(c=="show"){if(typeof g=="function"){if(!a.showing&&g.attempt([a,c])){a.show()}}else{if(!a.showing){a.show()}}}else{if(typeof g=="function"){if(a.showing&&!g.attempt([a,c])){a.hide()}}else{if(a.showing){a.hide()}}}}catch(f){alert(f.name+": "+f.message);return}},addPopup:function(a){this.popups.push(a)},removePopupAt:function(a){if(a>=0&&a<this.popups.length){this.popups.splice(a,1)}},getPopupAt:function(a){return this.popups[a]}});
