/*function cardImageEvent(){
			$("#cards>img").each(function(index){

				$(this).click(function(){
					customSelectEvent(index, 0);
					alert(1);
					var val=$("#ccType :selected").val();
					alert(val);
					if (val=="Amex")
					{
						$("#cvv2_help").html("(4 digit # on front of the card)");
						$("#cc_cvv2").attr("maxlength", "4");
					}
					else
					{
						$("#cvv2_help").html("(3 digit # on front of the card)");
						$("#cc_cvv2").val($("#cc_cvv2").val().substr(0,3));
						$("#cc_cvv2").attr("maxlength", "3");
					}
				});
			});
		}*/

// testimonials
  
function initTestimonials() {
	// options
	var rotateSpeed = 25; // pixels per second
	var pauseOnHover = true;
	
	// implementation
	$('div.b-feedback').each(function() {
		//if(!$(this).hasClass('feedback-implemented')) {
			var feedback = $(this);
			var feedbackSlicer = $('div.slicer', feedback);
			var feedbackNode = $('div.node', feedbackSlicer);
			var feedbackPane = $('div.pane', feedbackNode);
			
			var feedbackHeight = parseInt(feedbackPane.height());
			if (feedbackHeight > parseInt(feedbackSlicer.height())) {
				var feedbackPaneAfter = feedbackPane.clone(true).insertAfter(feedbackPane);
				var feedbackTime = Math.floor(feedbackHeight/rotateSpeed)*1000;
				function animateFeedback(feedTime) {
					
					feedbackNode
						.animate({
							top: - feedbackHeight
						}, {
							duration: feedTime,
							easing: 'linear',
							complete: function() {
								feedbackNode.css({
									top: 0
								});
								animateFeedback(feedbackTime);
							}
						});
				}
				
				animateFeedback(feedbackTime);
				if(pauseOnHover) {
					feedback
						.hover(function() {
							feedbackNode.stop();
						}, function() {
							animateFeedback(Math.ceil(feedbackTime * (parseInt(feedbackNode.css('top')) + feedbackHeight) / feedbackHeight));
						});
				}
			}
			feedback.addClass('feedback-implemented');
		//}
	});
}

// blog
function initBlogPreview() {
	// options
	var blogTimeout = 5000; // timeout
	var blogToggle = 1000; // animation speed
	var pauseOnHover = true;
	var blogCurr = 'active';
	
	$('div.b-blog').each(function() {
		if(!$(this).hasClass('blog-preview-implemented')) {
			var blog = $(this);
			var blogItem = $('div.item', blog);
			var blogCurrent = blogItem.index(blogItem.filter('.' + blogCurr).eq(0));
			if(blogCurrent<0) {
				blogCurrent = 0;
			}
			var blogPrev = blogCurrent;
			var blogHovered = false;
			blogItem.each(function() {
				$(this)
					.attr('thisHeight', $(this).height())
					.removeClass(blogCurr)
					.css({
						position: 'absolute',
						left: -7777,
						top: -7777
					});
			});
			blogItem.eq(blogCurrent).css({
				position: 'static',
				left: 'auto',
				top: 'auto'
			});
			function changeBlogItem() {
				blogPrev = blogCurrent;
				if(blogCurrent<blogItem.length-1) {
					blogCurrent++;
				} else {
					blogCurrent = 0;
				}
				blog.animate({
					height: parseInt(blogItem.eq(blogCurrent).attr('thisHeight'))
				}, {
					duration: blogToggle/2
				})
				blogItem.eq(blogPrev).animate({
					opacity: 0
				}, {
					duration: blogToggle/2,
					complete: function() {
						blogItem.eq(blogPrev).css({
							opacity: 'auto',
							left: -7777,
							top: -7777,
							position: 'absolute'
						});
						blogItem.eq(blogCurrent)
							.css({
								opacity: 0,
								left: 'auto',
								top: 'auto',
								position: 'static'
							})
							.animate({
								opacity: 1
							}, {
								duration: blogToggle/2,
								complete: function() {
									if($.browser.msie) {
										blogItem.eq(blogCurrent).css({
											opacity: 'auto'
										});
									}
								}
							});
					}
				});
			}
			if (blogTimeout) {
				setInterval(function() {
					if(!blogHovered) {
						changeBlogItem();
					}
				}, blogTimeout);
			}
			if(pauseOnHover) {
				blog.hover(function() {
					blogHovered = true;
				}, function() {
					blogHovered = false;
				});
			}
			$(this).addClass('blog-preview-implemented');
		}
	});
}

/*! Copyright (c) 2010 Brandon Aaron (http://brandonaaron.net)
 * Licensed under the MIT License (LICENSE.txt).
 *
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 * Thanks to: Seamus Leahy for adding deltaX and deltaY
 *
 * Version: 3.0.4
 * 
 * Requires: 1.2.2+
 */
(function($){var c=['DOMMouseScroll','mousewheel'];$.event.special.mousewheel={setup:function(){if(this.addEventListener){for(var i=c.length;i;){this.addEventListener(c[--i],handler,false)}}else{this.onmousewheel=handler}},teardown:function(){if(this.removeEventListener){for(var i=c.length;i;){this.removeEventListener(c[--i],handler,false)}}else{this.onmousewheel=null}}};$.fn.extend({mousewheel:function(a){return a?this.bind("mousewheel",a):this.trigger("mousewheel")},unmousewheel:function(a){return this.unbind("mousewheel",a)}});function handler(a){var b=a||window.event,args=[].slice.call(arguments,1),delta=0,returnValue=true,deltaX=0,deltaY=0;a=$.event.fix(b);a.type="mousewheel";if(a.wheelDelta){delta=a.wheelDelta/120}if(a.detail){delta=-a.detail/3}deltaY=delta;if(b.axis!==undefined&&b.axis===b.HORIZONTAL_AXIS){deltaY=0;deltaX=-1*delta}if(b.wheelDeltaY!==undefined){deltaY=b.wheelDeltaY/120}if(b.wheelDeltaX!==undefined){deltaX=-1*b.wheelDeltaX/120}args.unshift(a,delta,deltaX,deltaY);return $.event.handle.apply(this,args)}})(jQuery);

/**
 * @author trixta
 * @version 1.2
 */
(function($){var b={pos:[-260,-260]},minDif=3,doc=document,root=doc.documentElement,body=doc.body,longDelay,shortDelay;function unsetPos(){if(this===b.elem){b.pos=[-260,-260];b.elem=false;minDif=3}}$.event.special.mwheelIntent={setup:function(){var a=$(this).bind('mousewheel',$.event.special.mwheelIntent.handler);if(this!==doc&&this!==root&&this!==body){a.bind('mouseleave',unsetPos)}a=null;return true},teardown:function(){$(this).unbind('mousewheel',$.event.special.mwheelIntent.handler).unbind('mouseleave',unsetPos);return true},handler:function(e,d){var a=[e.clientX,e.clientY];if(this===b.elem||Math.abs(b.pos[0]-a[0])>minDif||Math.abs(b.pos[1]-a[1])>minDif){b.elem=this;b.pos=a;minDif=250;clearTimeout(shortDelay);shortDelay=setTimeout(function(){minDif=10},200);clearTimeout(longDelay);longDelay=setTimeout(function(){minDif=3},1500);e=$.extend({},e,{type:'mwheelIntent'});return $.event.handle.apply(this,arguments)}}};$.fn.extend({mwheelIntent:function(a){return a?this.bind("mwheelIntent",a):this.trigger("mwheelIntent")},unmwheelIntent:function(a){return this.unbind("mwheelIntent",a)}});$(function(){body=doc.body;$(doc).bind('mwheelIntent.mwheelIntentDefault',$.noop)})})(jQuery);

