//Carousel
(function($){$.preloadImage=function(image,callback){var self=this;this.file=image;this.callback=callback;this.loaded=false;this.aborted=false;this.error=false;this.image=new Image();this.cancelEvent=function(){if(this.image&&this.image.onload){this.image.onload=null;}
if(this.image&&this.image.onabort){this.image.onabort=null;}
if(this.image&&this.image.onerror){this.image.onerror=null;}};this.on_load=function(){self.loaded=true;if(self.callback&&typeof self.callback=="function"){self.callback.apply(self,["loaded"]);}
self.cancelEvent();};this.on_error=function(){self.error=true;if(self.callback&&typeof self.callback=="function"){self.callback.apply(self,["error"]);}
self.cancelEvent();};this.on_abort=function(){self.aborted=true;if(self.callback&&typeof self.callback=="function"){self.callback.apply(self,["aborted"]);}
self.cancelEvent();};this.image.src=this.file;this.autoCheckIntervalId=0;this.autoCheck=function(){if(self.loaded||self.aborted||self.error){window.clearInterval(self.autoCheckIntervalId);return;}
if(self.image&&self.image.complete){window.clearInterval(self.autoCheckIntervalId);self.loaded=true;if(self.callback&&typeof self.callback=="function"){self.callback.apply(self,["loaded"]);}
self.cancelEvent();return;}
if(self.image&&(self.image.width||self.image.height)){window.clearInterval(self.autoCheckIntervalId);self.loaded=true;if(self.callback&&typeof self.callback=="function"){self.callback.apply(self,["loaded"]);}
self.cancelEvent();return;}};this.autoCheckIntervalId=window.setInterval(self.autoCheck,500);};$.preloadImages=function(images,callback){if(typeof images=="string"){return new $.preloadImage(images,callback);}
var self=this;this.images=images;this.callback=callback;this.all_complete=false;this.preloader=[];this.checkComplete=function(){if(self.preloader.length<self.images.length)return;if(this.all_complete)return;var all_complete=true;var j=0;for(var i=0,n=self.preloader.length;i<n;i++){if(self.preloader[i]&&self.preloader[i].loaded){j++;}else{all_complete=false;}}
if(all_complete){this.all_complete=true;if(self.callback&&typeof self.callback=="function"){self.callback.apply(self);}}};for(var i=0,n=images.length;i<n;i++){this.preloader[i]=new $.preloadImage(this.images[i],function(){self.checkComplete();});}
this.autoCheckIntervalId=0;this.autoCheck=function(){if(this.all_complete){window.clearInterval(self.autoCheckIntervalId);}
self.checkComplete();};this.autoCheckIntervalId=window.setInterval(self.autoCheck,500);};$.fn.carousel=function(options){var isMethodCall=(typeof options=="string")||false;var args=arguments;$(this).each(function(){var carousel=$(this).data("carousel");if(carousel&&isMethodCall){if(carousel[options]&&$.isFunction(carousel[options])){carousel[options].apply(carousel,$.makeArray(args).slice(1));}}else if(!isMethodCall&&!carousel){carousel=new $.carousel(this,options);$(this).data("carousel",carousel);}});return this;};$.carousel=function(elem,options){this.elem=elem;this.options=$.extend({},$.carousel.defaults,options);this.init();};$.extend($.carousel,{defaults:{duration:1500,autoMode:1,autoMode_waitBeforeStart:8000,autoMode_delay:9000},prototype:{init:function(){var self=this;this.ready=false;this.slides=$(".carousel_contents ul li",this.elem);if(!this.slides.length)return;this.baseurl=$('script[src*='+window.location+']:first').attr('src');this.baseurl=this.baseurl.substring(0,this.baseurl.indexOf(window.location));this.loader=$(".carousel_loader",this.elem);this.autoModeTimeout=0;this.preloadImages();},preloadImages:function(){var to_preload=[];var self=this;$(".carousel_contents img",this.elem).each(function(){to_preload.push(this.src);});var preloader=new $.preloadImages(to_preload,function(){self.loaded.apply(self,[]);});},loaded:function(){var self=this;$(".carousel_loader",this.elem).animate({opacity:0},{duration:500,queue:false,complete:function(){$(this).hide().css("opacity","");}});$(".carousel_container",this.elem).css({opacity:0,display:"block"}).animate({opacity:1},{duration:750,queue:false,complete:function(){$(this).css("opacity","");}});this.slide_width=$(this.slides[0]).innerWidth();this.slide_height=$(this.slides[0]).innerHeight();this.slideContainer=$(".carousel_contents ul",this.elem);this.slideContainer.css({width:(this.slide_width*this.slides.length)+"px",height:this.slide_height+"px"});this.slideContainer.parent().css({height:this.slide_height+"px"});this.menu=$(".carousel_menu a",this.elem);$(this.menu).each(function(){$(this).bind("click",function(){self.resetAutoMode();self.moveTo.apply(self,[this]);return false;});});this.slideContainer.css({left:0});this.menu.removeClass("selected").filter(":eq(0)").addClass("selected");this.resetAutoMode();},moveTo:function(a){if($(a).is(".selected"))return;if(a.hash&&a.hash.replace('#','')!=""){var target=$(a.hash);if(target.length){var target_idx=this.slides.index(target);if(target_idx>=0){this.slideContainer.stop();this.slideContainer.animate({left:-(target_idx*this.slide_width)+"px"},{duration:this.options.duration,easing:"easeInOutExpo",queue:false});}}}
this.menu.not(a).removeClass("selected");$(a).addClass("selected");},clearAutoMode:function(){if(this.autoModeTimeout>0){window.clearTimeout(this.autoModeTimeout);}
this.autoModeTimeout=0;},resetAutoMode:function(){var self=this;this.clearAutoMode();this.autoModeTimeout=window.setTimeout(function(){self.autoNext();},this.options.autoMode_waitBeforeStart);},autoNext:function(){var cur,cur_next,self=this;this.clearAutoMode();cur=$(".carousel_menu a.selected",this.elem);if(!cur.length){cur=$(".carousel_menu a:eq(0)",this.elem);}
if(cur){cur=$(cur[0]);cur_next=$(cur).parents("li").next();if(!cur_next.length){cur_next=$(cur).parents("ul").find("li:eq(0)");}}
if(!cur_next)return;cur_next=$($("a",cur_next[0])[0]);if(cur){cur.removeClass("selected");}
this.moveTo($(cur_next).get(0));this.autoModeTimeout=window.setTimeout(function(){self.autoNext();},this.options.autoMode_delay);}}});$().ready(function(){$('.carousel').carousel();});})(jQuery);


