/*
 * @author			Designcise
 * 
 * @license			This JavaScript file is a commercial file, available for purchase at 
 *					http://codecanyon.net/user/designcise/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(d){var b=new Array();d(window).bind("resize",function(f){d.each(b,function(e,g){d(g).css({position:"absolute",left:0,top:0})});d.each(b,function(g){var h=d(this),e=h.data("placeOptions");c.init.apply(h,[e])})});var a={calcBounds:function(i,f){var h=this,k=d(h).offset();i=(null==i)?false:i;f=(null==f)?false:f;var j={width:((d.browser.msie)?(document.documentElement).clientWidth:d(window).width()),height:((d.browser.msie)?(document.documentElement).clientHeight:d(window).height())};var g={width:((d.browser.msie)?(document.documentElement).scrollWidth:d(document).width()),height:((d.browser.msie)?(document.documentElement).scrollHeight:d(document).height())};var l=(h===window)?j.width:((h===document)?g.width:d(h).width());var e=(h===window)?j.height:((h===document)?g.height:d(h).height());var n=(h===window)?j.width:((h===document)?g.width:d(h).outerWidth(i));var m=(h===window)?j.height:((h===document)?g.height:d(h).outerHeight(i));return{width:l,height:e,outerWidth:n,outerHeight:m,topEdge:(h===window)?((f)?d(window).scrollTop():0):((h===document)?0:k.top),leftEdge:(h===window)?((f)?d(window).scrollLeft():0):((h===document)?0:k.left)}},inBound:function(f,h,e){var i=d(this),j=i.data("placeOptions");if(!j){throw new Error("The element you've selected does not have the required data set on it!")}h=a.calcBounds.apply(h,[false,((j.relativeTo===window&&j.position==="absolute")?true:false)]);var g=a.calcBounds.apply(i,[j.includeMargin,((j.relativeTo===window&&j.position==="absolute")?true:false)]);if(e==="x"){if(f<h.leftEdge){return h.leftEdge}else{if((f+g.outerWidth)>=(h.leftEdge+h.outerWidth)){return((h.leftEdge+h.outerWidth)-g.outerWidth)}}return -1}else{if(e==="y"){if(f<h.topEdge){return h.topEdge}else{if((f+g.outerHeight)>=(h.topEdge+h.outerHeight)){return((h.topEdge+h.outerHeight)-g.outerHeight)}}return -1}}},apply:function(g,f){var e=d(this),h=e.data("placeOptions");if(f===undefined){if(!h){throw new Error("The element you've selected does not have the required data set on it!")}return h[g]}if(!h){h={};h[g]=f;c.init.apply(e,[h]);h=e.data("placeOptions")}if(g==="offsetX"&&h.inBoundX===true){if(h.x==="right"&&f<0){f-=e.outerWidth()}else{if(h.x==="left"&&f>0){f+=e.outerWidth()}}}if(g==="offsetY"&&h.inBoundY===true){if(h.y==="bottom"&&f<0){f-=e.outerHeight()}else{if(h.y==="top"&&f>0){f+=e.outerHeight()}}}h[g]=f;e.data("placeOptions",h);c.init.apply(e)}};var c={init:function(e){d(this).css("position","absolute");return this.each(function(){var q=d(this),g=q.data("placeOptions");if(null==e){e={}}if(g){e=d.extend({},g,e)}var h=(null==e.relativeTo)?window:e.relativeTo;var A=(null==e.position)?"absolute":e.position;var n=(null==e.x)?"left":e.x;var k=(null==e.y)?"top":e.y;var j=(null==e.z)?"auto":e.z;var w=(null==e.offsetX)?0:e.offsetX;var v=(null==e.offsetY)?0:e.offsetY;var s=(null==e.inBoundX)?true:e.inBoundX;var r=(null==e.inBoundY)?true:e.inBoundY;var i=(null==e.boundingBox)?window:e.boundingBox;var o=(null==e.includeMargin)?false:e.includeMargin;if(document.compatMode!="CSS1Compat"){throw new Error("This script only works in standards mode!")}if(null==h||d.type(h)!=="object"){throw new Error("The object to position an element relative to must either be an HTML element, window or document!")}if(!/\b(?:absolute|fixed)\b/.test(A)){throw new Error('"'+A+'" is not a valid CSS position property value!')}if(j!="auto"&&j!=""&&d.type(j)!=="number"){throw new Error('"'+j+'" is not a valid CSS z-index property value!')}if(d.type(w)!=="number"){throw new Error('Expecting numeric value for "offsetX"; encountered '+typeof(w))}if(d.type(v)!=="number"){throw new Error('Expecting numeric value for "offsetY"; encountered '+typeof(v))}if(d.type(s)!=="boolean"){throw new Error('Expecting boolean value for "inBoundX"; encountered '+typeof(s))}if(d.type(r)!=="boolean"){throw new Error('Expecting boolean value for "inBoundY"; encountered '+typeof(r))}if(null==i||d.type(i)!=="object"){throw new Error("The bounding box should either be an HTML element, window or document!")}if(d.type(o)!=="boolean"){throw new Error('Expecting boolean value for "includeMargin"; encountered '+typeof(o))}if((d.browser.msie&&d.browser.version<=7&&j=="auto")){j=""}if(!g){b.push(q)}q.data("placeOptions",{relativeTo:h,position:A,x:n,y:k,z:j,offsetX:w,offsetY:v,inBoundX:s,inBoundY:r,boundingBox:i,includeMargin:o});if(q.css("position")!=A){q.css("position",A)}var l=a.calcBounds.apply(document);q.css({width:"",height:"",left:(h===window&&n==="right"&&!s)?l.outerWidth:"",top:(h===window&&k==="bottom"&&!r)?l.outerHeight:""});var f=a.calcBounds.apply(q,[false,((h===window&&A==="absolute")?true:false)]);var p=a.calcBounds.apply(h,[o,((h===window&&A==="absolute")?true:false)]);var u=f.width,t=f.height;var C=0,m=0;switch(n){case"left":C=p.leftEdge-f.outerWidth;break;case"leftEdge":C=p.leftEdge;break;case"right":C=p.leftEdge+p.outerWidth;break;case"rightEdge":C=(p.leftEdge+p.outerWidth)-f.outerWidth;break;case"center":C=p.leftEdge-(f.outerWidth/2)+(p.outerWidth/2);break;case"overlay":C=p.leftEdge;u=p.outerWidth-(f.outerWidth-f.width);break}switch(k){case"top":m=p.topEdge-f.outerHeight;break;case"topEdge":m=p.topEdge;break;case"bottom":m=p.topEdge+p.outerHeight;break;case"bottomEdge":m=(p.topEdge+p.outerHeight)-f.outerHeight;break;case"center":m=p.topEdge-(f.outerHeight/2)+(p.outerHeight/2);break;case"overlay":m=p.topEdge;t=p.outerHeight-(f.outerHeight-f.height);break}if(s){var B=a.inBound.apply(q,[C,i,"x"]);C=((B!==-1)?B:C)}if(null!=C&&!((h===window||h===document)&&n==="overlay"&&s)){var B=(!s)?(C+w):(a.inBound.apply(q,[C+w,i,"x"]));C=((B!==-1)?B:(C+w))}if(r){var B=a.inBound.apply(q,[m,i,"y"]);m=((B!==-1)?B:m)}if(null!=m&&!((h===window||h===document)&&k==="overlay"&&r)){var B=(!r)?(m+v):(a.inBound.apply(q,[(m+v),i,"y"]));m=((B!==-1)?B:(m+v))}if(u<0){u="auto"}if(t<0){t="auto"}q.css({width:u,height:t,left:C,top:m,zIndex:j})})},reset:function(){return this.each(function(){var e=d(this),f=e.data("placeOptions");if(f){e.removeData("placeOptions")}})}};d.fn.place=function(e){if(/\b(?:relativeTo|position|x|y|z|offsetX|offsetY|inBoundX|inBoundY|boundingBox|includeMargin)\b/.test(e)){return a.apply.apply(this,arguments)}else{if(c[e]){return c[e].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof e==="object"||!e){return c.init.apply(this,arguments)}else{throw new Error("Method "+e+" does not exist on jQuery.place")}}}}})(jQuery);