/*
 * jScrollPane - v2.0.0beta6 - 2010-12-06
 * http://jscrollpane.kelvinluck.com/
 *
 * Copyright (c) 2010 Kelvin Luck
 * Dual licensed under the MIT and GPL licenses.
 */
(function(b,a,c){b.fn.jScrollPane=function(f){function d(C,L){var au,N=this,V,ah,v,aj,Q,W,y,q,av,aB,ap,i,H,h,j,X,R,al,U,t,A,am,ac,ak,F,l,ao,at,x,aq,aE,g,aA,ag=true,M=true,aD=false,k=false,Z=b.fn.mwheelIntent?"mwheelIntent.jsp":"mousewheel.jsp";aE=C.css("paddingTop")+" "+C.css("paddingRight")+" "+C.css("paddingBottom")+" "+C.css("paddingLeft");g=(parseInt(C.css("paddingLeft"))||0)+(parseInt(C.css("paddingRight"))||0);an(L);function an(aH){var aL,aK,aJ,aG,aF,aI;au=aH;if(V==c){C.css({overflow:"hidden",padding:0});ah=C.innerWidth()+g;v=C.innerHeight();C.width(ah);V=b('<div class="jspPane" />').wrap(b('<div class="jspContainer" />').css({width:ah+"px",height:v+"px"}));C.wrapInner(V.parent());aj=C.find(">.jspContainer");V=aj.find(">.jspPane");V.css("padding",aE)}else{C.css("width","");aI=C.outerWidth()+g!=ah||C.outerHeight()!=v;if(aI){ah=C.innerWidth()+g;v=C.innerHeight();aj.css({width:ah+"px",height:v+"px"})}aA=V.innerWidth();if(!aI&&V.outerWidth()==Q&&V.outerHeight()==W){if(aB||av){V.css("width",aA+"px");C.css("width",(aA+g)+"px")}return}V.css("width","");C.css("width",(ah)+"px");aj.find(">.jspVerticalBar,>.jspHorizontalBar").remove().end()}aL=V.clone().css("position","absolute");aK=b('<div style="width:1px; position: relative;" />').append(aL);b("body").append(aK);Q=Math.max(V.outerWidth(),aL.outerWidth());aK.remove();W=V.outerHeight();y=Q/ah;q=W/v;av=q>1;aB=y>1;if(!(aB||av)){C.removeClass("jspScrollable");V.css({top:0,width:aj.width()-g});n();D();O();w();af()}else{C.addClass("jspScrollable");aJ=au.maintainPosition&&(H||X);if(aJ){aG=ay();aF=aw()}aC();z();E();if(aJ){K(aG);J(aF)}I();ad();if(au.enableKeyboardNavigation){P()}if(au.clickOnTrack){p()}B();if(au.hijackInternalLinks){m()}}if(au.autoReinitialise&&!aq){aq=setInterval(function(){an(au)},au.autoReinitialiseDelay)}else{if(!au.autoReinitialise&&aq){clearInterval(aq)}}C.trigger("jsp-initialised",[aB||av])}function aC(){if(av){aj.append(b('<div class="jspVerticalBar" />').append(b('<div class="jspCap jspCapTop" />'),b('<div class="jspTrack" />').append(b('<div class="jspDrag" />').append(b('<div class="jspDragTop" />'),b('<div class="jspDragBottom" />'))),b('<div class="jspCap jspCapBottom" />')));R=aj.find(">.jspVerticalBar");al=R.find(">.jspTrack");ap=al.find(">.jspDrag");if(au.showArrows){am=b('<a class="jspArrow jspArrowUp" />').bind("mousedown.jsp",az(0,-1)).bind("click.jsp",ax);ac=b('<a class="jspArrow jspArrowDown" />').bind("mousedown.jsp",az(0,1)).bind("click.jsp",ax);if(au.arrowScrollOnHover){am.bind("mouseover.jsp",az(0,-1,am));ac.bind("mouseover.jsp",az(0,1,ac))}ai(al,au.verticalArrowPositions,am,ac)}t=v;aj.find(">.jspVerticalBar>.jspCap:visible,>.jspVerticalBar>.jspArrow").each(function(){t-=b(this).outerHeight()});ap.hover(function(){ap.addClass("jspHover")},function(){ap.removeClass("jspHover")}).bind("mousedown.jsp",function(aF){b("html").bind("dragstart.jsp selectstart.jsp",function(){return false});ap.addClass("jspActive");var s=aF.pageY-ap.position().top;b("html").bind("mousemove.jsp",function(aG){S(aG.pageY-s,false)}).bind("mouseup.jsp mouseleave.jsp",ar);return false});o()}}function o(){al.height(t+"px");H=0;U=au.verticalGutter+al.outerWidth();V.width(ah-U-g);if(R.position().left==0){V.css("margin-left",U+"px")}}function z(){if(aB){aj.append(b('<div class="jspHorizontalBar" />').append(b('<div class="jspCap jspCapLeft" />'),b('<div class="jspTrack" />').append(b('<div class="jspDrag" />').append(b('<div class="jspDragLeft" />'),b('<div class="jspDragRight" />'))),b('<div class="jspCap jspCapRight" />')));ak=aj.find(">.jspHorizontalBar");F=ak.find(">.jspTrack");h=F.find(">.jspDrag");if(au.showArrows){at=b('<a class="jspArrow jspArrowLeft" />').bind("mousedown.jsp",az(-1,0)).bind("click.jsp",ax);x=b('<a class="jspArrow jspArrowRight" />').bind("mousedown.jsp",az(1,0)).bind("click.jsp",ax);if(au.arrowScrollOnHover){at.bind("mouseover.jsp",az(-1,0,at));
x.bind("mouseover.jsp",az(1,0,x))}ai(F,au.horizontalArrowPositions,at,x)}h.hover(function(){h.addClass("jspHover")},function(){h.removeClass("jspHover")}).bind("mousedown.jsp",function(aF){b("html").bind("dragstart.jsp selectstart.jsp",function(){return false});h.addClass("jspActive");var s=aF.pageX-h.position().left;b("html").bind("mousemove.jsp",function(aG){T(aG.pageX-s,false)}).bind("mouseup.jsp mouseleave.jsp",ar);return false});l=aj.innerWidth();ae()}else{}}function ae(){aj.find(">.jspHorizontalBar>.jspCap:visible,>.jspHorizontalBar>.jspArrow").each(function(){l-=b(this).outerWidth()});F.width(l+"px");X=0}function E(){if(aB&&av){var aF=F.outerHeight(),s=al.outerWidth();t-=aF;b(ak).find(">.jspCap:visible,>.jspArrow").each(function(){l+=b(this).outerWidth()});l-=s;v-=s;ah-=aF;F.parent().append(b('<div class="jspCorner" />').css("width",aF+"px"));o();ae()}if(aB){V.width((aj.outerWidth()-g)+"px")}W=V.outerHeight();q=W/v;if(aB){ao=1/y*l;if(ao>au.horizontalDragMaxWidth){ao=au.horizontalDragMaxWidth}else{if(ao<au.horizontalDragMinWidth){ao=au.horizontalDragMinWidth}}h.width(ao+"px");j=l-ao;ab(X)}if(av){A=1/q*t;if(A>au.verticalDragMaxHeight){A=au.verticalDragMaxHeight}else{if(A<au.verticalDragMinHeight){A=au.verticalDragMinHeight}}ap.height(A+"px");i=t-A;aa(H)}}function ai(aG,aI,aF,s){var aK="before",aH="after",aJ;if(aI=="os"){aI=/Mac/.test(navigator.platform)?"after":"split"}if(aI==aK){aH=aI}else{if(aI==aH){aK=aI;aJ=aF;aF=s;s=aJ}}aG[aK](aF)[aH](s)}function az(aF,s,aG){return function(){G(aF,s,this,aG);this.blur();return false}}function G(aH,aF,aK,aJ){aK=b(aK).addClass("jspActive");var aI,s=function(){if(aH!=0){T(X+aH*au.arrowButtonSpeed,false)}if(aF!=0){S(H+aF*au.arrowButtonSpeed,false)}},aG=setInterval(s,au.arrowRepeatFreq);s();aI=aJ==c?"mouseup.jsp":"mouseout.jsp";aJ=aJ||b("html");aJ.bind(aI,function(){aK.removeClass("jspActive");clearInterval(aG);aJ.unbind(aI)})}function p(){w();if(av){al.bind("mousedown.jsp",function(aH){if(aH.originalTarget==c||aH.originalTarget==aH.currentTarget){var aG=b(this),s=setInterval(function(){var aI=aG.offset(),aJ=aH.pageY-aI.top;if(H+A<aJ){S(H+au.trackClickSpeed)}else{if(aJ<H){S(H-au.trackClickSpeed)}else{aF()}}},au.trackClickRepeatFreq),aF=function(){s&&clearInterval(s);s=null;b(document).unbind("mouseup.jsp",aF)};b(document).bind("mouseup.jsp",aF);return false}})}if(aB){F.bind("mousedown.jsp",function(aH){if(aH.originalTarget==c||aH.originalTarget==aH.currentTarget){var aG=b(this),s=setInterval(function(){var aI=aG.offset(),aJ=aH.pageX-aI.left;if(X+ao<aJ){T(X+au.trackClickSpeed)}else{if(aJ<X){T(X-au.trackClickSpeed)}else{aF()}}},au.trackClickRepeatFreq),aF=function(){s&&clearInterval(s);s=null;b(document).unbind("mouseup.jsp",aF)};b(document).bind("mouseup.jsp",aF);return false}})}}function w(){F&&F.unbind("mousedown.jsp");al&&al.unbind("mousedown.jsp")}function ar(){b("html").unbind("dragstart.jsp selectstart.jsp mousemove.jsp mouseup.jsp mouseleave.jsp");ap&&ap.removeClass("jspActive");h&&h.removeClass("jspActive")}function S(s,aF){if(!av){return}if(s<0){s=0}else{if(s>i){s=i}}if(aF==c){aF=au.animateScroll}if(aF){N.animate(ap,"top",s,aa)}else{ap.css("top",s);aa(s)}}function aa(aF){if(aF==c){aF=ap.position().top}aj.scrollTop(0);H=aF;var aI=H==0,aG=H==i,aH=aF/i,s=-aH*(W-v);if(ag!=aI||aD!=aG){ag=aI;aD=aG;C.trigger("jsp-arrow-change",[ag,aD,M,k])}u(aI,aG);V.css("top",s);C.trigger("jsp-scroll-y",[-s,aI,aG])}function T(aF,s){if(!aB){return}if(aF<0){aF=0}else{if(aF>j){aF=j}}if(s==c){s=au.animateScroll}if(s){N.animate(h,"left",aF,ab)}else{h.css("left",aF);ab(aF)}}function ab(aF){if(aF==c){aF=h.position().left}aj.scrollTop(0);X=aF;var aI=X==0,aH=X==j,aG=aF/j,s=-aG*(Q-ah);if(M!=aI||k!=aH){M=aI;k=aH;C.trigger("jsp-arrow-change",[ag,aD,M,k])}r(aI,aH);V.css("left",s);C.trigger("jsp-scroll-x",[-s,aI,aH])}function u(aF,s){if(au.showArrows){am[aF?"addClass":"removeClass"]("jspDisabled");ac[s?"addClass":"removeClass"]("jspDisabled")}}function r(aF,s){if(au.showArrows){at[aF?"addClass":"removeClass"]("jspDisabled");
x[s?"addClass":"removeClass"]("jspDisabled")}}function J(s,aF){var aG=s/(W-v);S(aG*i,aF)}function K(aF,s){var aG=aF/(Q-ah);T(aG*j,s)}function Y(aR,aM,aG){var aK,aH,aI,s=0,aQ=0,aF,aL,aO,aN,aP;try{aK=b(aR)}catch(aJ){return}aH=aK.outerHeight();aI=aK.outerWidth();aj.scrollTop(0);aj.scrollLeft(0);while(!aK.is(".jspPane")){s+=aK.position().top;aQ+=aK.position().left;aK=aK.offsetParent();if(/^body|html$/i.test(aK[0].nodeName)){return}}aF=aw();aL=aF+v;if(s<aF||aM){aN=s-au.verticalGutter}else{if(s+aH>aL){aN=s-v+aH+au.verticalGutter}}if(aN){J(aN,aG)}viewportLeft=ay();aO=viewportLeft+ah;if(aQ<viewportLeft||aM){aP=aQ-au.horizontalGutter}else{if(aQ+aI>aO){aP=aQ-ah+aI+au.horizontalGutter}}if(aP){K(aP,aG)}}function ay(){return -V.position().left}function aw(){return -V.position().top}function ad(){aj.unbind(Z).bind(Z,function(aI,aJ,aH,aF){var aG=X,s=H;T(X+aH*au.mouseWheelSpeed*ah/(Q-ah),false);S(H-aF*au.mouseWheelSpeed*v/(W-v),false);return aG==X&&s==H})}function n(){aj.unbind(Z)}function ax(){return false}function I(){V.unbind("focus.jsp").bind("focus.jsp",function(s){if(s.target===V[0]){return}Y(s.target,false)})}function D(){V.unbind("focus.jsp")}function P(){var aF,s;C.attr("tabindex",0).unbind("keydown.jsp").bind("keydown.jsp",function(aJ){if(aJ.target!==C[0]){return}var aH=X,aG=H,aI=aF?2:16;switch(aJ.keyCode){case 40:S(H+aI,false);break;case 38:S(H-aI,false);break;case 34:case 32:J(aw()+Math.max(32,v)-16);break;case 33:J(aw()-v+16);break;case 35:J(W-v);break;case 36:J(0);break;case 39:T(X+aI,false);break;case 37:T(X-aI,false);break}if(!(aH==X&&aG==H)){aF=true;clearTimeout(s);s=setTimeout(function(){aF=false},260);return false}});if(au.hideFocus){C.css("outline","none");if("hideFocus" in aj[0]){C.attr("hideFocus",true)}}else{C.css("outline","");if("hideFocus" in aj[0]){C.attr("hideFocus",false)}}}function O(){C.attr("tabindex","-1").removeAttr("tabindex").unbind("keydown.jsp")}function B(){if(location.hash&&location.hash.length>1){var aG,aF;try{aG=b(location.hash)}catch(s){return}if(aG.length&&V.find(aG)){if(aj.scrollTop()==0){aF=setInterval(function(){if(aj.scrollTop()>0){Y(location.hash,true);b(document).scrollTop(aj.position().top);clearInterval(aF)}},50)}else{Y(location.hash,true);b(document).scrollTop(aj.position().top)}}}}function af(){b("a.jspHijack").unbind("click.jsp-hijack").removeClass("jspHijack")}function m(){af();b("a[href^=#]").addClass("jspHijack").bind("click.jsp-hijack",function(){var s=this.href.split("#"),aF;if(s.length>1){aF=s[1];if(aF.length>0&&V.find("#"+aF).length>0){Y("#"+aF,true);return false}}})}b.extend(N,{reinitialise:function(aF){aF=b.extend({},aF,au);an(aF)},scrollToElement:function(aG,aF,s){Y(aG,aF,s)},scrollTo:function(aG,s,aF){K(aG,aF);J(s,aF)},scrollToX:function(aF,s){K(aF,s)},scrollToY:function(s,aF){J(s,aF)},scrollBy:function(aF,s,aG){N.scrollByX(aF,aG);N.scrollByY(s,aG)},scrollByX:function(s,aG){var aF=ay()+s,aH=aF/(Q-ah);T(aH*j,aG)},scrollByY:function(s,aG){var aF=aw()+s,aH=aF/(W-v);S(aH*i,aG)},animate:function(aF,aI,s,aH){var aG={};aG[aI]=s;aF.animate(aG,{duration:au.animateDuration,ease:au.animateEase,queue:false,step:aH})},getContentPositionX:function(){return ay()},getContentPositionY:function(){return aw()},getIsScrollableH:function(){return aB},getIsScrollableV:function(){return av},getContentPane:function(){return V},scrollToBottom:function(s){S(i,s)},hijackInternalLinks:function(){m()}})}f=b.extend({},b.fn.jScrollPane.defaults,f);var e;this.each(function(){var g=b(this),h=g.data("jsp");if(h){h.reinitialise(f)}else{h=new d(g,f);g.data("jsp",h)}e=e?e.add(g):g});return e};b.fn.jScrollPane.defaults={showArrows:false,maintainPosition:true,clickOnTrack:true,autoReinitialise:false,autoReinitialiseDelay:500,verticalDragMinHeight:0,verticalDragMaxHeight:99999,horizontalDragMinWidth:0,horizontalDragMaxWidth:99999,animateScroll:false,animateDuration:300,animateEase:"linear",hijackInternalLinks:false,verticalGutter:4,horizontalGutter:4,mouseWheelSpeed:30,arrowButtonSpeed:30,arrowRepeatFreq:100,arrowScrollOnHover:false,trackClickSpeed:30,trackClickRepeatFreq:100,verticalArrowPositions:"split",horizontalArrowPositions:"split",enableKeyboardNavigation:true,hideFocus:false}
})(jQuery,this);