function init_defText() {
	(function($){
		var changedClass = "jDefText_changed";
				
		$(":input.jDefText[type='text'], textarea.jDefText").each(function(){
			var onFocus = false;
			var elem = this;
			$(this).bind("focus.jDefText", function(){
				onFocus = true;
				if (this.value == this.defaultValue) {
					this.value = "";
				}
				$(this).addClass(changedClass);
			});
			$(this).bind("blur.jDefText", function(){
				onFocus = false;
				if (this.value == "") {
					this.value = this.defaultValue;
					$(this).removeClass(changedClass);
				}
			});
			$(this).bind("change.jDefText", function(){
				if (!onFocus) {
					$(this).triggerHandler("focus");
					$(this).triggerHandler("blur");
				}
			});
			//form reset
			if ($(this).parents("form").length) {
				$(this).parents("form").bind("reset.jDefText", function(){
					elem.value = elem.defaultValue;
					$(elem).removeClass(changedClass);
				});
			}
			if (this.value == this.defaultValue) {
				$(this).removeClass(changedClass);
			} else {
				$(this).addClass(changedClass);
			}
			
		});
	})(jQuery);
	}


(function($){
	var all_menu = [];
	
	function _subnav(elem, submenuSelector) {
		var elem = $(elem);
		
		var	parent = elem.parent(),
			a = $(">a", elem),
			width = elem.outerWidth(), w,
			height = elem.outerHeight(),
			offset = elem.offset(),
			SUBMENU = $(submenuSelector, elem),
			siblings = elem.siblings(),
			hideTimeout = 0;
			
		var SUBMENU = $(submenuSelector, elem);
		var siblings = elem.siblings();
			
		var clearHideTimeout = function() {
			if (hideTimeout > 0) {
				window.clearTimeout(hideTimeout);
				hideTimeout = 0;
			}
		};
		
		var startHideTimeout = function() {
			clearHideTimeout();
			hideTimeout = window.setTimeout(function(){
				elem.trigger("hidemenu.NAV");
			}, 200);
		};
		
		elem.unbind(".NAV")
			.bind({
				"mouseover.NAV": function() {
					elem.trigger("showmenu.NAV");
				},
				"mouseout.NAV": function() {
					startHideTimeout();
				},
				"showmenu.NAV": function() {
					var o = elem.offset();
					clearHideTimeout();
					$(all_menu).not(elem).trigger("hidemenu.NAV");
					//siblings.trigger("hidemenu.NAV");
					elem.addClass("active");
					if (SUBMENU.length > 0) {
						SUBMENU.css({
							left: o.left + "px",
							top: (o.top + height) + "px"
						});
						SUBMENU.show();
					}
				},
				"hidemenu.NAV": function() {
					elem.removeClass("active");
					if (SUBMENU.length > 0) {
						SUBMENU.hide();
					}
				}
			});
			
		if (SUBMENU.length > 0) {
			$(SUBMENU).bind("mouseover.NAV", function(){
				elem.trigger("mouseover.NAV");
				clearHideTimeout();
			});
			$(SUBMENU).bind("mouseout.NAV", function(){
				elem.trigger("mouseout.NAV");
				startHideTimeout();
			});
		}
		
		if (SUBMENU.length > 0) {
			
			SUBMENU.appendTo( $("body") );
			w = SUBMENU.width();
			SUBMENU.hide();
			width = elem.outerWidth();
			
			if (SUBMENU.is(".SUBNAV_custom")) {
				var custom_shadow = $("<div class='SUBNAV_custom_shadow'></div>");
				custom_shadow.appendTo(SUBMENU).css({
					width: (SUBMENU.outerWidth() - width + 20) + "px"
				});
				SUBMENU.css({
					left: offset.left + "px",
					top: (offset.top + height) + "px",
					visibility:"visible"
				});
				
				$(">ul>li:first", SUBMENU).addClass("first");
				$(">ul>li:last", SUBMENU).addClass("last");
				
			} else {
				if (w > width) {
					width = w;
				}
				SUBMENU.css({
					width:width+"px",
					left: offset.left + "px",
					top: (offset.top + height) + "px",
					visibility:"visible"
				});
			}
			
		}
		
		all_menu.push(elem[0]);
	};
	
	function _sublocnav(elem, submenuSelector) {
		var elem = $(elem);
		
		var	parent = elem.parent(),
			a = $(">a", elem),
			width = elem.outerWidth(), w,
			height = elem.outerHeight(),
			offset = elem.offset(),
			SUBMENU = $(submenuSelector, elem),
			menudivHeight = $('.LOCNAV .sub-menu').innerHeight(),
			siblings = elem.siblings(),
			hideTimeout = 0;
			
		
		var SUBMENU = $(submenuSelector, elem);
		var siblings = elem.siblings();
		var clearHideTimeout = function() {
			if (hideTimeout > 0) {
				window.clearTimeout(hideTimeout);
				hideTimeout = 0;
			}
		};
		
		var startHideTimeout = function() {
			clearHideTimeout();
			hideTimeout = window.setTimeout(function(){
				elem.trigger("hidemenu.LOCNAV");
			}, 200);
		};
		
		//alert(menudivHeight);
		elem.unbind(".LOCNAV")
			.bind({
				"mouseover.LOCNAV": function() {
					elem.trigger("showmenu.LOCNAV");
				},
				"mouseout.LOCNAV": function() {
					startHideTimeout();
				},
				"showmenu.LOCNAV": function() {
					var o = elem.offset();
					clearHideTimeout();
					$(all_menu).not(elem).trigger("hidemenu.LOCNAV");
					//siblings.trigger("hidemenu.LOCNAV");
					elem.addClass("active");
					if (SUBMENU.length > 0) {
						SUBMENU.show();
						
						SUBMENU.css({
							left: o.left + "px",
							top: (o.top  - menudivHeight) + "px"
						});
						
					}
				},
				"hidemenu.LOCNAV": function() {
					elem.removeClass("active");
					if (SUBMENU.length > 0) {
						SUBMENU.hide();
					}
				}
			});
			
		if (SUBMENU.length > 0) {
			$(SUBMENU).bind("mouseover.LOCNAV", function(){
				elem.trigger("mouseover.LOCNAV");
				clearHideTimeout();
			});
			$(SUBMENU).bind("mouseout.LOCNAV", function(){
				elem.trigger("mouseout.LOCNAV");
				startHideTimeout();
			});
		}
		
		if (SUBMENU.length > 0) {
			
			SUBMENU.appendTo( $("body") );
			w = SUBMENU.width();
			h = SUBMENU.height();
			menudivHeight = SUBMENU.outerHeight();
			SUBMENU.hide();
			width = elem.outerWidth();
			height = elem.outerHeight();
			
			 
			if (w > width) {
				width = w;
			}
			
			
			
			SUBMENU.css({
				height:h+"px",
				width:w+"px",
				left: offset.left + "px",
				top: (offset.top  + height) + "px",
				visibility:"visible"
			});
			 
			
		}
		
		all_menu.push(elem[0]);
	};
	
	$(function(){
		$(".NAV>.dmn>ul>li").each(function(){
			var ul = $(">ul:eq(0)", this);
			var pClass = ul.closest(".NAV").parent().attr("class");
			if (ul.length > 0) {
				
				
				ul.addClass("cf").wrap( $("<div />").addClass("SUBNAV"));
				if ( $("ul", ul).length > 0 ) {
					ul.parent().addClass("SUBNAV_" + pClass + "  SUBNAV_custom SUBNAV_COLS");
					$("ul", ul).each(function(){
						$("a:first", $(this).parent()).addClass("menu-item-header");
					});
				}
			}
		});
		
		
		$(".LOCNAV>.dmn>ul>li").each(function(){
			var ul = $(">ul:eq(0)", this);
			var pClass = ul.closest(".LOCNAV").parent().attr("class");
			if (ul.length > 0) {
				ul.addClass("cf").wrap( $("<div />").addClass("SUBNAV"));
				if ( $("ul", ul).length > 0 ) {
					ul.parent().addClass("SUBNAV_" + pClass + "  SUBNAV_custom SUBNAV_COLS");
					$("ul", ul).each(function(){
						$("a:first", $(this).parent()).addClass("menu-item-header");
					});
				}
			}
		});
		
		$(".NAV>.dmn>ul>li").each(function(){
			new _subnav(this, ".SUBNAV");
		});
		
		$(".LOCNAV>.dmn>ul>li").each(function(){
			new _sublocnav(this, ".SUBNAV");
		});
		all_menu = $.unique(all_menu);
		
		var path = location.pathname.substring(1);
		if ( path ) $('ul.menu a[href$="' + path + '"]').attr('class', 'selected');
	});
})(jQuery);



