/*
 * @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.
 */


(function(e){var d=false;var c=0;var a=[];var b={init:function(f){return this.each(function(){var h=e(this),g=h.data("options");if(null==f){f={}}if(null!=f.htmlBlock&&typeof f.htmlBlock!=="string"){throw new Error("Invalid CSS selector specified for htmlBlock!")}c+=1;f=e.extend({},f,{uid:"popup_"+c,position:null,visible:false,lockTo:null});h.css({opacity:0,display:"none"});if(!g){h.data("options",e.extend({htmlBlock:null},f))}h.bind({"click.popup":function(){var j=e(this),i=e(this).data("options");e(this).trigger("regionClick.popup",[i.lockTo,i])},"mouseenter.popup":function(){var j=e(this),i=e(this).data("options");e(this).trigger("regionOver.popup",[i.lockTo,i])},"mouseleave.popup":function(){var j=e(this),i=e(this).data("options");e(this).trigger("regionOut.popup",[i.lockTo,i])}});if(d){e(window).bind("resize.popup",b.reposition)}})},destroy:function(f){return this.each(function(){var h=e(this),g=h.data("options");if(g.visible){e.each(a,function(j){var k=e(this);if(k[0]===h[0]){a.splice(j,1);return false}})}h.removeData("options");h.unbind(".popup");if(null!=f){e.each(f,function(j,k){k.unbind(".popup")})}})},assign:function(g,h,i,f){return this.each(function(){var k=e(this),j=k.data("options");if(null==g||typeof g!=="object"){throw new Error('"'+g+'" 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|error|focus|focusin|focusout|keydown|keypress|keyup|load|mousedown|mouseenter|mouseleave|mousemove|mouseout|mouseover|mouseup|mousewheel|resize|scroll|select|submit|unload)\b/i.test(h)){throw new Error('The specified event "'+h+'" cannot be recognized!')}if(!/toggle|show|hide/i.test(i)){throw new Error('You must specify action as "show", "hide" or "toggle" only!')}g.bind(String(h+".popup"),{popup:k},function(q){var m=q.data.popup;if(g!==window){q.preventDefault()}if(null==f){f={}}var n=i;var l=(null==f.position)?{}:f.position;var s=(null==f.condition||!e.isFunction(f.condition))?null:f.condition;var o=(null==f.showOptions)?{handler:g}:e.extend({},f.showOptions,{handler:g});var p=(null==f.hideOptions)?{}:f.hideOptions;if(n=="toggle"){var r=(null!=j.lockTo&&j.lockTo[0]===g[0])?j.visible:false;n="hide";if(!r){n="show"}}if(n=="show"){if(e.isFunction(s)){if(s.apply(this,[m,n])){b.position.apply(m,[l]);b.show.apply(m,[o])}}else{b.position.apply(m,[l]);b.show.apply(m,[o])}}else{if(e.isFunction(s)){if(!s.apply(this,[m,n])){b.hide.apply(m,[p])}}else{b.hide.apply(m,[p])}}g.trigger("trigger.popup",[g,n,j])})})},show:function(n){var g=e(this),h=g.data("options");var f=h.lockTo;if(null==n){n={}}var l=(null==n.opacity)?1:n.opacity;var i=(null==n.fade)?true:n.fade;var k=(null==n.animation)?{}:n.animation;var j=(null==n.duration)?((i)?400:5):n.duration;var m=(null==n.handler)?null:n.handler;if(typeof l!=="number"||l<0||l>1){throw new Error('Expecting decimal value for "opacity" between 0 and 1; encountered "'+l+'" which is of type: '+typeof(l))}if(typeof i!=="boolean"){throw new Error('Expecting boolean value for "fade"; encountered '+typeof(i))}if(typeof k!=="object"){throw new Error("Animation settings must be in the form of an object literal!")}if(typeof j!=="number"||j<0){throw new Error('Expecting a positive numeric value for "duration"; encountered value "'+j+'" which is of type: '+typeof(j))}if(m!=null&&typeof m!=="object"){throw new Error('"'+m+'" is not a valid event handler object! An event handler object must either be an HTML element, window or document!')}g.stop(true,false);if(null==h.lockTo){h.lockTo=m}else{if(null!=m){if(m[0]===f[0]){if(g.css("opacity")==l&&e.isEmptyObject(k)){return}}else{h.lockTo=m;g.css("opacity",0)}}}g.trigger("beforeShow.popup",[f,h,((g.css("opacity")>0)?true:false)]);g.css("display","block");g.animate(e.extend(k,{opacity:l}),j,((i)?"linear":null),function(){g.trigger("afterShow.popup",[f,h,true])});h.visible=true;a.push(g)},hide:function(h){var g=e(this),f=g.data("options");var i=f.lockTo;if(null==h){h={}}var l=(null==h.fade)?true:h.fade;var j=(null==h.animation)?{}:h.animation;var k=(null==h.duration)?((l)?400:5):h.duration;if(typeof l!=="boolean"){throw new Error('Expecting boolean value for "fade"; encountered '+typeof(l))}if(typeof j!=="object"){throw new Error("Animation settings must be in the form of an object literal!")}if(typeof k!=="number"||k<0){throw new Error('Expecting a positive numeric value for "duration"; encountered value "'+k+'" which is of type: '+typeof(k))}g.stop(true,false);g.trigger("beforeHide.popup",[i,f,((g.css("opacity")>0)?true:false)]);g.animate(e.extend(j,{opacity:0}),k,((l)?"linear":null),function(){g.trigger("afterHide.popup",[i,f,false]);g.css("display","none")});f.visible=false;e.each(a,function(m){var n=e(this);if(n[0]===g[0]){a.splice(m,1);return false}})},position:function(f){return this.each(function(){var h=e(this),j=h.data("options");if(null==f){f={}}var i=(null==f.relativeTo||(/^(?:body|html)$/i).test(f.relativeTo.nodeName)?window:f.relativeTo);var A=(null==f.position)?"absolute":f.position;var m=(null==f.x)?"left":f.x;var l=(null==f.y)?"top":f.y;var k=(null==f.z)?"auto":f.z;var u=(null==f.offsetX)?0:f.offsetX;var t=(null==f.offsetY)?0:f.offsetY;var q=(null==f.inBoundX)?true:f.inBoundX;var p=(null==f.inBoundY)?true:f.inBoundY;var g=(null==f.injectIn)?null:((f.injectIn===window||(/^(?:body|html)$/i).test(f.injectIn.nodeName))?document.body:f.injectIn);if(null==i||typeof i!=="object"){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(A)){throw new Error('"'+A+'" is not a valid CSS position property value!')}if(k!="auto"&&k!=""&&typeof k!=="number"){throw new Error('"'+k+'" is not a valid CSS z-index property value!')}if(typeof u!=="number"){throw new Error('Expecting numeric value for "offsetX"; encountered '+typeof(u))}if(typeof t!=="number"){throw new Error('Expecting numeric value for "offsetY"; encountered '+typeof(t))}if(typeof q!=="boolean"){throw new Error('Expecting boolean value for "inBoundX"; encountered '+typeof(q))}if(typeof p!=="boolean"){throw new Error('Expecting boolean value for "inBoundY"; encountered '+typeof(p))}if(typeof g!=="object"){throw new Error("The block you want to inject the popup into must be an HTML element!")}if((e.browser.msie&&e.browser.version<=7&&k=="auto")){k=""}h.css({width:"",height:"",left:"",top:""});j.position={relativeTo:i,position:A,x:m,y:l,z:k,offsetX:u,offsetY:t,inBoundX:q,inBoundY:p,injectIn:g};if(h.css("position")!=A){h.css("position",A)}var w={width:e(i).width(),outerWidth:(i==window)?e(window).width():e(i).outerWidth(),height:e(i).height(),outerHeight:(i==window)?e(window).height():e(i).outerHeight(),left:(i==window)?0:e(i).position().left,top:(i==window)?0:e(i).position().top};var v={width:e(h).width(),outerWidth:e(h).outerWidth(),height:e(h).height(),outerHeight:e(h).outerHeight(),left:e(h).position().left,top:e(h).position().top};var B=0,n=0;var s=v.outerWidth,r=v.outerHeight;var o={width:((e.browser.msie)?((A=="absolute")?(document.body||document.documentElement).scrollWidth:(document.body||document.documentElement).clientWidth):((A=="absolute")?e(document).width():e(window).width())),height:((e.browser.msie)?((A=="absolute")?(document.body||document.documentElement).scrollHeight:(document.html||document.documentElement).clientHeight):((A=="absolute")?e(document).height():e(window).height()))};if(null!=g&&e(g)!=h.parent()){h.appendTo(e(g))}switch(m){case"left":B=w.left-(s+(v.outerWidth-v.width));break;case"leftEdge":B=w.left;break;case"right":B=(i==window)?o.width:(w.left+w.outerWidth);break;case"rightEdge":B=((i==window)?o.width:(w.left+w.outerWidth))-(s+(v.outerWidth-v.width));break;case"center":B=w.left-((s/2)-((((i==window)?o.width:w.outerWidth)-(v.outerWidth-v.width))/2));break;case"overlay":B=w.left;s=((i==window)?o.width:w.outerWidth)-(v.outerWidth-v.width);break;default:throw new Error('"'+m+'" is not a valid horizontal/x position value!');break}if(null!=B){B+=u}if(q){if(B<0){B=0}else{if((B+s)>o.width){B=o.width-(s+(v.outerWidth-v.width))}}}switch(l){case"top":n=w.top-(r+(v.outerHeight-v.height));break;case"topEdge":n=w.top;break;case"bottom":n=(i==window)?o.height:(w.top+w.outerHeight);break;case"bottomEdge":n=((i==window)?o.height:(w.top+w.outerHeight))-(r+(v.outerHeight-v.height));break;case"center":n=w.top-((r/2)-((((i==window)?o.height:w.outerHeight)-(v.outerHeight-v.height))/2));break;case"overlay":n=w.top;r=((i==window)?o.height:w.outerHeight)-(v.outerHeight-v.height);break;default:throw new Error('"'+l+'" is not a valid vertical/y position value!');break}if(null!=n){n+=t}if(p){if(n<0){n=0}else{if((n+r)>o.height){n=o.height-(r+(v.outerHeight-v.height))}}}if(s<0){s="auto"}if(r<0){r="auto"}h.css({width:s,height:r,left:B,top:n,zIndex:k})})},reposition:function(){e.each(a,function(h){var g=e(this),f=g.data("options");b.position.apply(g,[f.position])})},html:function(i){var h=e(this),g=h.data("options");var f=h.find(g.htmlBlock).eq(0);if(f.length==0){throw new Error('Cannot set HTML for Popup (uid: "'+this.uid+'") because no popup HTML block/tag was specified or the HTML block could not be found inside the popup structure.')}if(null==i){return f.html()}else{f.html(i)}}};e.fn.popup=function(f){if(b[f]){return b[f].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof f==="object"||!f){return b.init.apply(this,arguments)}else{throw new Error("Method "+f+" does not exist on jQuery.popup")}}}})(jQuery);