/**
 * jQuery urForms Plugin
 * Copyright: htmlReligion Team
 * URL: http://research.htmlreligion.com/custom-forms/
 * Version: 2.0 (2011-jan-27)
 * Requires: jQuery v1.3+
 * License: MIT (http://www.opensource.org/licenses/mit-license.php)
*/
(function($) {
	
	var UrForm = function(element, options) {
		var elem = $(element);
		var obj = this;
		 
		// default options for plugin
		var settings = $.extend({
			replaceRadios : false,
			replaceCheckboxes : false,
			replaceSelects : false,
			implementedClass : 'customizedForm',
			customizedClass : 'customizedElement',
			noCustomClass : 'no-transform',
			radioClass : 'customRadio',
			radioClassChecked : 'customRadioChecked',
			checkboxClass : 'customCheckbox',
			checkboxClassChecked : 'customCheckboxChecked',
			selectOptionHTML : '<div><ul>{options}</ul></div>',
			selectOptionItem : '<li><a href="#">{optionItem}</a></li>',
			selectClass : 'customSelect',
			selectDisabledClass : 'disabled-select',
			optionsClass : 'customOptions',
			optionsHiddenClass : 'customOptionsHidden',
			selectActiveClass : 'customSelectActive',
			selectImplemented : false,
			hideOnResize: true,
			hideOnScroll: false
		}, options || {});
		
		// init
		obj.initialize = function() {
			
			if (!$(this).hasClass(settings.implementedClass)) {
				
				obj.elements = {};
				
				// get form relations
				obj.getRelations();
				
				// replace radios
				if (settings.replaceRadios) {
					obj.customizeRadios();
				}
				
				// replace checkboxes
				if (settings.replaceCheckboxes) {
					obj.customizeCheckboxes();
				}
				
				// replace selects

				if (settings.replaceSelects) {
					obj.customizeSelects();
				}
				
				$(this).addClass(settings.implementedClass);
			}
		};
		
		// public
		// get form relations
		obj.getRelations = function() {
			// get elements
			obj.elements.inputs = [];
			obj.elements.selects = [];
			obj.elements.labels = [];
			elem.find('input').each(function () {
				if (!$(this).hasClass(settings.customizedClass) && !$(this).hasClass(settings.noCustomClass)) {
					obj.elements.inputs.push($(this));
				}
			});
			$('select', elem).each(function () {
				if (!$(this).hasClass(settings.customizedClass) && !$(this).hasClass(settings.noCustomClass)) {
					obj.elements.selects.push($(this));
				}
			});
			$('label', elem).each(function () {
				try {
					var labelFor = $(this).attr('for');
					if (labelFor && $('#' + labelFor).length) {
						if(!$('#' + labelFor).hasClass(settings.customizedClass) && !$('#' + labelFor).hasClass(settings.noCustomClass)) {
							obj.elements.labels.push($(this));
						}
					}
				} catch (labErr) {}
			});
			
			// get relations
			obj.elements.radios = [];
			obj.elements.radioLabels = [];
			obj.elements.checkboxes = [];
			obj.elements.checkboxLabels = [];
			
			var _rCount = 0;
			var _cCount = 0;
			
			for (i=0; i<obj.elements.inputs.length; i++) {
				if (obj.elements.inputs[i].attr('type') == "radio") {
					obj.elements.radios.push(obj.elements.inputs[i]);
					for (var _lCount=0; _lCount<obj.elements.labels.length; _lCount++) {
						if (obj.elements.inputs[i].attr('id') && obj.elements.labels[_lCount].attr('for') == obj.elements.inputs[i].attr('id')) {
							obj.elements.labels[_lCount].attr('targetId', _rCount);
							obj.elements.radioLabels.push(obj.elements.labels[_lCount]);
						}
					}
					_rCount++;
				}
				if (obj.elements.inputs[i].attr('type') == "checkbox") {
					obj.elements.checkboxes.push(obj.elements.inputs[i]);
					for (var _lCount=0; _lCount<obj.elements.labels.length; _lCount++) {
						if (obj.elements.inputs[i].attr('id') && obj.elements.labels[_lCount].attr('for') == obj.elements.inputs[i].attr('id')) {
							obj.elements.labels[_lCount].attr('targetId', _cCount);
							obj.elements.checkboxLabels.push(obj.elements.labels[_lCount]);
						}
					}
					_cCount++;
				}
			}
		};
		
		// public
		// replace input[type=checkbox]'s
		obj.customizeCheckboxes = function() {
			for (i=0, chn=obj.elements.checkboxes.length; i<chn; i++) {
				if (!obj.elements.checkboxes[i].hasClass(settings.customizedClass)) {
					obj.elements.checkboxes[i].addClass(settings.customizedClass);
					var replacedInputCheckbox = $('<div></div>');
					if (obj.elements.checkboxes[i].attr('checked') == true) {
						replacedInputCheckbox.addClass(settings.checkboxClassChecked);
					} else {
						replacedInputCheckbox.addClass(settings.checkboxClass);
					}
					replacedInputCheckbox.attr('customCheckboxId', 'customCheckbox' + i);
					obj.elements.checkboxes[i].parent().prepend(replacedInputCheckbox);
					obj.elements.checkboxes[i].custom = replacedInputCheckbox;
					replacedInputCheckbox.click(function () {
						var clickIndex = $(this).attr('customCheckboxId').replace('customCheckbox', '');
						retoggleCheckbox (clickIndex);
					});
				}
				//obj.elements.checkboxes[i].onkeydown = checkBySpace;
			}
			for (i=0, chln=obj.elements.checkboxLabels.length; i<chln; i++) {
				var _forAttr = obj.elements.checkboxLabels[i].attr('for');
				if (_forAttr && $('#' + _forAttr).length) {
					if (obj.elements.checkboxLabels[i].attr('targetId')) {
						obj.elements.checkboxLabels[i].click(function () {
							toggleCheckbox ($(this).attr('targetId'));
						});
					}
				}
			}
		};
		
		// private
		// retoggle checkboxes
		function retoggleCheckbox (_clickIndex) {
			var _state = false;
			if(obj.elements.checkboxes[_clickIndex].attr('checked') == true) {
				_state = false;
			} else {
				_state = true;
			}
			obj.elements.checkboxes[_clickIndex].attr('checked', _state);
			checkCheckbox(_clickIndex, _state);
		};
		
		// private
		// toggle checkboxes
		function toggleCheckbox (clickI) {
			if (obj.elements.checkboxes[clickI]) {
				if (obj.elements.checkboxes[clickI].attr('checked') == true) {
					checkCheckbox(clickI, false);
				} else {
					checkCheckbox(clickI, true);
				}		
			}
		};
		
		// private
		// checking checkbox
		function checkCheckbox(_indexClick, state) {
			var customAppr = obj.elements.checkboxes[_indexClick].custom;
			if (state == true) {
				customAppr.attr('class', settings.checkboxClassChecked);
				customAppr.attr('checked', true);
			}
			if (state == false) {
				customAppr.attr('class', settings.checkboxClass);
				customAppr.attr('checked', false);
			}
		};
		
		
		// private
		// toggle radio buttons
		function changeRadios (changeIndex) {
			for(var r = 0, rlen = obj.elements.radios.length; r < rlen; r++) {
				if(obj.elements.radios[r].attr('name') == obj.elements.radios[changeIndex].attr('name')) {
					obj.elements.radios[r]
						.attr('checked', false)
						.removeClass('checked');
				}
			}
			obj.elements.radios[changeIndex]
				.attr('checked', true)
				.addClass('checked');
			checkRadios(changeIndex);
		};
		
		// private
		// check radio buttons
		function checkRadios (checkIndex) {
			var customAppr = obj.elements.radios[checkIndex];
			for(var _r = 0, _rlen = obj.elements.radios.length; _r < _rlen; _r++) {
				if(obj.elements.radios[_r].custom || obj.elements.radios[_r].custom != 'undefined') {
					if((obj.elements.radios[_r].custom.hasClass(settings.radioClassChecked)) && obj.elements.radios[_r].attr('name') == customAppr.attr('name')) {
						obj.elements.radios[_r].custom.attr('class', settings.radioClass);
					}
				}
			}
			customAppr.trigger('change');
			customAppr.custom.attr('class', settings.radioClassChecked);
		};
		
		// public
		// replace input[type=radio]'s
		obj.customizeRadios = function() {
			for(i=0, iln = obj.elements.radios.length; i<iln; i++) {
				if(!obj.elements.radios[i].hasClass(settings.customizedClass)) {
					obj.elements.radios[i].addClass(settings.customizedClass);
					var replacedInputRadio = $('<div></div>');
					if(obj.elements.radios[i].attr('checked') == true) {
						replacedInputRadio.addClass(settings.radioClassChecked);
					} else {
						replacedInputRadio.addClass(settings.radioClass);
					}
					replacedInputRadio.attr('customRadioId', 'customRadio' + i);
					obj.elements.radios[i].parent().prepend(replacedInputRadio);
					obj.elements.radios[i].custom = replacedInputRadio;
					
					// click custom radio input
					replacedInputRadio.click(function () {
						var _clickIndex = $(this).attr('customRadioId').replace('customRadio', '');
						changeRadios(_clickIndex, obj.elements, settings.radioClass, settings.radioClassChecked);
					});
				}
			}
			for (i=0, ilen = obj.elements.radioLabels.length; i<ilen; i++) {
				var _forAttr = obj.elements.radioLabels[i].attr('for');
				if (_forAttr && $('#' + _forAttr).length) {
					if (obj.elements.radioLabels[i].attr('targetId')) {
						obj.elements.radioLabels[i].click(function () {
							checkRadios($(this).attr('targetId'), obj.elements, settings.radioClass, settings.radioClassChecked);
						});
					}
				}
			}
		};
		
		// private
		// show custom select options
		function showOptions(selectId) {
			var _customSelect = obj.elements.selects[selectId].customSelect;
			var _customSelectHeight = _customSelect.outerHeight();
			var _customOptions = obj.elements.selects[selectId].optionz;
			if (_customOptions && _customSelect) {
				if (elem.openedSelect && elem.openedSelect != _customOptions) {
					elem.openedSelect
						.removeClass(settings.optionsHiddenClass)
						.addClass(settings.optionsClass)
						.css({
							height : 'auto'
						});
				}
				if(_customOptions.hasClass(settings.optionsHiddenClass)) {
					_customOptions.css({
						left: '-9999px',
						top: getTopPosition(_customSelect) + _customSelectHeight + 'px'
					});
					hideOptions();
					_customOptions
						.removeClass(settings.optionsHiddenClass)
						.addClass(settings.optionsClass)
						.css({
							left: getLeftPosition(_customSelect) + 'px'
						});
					_customSelect.addClass(settings.selectActiveClass);
					elem.openedSelect = _customOptions;
					
					$(document).click(function (e) {
						if ($(e.target).parents('div.' + settings.selectClass).length == 0 && $(e.target).parents('div.' + settings.optionsClass).length == 0) {
							hideOptions();
						}
					});
				} else if(_customOptions.hasClass(settings.optionsClass)) {
					_customOptions
						.css({
							height : 'auto'
						})
						.removeClass(settings.optionsClass)
						.addClass(settings.optionsHiddenClass);
					hideOptions(); //hide
				}
			}
		};
		
		// private
		// hide custom select options
		function hideOptions() {
			if(elem.openedSelect){
				$('.' + settings.optionsClass).each(function(){
					$(this)
						.removeClass(settings.optionsClass)
						.addClass(settings.optionsHiddenClass);
				});
				$('.' + settings.selectActiveClass).each(function(){
					$(this).removeClass(settings.selectActiveClass);
				});
				elem.openedSelect = false;
			}
		};
		
		// private
		// custom selects event
		function customSelectEvent(_optionId, _selectIndex) {
			var customAppr = obj.elements.selects[_selectIndex];
			$('option', customAppr).each(function(optionId) {
				if(optionId == _optionId) {
					$(this).attr('selected', true);
				} else {
					$(this).attr('selected', false);
				}
			});
			var _customSelectTextNew = $('option', customAppr).eq(_optionId).text();
			customAppr.customSelect.find('span.bg-select-center').text(_customSelectTextNew);
			if (customAppr.change && obj.selectsAll) {
				eval(customAppr.change());
			}
			hideOptions();
		};
		function cardImageEvent(){
			$("#cards>img").each(function(index){

				$(this).click(function(){
                   
					//customSelectEvent(index, 0);
					$("#ccType :nth-child("+(index+1)+")").attr("selected", "selected");
					var val=$("#ccType :selected").val();
					
					if (val=="Amex")
					{
						$("#cvv2_help").html("(4 digit # on front of the card)");
						$("#cc_cvv2").attr("maxlength", "4");
					}
					else
					{
						$("#cvv2_help").html("(3 digit # on front of the card)");
						$("#cc_cvv2").val($("#cc_cvv2").val().substr(0,3));
						$("#cc_cvv2").attr("maxlength", "3");
					}
				});
			});
		}
		cardImageEvent();
		// public
		// live selects update
		obj.updateSelect = function(selectObject) {
			var updateSelectId = selectObject.attr('defaultselectid').replace('defaultSelect', '');
			var replacedOptions = settings.selectOptionHTML;
			var replacedOptionsItems = '';
			var customSelectBoxDefault = selectObject.find('option').eq(0).text();
			if(selectObject.attr('disabled')) 
						$("div[customselectid='customSelect"+updateSelectId+"']").addClass(settings.selectDisabledClass);
			else			
						$("div[customselectid='customSelect"+updateSelectId+"']").removeClass(settings.selectDisabledClass);
			selectObject.find('option').each(function (j) {
				var _oHTML = {
					optionItem : $(this).html()
				};
				replacedOptionsItems += settings.selectOptionItem.supplantstr(_oHTML);
				var _attrSelected = $(this).attr('selected');
				if(_attrSelected) {
					customSelectBoxDefault = selectObject.find('option').eq(j).text();
				}
			});
			var customSelectDropdown = selectObject.data('dOptions');
			var customSelectDropdownUl = $('ul', customSelectDropdown);
			if(customSelectDropdownUl.length) {
				customSelectDropdownUl.html(replacedOptionsItems);
				$('a', customSelectDropdownUl).each(function (j) {
					$(this)
						.attr('rel', j)
						.attr('class', updateSelectId);
					// click select dropdown option item
					$(this).click(function () {
						var _j = $(this).attr('rel');
						var _i = $(this).attr('class');
						if (_j && _i) {
							showOptions(_i);
							customSelectEvent(_j, _i);
						}
						return false;
					});
				});
			}
			var customSelectBox = selectObject.data('dCustomSelect');
			var customSelectBoxText = $('span.bg-select-center', customSelectBox);
			customSelectBoxText.html(customSelectBoxDefault);
		};
		
		// public
		// replace selects
		obj.customizeSelects = function() {
			// set string supplant method if undefined
			if(typeof String.prototype.supplantstr != 'function') {
				String.prototype.supplantstr = function (obj) {
					return this.replace(/{([^{}]*)}/g,
					function(a, b) {
						var r = obj[b];
						return typeof r === 'string' || typeof r === 'number' ? r : a;
					});
				};
			}
			obj.selectsAll = false;
			elem.openedSelect = false;
			for (i=0; i<obj.elements.selects.length; i++) {
				if (!obj.elements.selects[i].hasClass(settings.customizedClass)) {
					obj.elements.selects[i].index = i;
					var _selectWidth = parseInt(obj.elements.selects[i].width());
					var _defaultTxt = '';
					obj.elements.selects[i].find('option').each(function () {
						if ($(this).attr('selected')) {
							_defaultTxt = $(this).html();
						}
					});
					if (_defaultTxt=='') _defaultTxt = obj.elements.selects[i].find('option').eq(0).text();
					var replacedSelect = $('\
					<div class="' + settings.selectClass + '">\
					    <span class="bg-select-left"></span>\
					    <span class="disabled"></span>\
					    <span class="bg-select-center" customselecttext="customSelectText' + i + '">' + _defaultTxt + '</span>\
					    <a href="#" rel="' + i + '" class="selectButton"></a>\
					</div>');
					replacedSelect.addClass(obj.elements.selects[i].attr('class'));
					if(obj.elements.selects[i].attr('disabled')) {
						replacedSelect.addClass(settings.selectDisabledClass);
					}
					obj.elements.selects[i].parent().prepend(replacedSelect);
					// click select
					$('a', replacedSelect).click(function () {
						var _id = $(this).attr('rel');
						if (_id && parseInt(_id)==_id) {
							showOptions(_id);
						}
						return false;
					});
					var _leftWidth = parseInt(replacedSelect.find('.bg-select-left').width());
					var _rightWidth = parseInt(replacedSelect.find('.bg-select-center').css('marginRight'));
					replacedSelect
						.css({
							width : _selectWidth + _leftWidth + _rightWidth
						})
						.attr('customSelectId', 'customSelect' + i);
					$(obj.elements.selects[i]).attr('defaultSelectId', 'defaultSelect' + i);
					var replacedOptions = settings.selectOptionHTML;
					var replacedOptionsItems = '';
					obj.elements.selects[i].find('option').each(function (j) {
						var _oHTML = {
							optionItem : $(this).html()
						};
						replacedOptionsItems += settings.selectOptionItem.supplantstr(_oHTML);
					});
					var _sHTML = {
						options : replacedOptionsItems
					};
					replacedOptions = replacedOptions.supplantstr(_sHTML);
					replacedOptions = $(replacedOptions);
					replacedOptions
						.css({
							width : _selectWidth + _leftWidth + _rightWidth
						})
						.attr('customOptionsId', 'customOptions' + i);
					$('a', replacedOptions).each(function (j) {
						$(this)
							.attr('rel', j)
							.attr('class', i);
						// click select dropdown option item
						$(this).click(function () {
							var _j = $(this).attr('rel');
							var _i = $(this).attr('class');
							if (_j && _i) {
								showOptions(_i);
								customSelectEvent(_j, _i);
							}
							return false;
						});
					});
					obj.elements.selects[i].customSelect = replacedSelect;
					obj.elements.selects[i].optionz = replacedOptions;
					obj.elements.selects[i].data({
						dCustomSelect: replacedSelect,
						dOptions: replacedOptions
					});
					replacedOptions.addClass(obj.elements.selects[i].attr('class'));
					replacedOptions.select = obj.elements.selects[i];
					$('body').append(replacedOptions);
					obj.elements.selects[i].addClass(settings.customizedClass);
					replacedOptions.addClass(settings.optionsHiddenClass);
				}
			}
			obj.selectsAll = true;
			if(settings.selectImplemented && jQuery.isFunction(settings.selectImplemented)) {
				settings.selectImplemented.apply(this);
			}
			
			// hide select's dropdown on window resize
			if (settings.hideOnResize) {
				$(window).resize(function () {
					$('.' + settings.optionsClass).each(function () {
						$(this)
							.removeClass(settings.optionsClass)
							.addClass(settings.optionsHiddenClass);
					});
					$('.' + settings.selectActiveClass).each(function () {
						$(this).removeClass(settings.selectActiveClass);
					});
				});
			}
			
			// hide select's dropdown on window scroll
			if (settings.hideOnScroll) {
				$(window).scroll(function () {
					$('.' + settings.optionsClass).each(function () {
						$(this)
							.removeClass(settings.optionsClass)
							.addClass(settings.optionsHiddenClass);
					});
					$('.' + settings.selectActiveClass).each(function () {
						$(this).removeClass(settings.selectActiveClass);
					});
				});
			}
		};
		
		// private
		// get left position
		var getLeftPosition = function(selectObject) {
			var objectOffset = selectObject.offset();
			return objectOffset.left;
		};
		
		// private
		// get top position
		var getTopPosition = function(selectObject) {
			var objectOffset = selectObject.offset();
			return objectOffset.top;
		};
		
		// init
		obj.initialize();
	};
	$.fn.urForm = function(options) {
		return this.each(function() {
			var element = $(this);
			if (element.data('urForm')) return;
			var urForm = new UrForm(this, options);
			element.data('urForm', urForm);
		});
	};
})(jQuery);