$(document).ready(function(){
	equalHeight($(".mainBox>.wrapper>.box"));	
	//Handles Newsletter AJAX paging
	$("#next").live("click", function() {
		$("#mainContent").fadeOut(400, function() {
			$.get("newsletter-ajax.php", {page: $("#hnext").val()}, function(data) {
				$("#mainContent").html(data);
				$("#mainContent").fadeIn(400);
			});
		});
		return false;
	});
	$("#prev").live("click", function() {
		$("#mainContent").fadeOut(400, function() {
			$.get("newsletter-ajax.php", {page: $("#hprev").val()}, function(data) {
				$("#mainContent").html(data);
				$("#mainContent").fadeIn(400);
			});
		});
		return false;
	});
	$(".pagenum").live("click", function() {
		var num = $(this).text();
		$("#mainContent").fadeOut(400, function() {
			$.get("newsletter-ajax.php", {page: num}, function(data) {
				$("#mainContent").html(data);
				$("#mainContent").fadeIn(400);
			});
		});
		return false;
	});
	$('a[rel*=facebox]').facebox();
	$('.tTip').tipTip({defaultPosition: "top", maxWidth: "320px", delay: 300});
	$(".colorbox").colorbox({width:"80%", height:"80%", iframe:true});
	
	//Start
	$("#spirinetdropdown").css({border: "3px solid #323465", textAlign: "center", width: "194px"});
	$("#spirinetdropdown img").css("border", "0");
	$("#spirinetdropdown a").css("color", "#252F6A");
	$("#spirinetdropdown a").click(function() {
		window.open(this.href, '_blank');
		return false;
	});
	$("#spirinetgetyours").css({fontSize: "11px", marginLeft: "66px", display: "block", marginTop: "7px", marginBottom: "2px"});
	var a;
	var b;
	$("#spirinettools").css("display", "block");
	$("#spirinettools").hover(function() {
		clearTimeout(a);
		clearTimeout(b);
		$("#spirinetdropdown").css("display", "block");
	}, function() {
		a = setTimeout("$('#spirinetdropdown').css('display', 'none')", 700);
	});

	$("#spirinetdropdown").hover(function() {
		clearTimeout(a);
		clearTimeout(b);
		$(this).css("display", "block");
	}, function() {
		b = setTimeout("$('#spirinetdropdown').css('display', 'none')", 700);
	});
	$("#spirinetdropdown a").hover(function() {
		$(this).css("color", "#E88600");
	}, function() {
		$(this).css("color", "#252F6A");
	});
	$("#spirinettools").click(function() {
		window.open("http://tools.spirinet.com/", "mywindow", "width = 830, height = 700, toolbar = no, location = no, menubar = no, directories = no, status = no");
		return false;
	});
	
	
	init_defText();
 
});

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}

function initCaptcha(elem) {
	$(".captcha_btn_refresh a",elem).bind("click.captcha", function(){
		var url = this.href;
		url += "&"+(new Date()).getTime();
		$(".captcha_image img",elem).attr("src", url);
		
		this.blur();
		return false;
	});
}