// star rating
function initStars() {
	$('.rating-holder').each(function(){
		if (!$(this).hasClass('rating-holder-implemented')) {
			var starsHolder = $(this);
			var starsUl = $('ul', starsHolder);
			var starsState = $('.stars-rate', starsHolder);
			if (!starsUl.hasClass('stars-disabled')) {
				var starsLi = $('li', starsUl);
				var starsA = $('a', starsLi);
				var starsInput = $('input', starsHolder);
				starsUl.hover(function () {
					starsLi.each(function (_el) {
						if ($(this).hasClass('hover')) {
							starsUl.attr('_hover',_el);
							$(this).removeClass('hover');
						}
						if ($(this).hasClass('active')) {
							starsUl.attr('_active',_el);
							$(this).removeClass('active');
						}
					});
				},function(){
					if ($(this).attr('_hover') && !starsLi.eq($(this).attr('_hover')).hasClass('hover') && !$(this).attr('_active')) {
						starsLi.eq($(this).attr('_hover')).addClass('hover');
					}
					if ($(this).attr('_active') && !starsLi.eq($(this).attr('_active')).hasClass('active')) {
						starsLi.eq($(this).attr('_active')).addClass('active');
					}
					return false;
				});
				starsA.click(function () {
					
					starsUl.attr('_active',starsLi.index(this.parentNode));
					if (!starsLi.eq(starsUl.attr('_active')).hasClass('active')) {
						starsLi.eq(starsUl.attr('_active')).addClass('active');
					}
					if (starsState.length) {
						starsState.text(starsLi.eq(starsUl.attr('_active')).find('a').attr('title'));
					}
					var starsUrl = $(this).attr('rel');
					if (starsUrl) {
						// ajax star rating
						var _this = $(this);
						$.ajax({
							type: "POST",
							url: starsUrl,
							success: function (msg) {
								stars.append(msg);
								starsUl.remove();
							}
						});
					} else {
						// static star rating
						starsInput.val(parseInt(starsUl.attr('_active'))+1);
						var order_number=$('#order_number').html();
						
						if (order_number>0) 
							$.post("ajax_php/rate_order.php",{order_number:order_number,"rating":starsInput.val()},
									function(data)
									{
					
									}
									);
						else
						   {
						   	$.post("ajax_php/blog_ajax.php",{"mode":1,"art_id":$("#art").val(),"rating":starsInput.val()},
									function(data)
									{
										$("#avg_score").html(parseFloat(data).toFixed(2));
										$("#total_rating").html(parseInt($("#total_rating").html())+1);
					
									}
									);
						   }		
					}
					// star rating confirm function
					$(this).blur();
					return false;
				});
			}
			starsHolder.addClass('rating-holder-implemented');
		}
	});
}

// input hide text on focus
function initInputPlaceholder() {$('.focusable').each(function(){$(this).attr('placeholder',$(this).val());$(this).focus(function(){$(this).addClass('focused');if($(this).val()==$(this).attr('placeholder'))$(this).val('')}).blur(function(){$(this).removeClass('focused');if($(this).val()=='')$(this).val($(this).attr('placeholder'))})})}

// security popup
function initSecurityPopup() {
	// options
	var secureTipMargin = -30,
	secureTipDuration = 200
	
	$('div.b-secure').each(function() {
		if(!$(this).hasClass('b-secure-implemented')) {
			var secure = $(this);
			var securePopup = $('div.tip-warning', secure);
			securePopup.css({
				marginTop: secureTipMargin,
				textShadow: '0 1px 1px #fff',
				opacity: 0,
				display: 'none'
			});
			secure
				.mouseenter(function() {
					securePopup
						.css({
							display: 'block'
						})
						.stop()
						.animate({
							marginTop: 0,
							opacity: 1
						}, {
							duration: secureTipDuration,
							complete: function() {
								if($.browser.msie) {
									securePopup.css({
										opacity: 'auto'
									});
								}
							}
						});
				})
				.mouseleave(function() {
					securePopup
						.stop()
						.animate({
							marginTop: secureTipMargin,
							opacity: 0
						}, {
							duration: secureTipDuration,
							complete: function() {
								securePopup.css({
									display: 'none'
								});
							}
						});
				});
			
			secure.addClass('b-secure-implemented');
		}
	});
}

// tabs
function initTabs() {
	var _atab = $('.tabset a');
	var _activeClass = 'current';
	
	_atab.eq(0).addClass('first-child');

	function setTabs(){
		_atab.each(function(){
			var _tabId = $(this).attr('rel');
			if(_tabId!='' && _tabId!='#') {
				if($(_tabId).length){
					if($(this).hasClass(_activeClass)) $(_tabId).css({
						position:'static',
						left:0,
						top:0
					});
					else $(_tabId).css({
						position:'absolute',
						left:'-7777px',
						top:'-7777px'
					});
				}	
			}
		});
	}
	setTabs();
	
	// click
	_atab.click(function(){
		if ($(this).hasClass(_activeClass)) {
			return false;
		} else {
			_atab.removeClass(_activeClass);
			$(this).addClass(_activeClass);
			setTabs();
			$('div.customOptions').each(function() {
				$(this)
					.removeClass('customOptions')
					.addClass('customOptionsHidden');
			});
			$('div.customSelectActive').each(function() {
				$(this).removeClass('customSelectActive');
			});
		}
		return false;
	});
}

(function($) {
	var UrPopup = function(element, options) {
		var elem = $(element);
		var obj = this;
		var settings = $.extend({
			popupShowTime: 200,
			overlayShowTime: 200,
			popupHideTime: 200,
			overlayHideTime: 200,
			popupHiddenClass: 'popup-hidden',
			implementedClass: 'popup-implemented',
			closeLink: 'a.popup-close',
			overlayOpacity: .5,
			contentHolder: $('div.bone').eq(0),
			beforeShowPopup: false,
			beforeHidePopup: false,
			onScroll: false
		}, options || {});
		
		// init
		obj.initialize = function() {
			// popup caller
			var popupId = elem.attr('href');
			if(popupId && popupId!='') {
				popupId = popupId.substr(popupId.indexOf("#"));
				if(popupId!='#') {
					popupId = $(popupId);
					if(popupId.length) {
						if(!popupId.hasClass(settings.implementedClass)) {
							var popupClose = $(settings.closeLink, popupId);
							popupClose.click(function() {
								obj.hidePopup(popupId);
								return false;
							});
							popupId.addClass(settings.implementedClass);
						}
						elem.click(function() {
							obj.showPopup(popupId);
							return false;
						});
					}
				}
			}
			
			// overlay
			var _popupOverlay = $('#popup-overlay');
			if (!_popupOverlay.length){
				_popupOverlay = $('<span id="popup-overlay"></span>');
				$('body').append(_popupOverlay);
			}
			obj.popupOverlay = _popupOverlay;
			obj.contentHolder = settings.contentHolder;
			if($.browser.msie) {
				obj.popupOverlay.css({
					width: obj.contentHolder.width(),
					height: obj.contentHolder.height()
				});
			}
			obj.popupOverlay
				.css({
					opacity: settings.overlayOpacity
				})
				.hide();
			
			// set visible popup position on window resize
			$(window).resize(function() {
				var visPopup = $('div.popup').filter(':not(.' + settings.popupHiddenClass + ')').eq(0);
				if(visPopup.length) {
					obj.setPopupPosition(visPopup);
				}
			});
			
			// window scroll functionality
			if(settings.onScroll && $.isFunction(settings.onScroll)) {
				$(window).scroll(function() {
					settings.onScroll.apply(obj);
				});
			}
			
			// hide popup by clickin' overlay
			obj.popupOverlay
				.unbind('click')
				.click(function() {
					var visPopup = $('div.popup').filter(':not(.popup-hidden)').eq(0);
					if(visPopup.length) {
						obj.hidePopup(visPopup);
					}
				});
		}();
		
		// position
		obj.setPopupPosition = function(_popupObj) {
			var winHeight = 0;
			var winWidth = 0;
			if (window.innerHeight) {
				winHeight = window.innerHeight;
				winWidth = window.innerWidth;
			} else {
				winHeight = document.documentElement.clientHeight;
				winWidth = document.documentElement.clientWidth;
			}
			// popup top position
			var popupHeight = _popupObj.outerHeight();
			if (winHeight > popupHeight) {
				if (!window.innerHeight) {
					_popupObj.css({
						position: 'absolute',
						top: (document.documentElement.scrollTop + (winHeight - popupHeight) / 2)+"px"
					});
				} else {
					_popupObj.css({
						position: 'fixed',
						top: ((winHeight - _popupObj.outerHeight()) / 2)+"px"
					});
				}
			} else {
				_popupObj.css({
					position: 'absolute',
					top: 0
				});
				if($.browser.msie){
					obj.popupOverlay.css('height', popupHeight);
				}
			}
			// popup left position
			var popupWidth = _popupObj.outerWidth();
			if (winWidth > popupWidth) {
				_popupObj.css({
					left: (winWidth - popupWidth) / 2
				});
			} else {
				_popupObj.css({
					position: 'absolute',
					left: 0
				});
			}

			var winMinWidth = obj.contentHolder.outerWidth();
			var pageBody = $('body');
			if ($.browser.msie) {
				if (winHeight > pageBody.innerHeight()) {
					obj.popupOverlay.css('height', winHeight);
				} else {
					obj.popupOverlay.css('height', pageBody.innerHeight());
				}
				if (winWidth < winMinWidth) {
					obj.popupOverlay.css('width', winMinWidth);
				} else {
					obj.popupOverlay.css('width', '100%');
				}
			}
		}
		
		// show overlay
		obj.showOverlay = function(callback) {
			if($.browser.msie) {
				obj.popupOverlay.css({
					width: obj.contentHolder.width(),
					height: obj.contentHolder.height()
				});				
			}
			obj.popupOverlay.fadeIn(settings.overlayShowTime, function() {
				if(callback && $.isFunction(callback)) {
					callback.apply(this);
				}
			});
		}
		
		// hide overlay
		obj.hideOverlay = function(callback) {
			obj.popupOverlay.fadeOut(settings.overlayHideTime, function() {
				if(callback && $.isFunction(callback)) {
					callback.apply(this);
				}
			});
		}
		
		// show popup
		obj.showPopup = function(_popupObj) {
			if(settings.beforeShowPopup && $.isFunction(settings.beforeShowPopup)) {
				settings.beforeShowPopup.apply(obj);
			}
			obj.showOverlay(function() {
				obj.setPopupPosition(_popupObj);
				if($.browser.msie) {
					_popupObj.removeClass(settings.popupHiddenClass)
				} else {
					_popupObj
						.removeClass(settings.popupHiddenClass)
						.css({
							opacity: 0
						})
						.animate({
							opacity: 1
						}, {
							duration: settings.popupHideTime
						});
				}
			});
		}
		
		// hide popup
		obj.hidePopup = function(_popupObj, afterHide) {
			if(settings.beforeHidePopup && $.isFunction(settings.beforeHidePopup)) {
				settings.beforeHidePopup.apply(obj);
			}
			if($.browser.msie) {
				_popupObj.addClass(settings.popupHiddenClass);
				obj.hideOverlay(function() {
					if(afterHide && $.isFunction(afterHide)) {
						afterHide.apply(this);
					}
				});
			} else {
				_popupObj.animate({
					opacity: 0
				}, {
					duration: settings.popupHideTime,
					complete: function() {
						_popupObj.addClass(settings.popupHiddenClass);
						obj.hideOverlay(function() {
							if(afterHide && $.isFunction(afterHide)) {
								afterHide.apply(this);
							}
						});
					}
				});
			}
		}
	};
	$.fn.urPopup = function(options) {
		return this.each(function() {
			var element = $(this);
			if (element.data('urPopup')) return;
			var urPopup = new UrPopup(this, options);
			element.data('urPopup', urPopup);
		});
	};
})(jQuery);

function initPage() {
	initTestimonials();
	initBlogPreview();
	initStars();
	initInputPlaceholder();
	//initSecurityPopup();
	initTabs();
}
$(initPage);
$(window).load(function() {
	// custom forms
	
	if(typeof window.customForm=='undefined') {
		window.customForm = false;
	}
	customForm = $('div.custom-form');
	customForm.urForm({
		replaceRadios: true,
		replaceCheckboxes: true,
		replaceSelects: true,
		selectOptionHTML: '<div class="select-holder"><div class="scroll-pane-select"><ul>{options}</ul></div><div class="select-bt"><div class="select-bl"></div><div class="select-bc"></div><div class="select-br"></div></div></div>',
		selectImplemented: function () {
			$('div.customOptionsHidden').each(function() {
				var customOptz = $(this);
				customOptz
					.removeClass('customOptionsHidden')
					.addClass('customOptions');
				var selectScrollPane = $('div.scroll-pane-select', customOptz);
				if(parseInt(selectScrollPane.height())>182) {
					selectScrollPane.css({
						height: '182px'
					});
					selectScrollPane.jScrollPane({
						showArrows: true,
						horizontalGutter: 0,
						verticalGutter: 0,
						verticalDragMinHeight: 22,
						verticalDragMaxHeight: 22
					});
					$('div.select-bt', customOptz).addClass('customOptionsScroll');
				}
				customOptz
					.removeClass('customOptions')
					.addClass('customOptionsHidden');
			});
		}
	});
	
	window.customForm = $('div.custom-form').data('urForm');
});

