(function($) {
	$.fn.equalHeights = function(minHeight, maxHeight) {
		tallest = (minHeight) ? minHeight : 0;
		this.each(function() {
			if($(this).height() > tallest) {
				tallest = $(this).height();
			}
		});
		if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
		return this.each(function() {
			$(this).height(tallest).css("overflow","hidden");
		});
	}
})(jQuery);

(function($) {
	function hideContent(anim) {
		var content = $(this);
		var height = content.data("showHide_contentHeight");
		var anim = (anim == undefined) ? true : anim;
		
		content.stop();
		if (anim) {
			content.animate({height:0}, {queue:false, duration:600, easing:"easeOutExpo", complete:function(){
				$(this).hide();
			}});
		} else {
			$(this).css("height",0).hide();
		}
	};
	
	function showContent(anim) {
		var content = $(this);
		var height = content.data("showHide_contentHeight");
		var anim = (anim == undefined) ? true : anim;
		
		content.stop();
		if (content.css("display") == "none") {
			content.show();
		}
		if (anim) {
			content.animate({height:height+'px'}, {queue:false, duration:800, easing:"easeInOutExpo", complete:function(){
				$(this).css("height","");
			}});
		} else {
			$(this).css("height","");
		}
	};
	
	$.fn.showHide = function() {
		return this.each(function() {
			var elem = $(this),
				header = $(".accordion-header", elem),
				content = $(".accordion-content", elem),
				wrapper = elem.closest(".accordionWrapper");
				
			content.data("showHide_contentHeight", content.height());	
			
			if (elem.parent().is(".accordionSH")) {

				header.unbind(".showHide")
					.bind("click", function(event){
						if ($(this).is(".ui-state-active")) {
							$(this).removeClass("ui-state-active");
							elem.removeClass("accordion-selected");
							hideContent.call(content);
						} else {
							$(this).addClass("ui-state-active");
							elem.addClass("accordion-selected");
							showContent.call(content);
						}
						
						if ($(".accordion>li", wrapper).length > 0 && ($(".accordion>li", wrapper).length == $(".accordion>li.accordion-selected", wrapper).length)) {
							$(".accordionAction_expand", wrapper).hide();
							$(".accordionAction_collapse", wrapper).show();
						} else if ($(".accordion>li.accordion-selected", wrapper).length == 0) {
							$(".accordionAction_expand", wrapper).show();
							$(".accordionAction_collapse", wrapper).hide();
						}
						
						this.blur();
						return false;
					});
			}
				
			elem.unbind(".showHide")
				.bind({
					"expand.showHide": function(){
						if (!$(header).is(".ui-state-active")) {
							$(header).addClass("ui-state-active");
							showContent.call(content);
						}
					},
					"collapse.showHide": function(){
						if ($(header).is(".ui-state-active")) {
							$(header).removeClass("ui-state-active");
							hideContent.call(content);
						}
					}
				});
				
			if (elem.is(".accordion-selected")) {
				showContent.call(content, false);
				header.addClass("ui-state-active");
			} else {
				hideContent.call(content, false);
			}
		});
	}
})(jQuery);

(function($){
	$(function() {
		if (jQuery.browser.safari) {
			jQuery("body").addClass("safari");	
		} else if (jQuery.browser.msie && jQuery.browser.version >= 8) {
			jQuery("body").addClass("ie8");	
		} else if (jQuery.browser.opera) {
			jQuery("body").addClass("opera");	
		}
		
		var isMac = (navigator.platform && navigator.platform.toLowerCase().indexOf("mac") >= 0);
		if (isMac && !jQuery.browser.safari) {
			jQuery("body").addClass("mac");
			if (jQuery.browser.mozilla && parseFloat(jQuery.browser.version) >= 1.9) {
				jQuery("body").addClass("mac_moz3");
			} else if (/mozilla/.test(navigator.userAgent.toLowerCase()) && parseFloat(jQuery.browser.version) >= 1.8) {
				jQuery("body").addClass("mac_moz2");
			}
		}
		
		if ($.browser.msie && $.browser.version < 7) {
			/*
			$("img[src$=png]").pngfix({
				//imageFixSrc: "http://127.0.0.1/c21/www/images/x.gif"
				imageFixSrc: baseurl + "images/x.gif"
			});
			*/
		}
		//gradient
		
		Cufon('.mainSolution .mainSlides .slideContent h2', {
			fontFamily: 'GothamBook',
			hover: true,
			hoverables: { li: true, a:true }
		});
		
		Cufon('.NAV>.dmn>ul>li>a>span', {
			fontFamily: 'GothamBold',
			hover: true,
			hoverables: { li: true, a:true }
		});
		
		
		Cufon('.mainSolution .mainSlides .slideContent h3', {
			fontFamily: 'GothamBold',
			hover: true,
			hoverables: { li: true, a:true }
		});
		
		Cufon('a.btn31', {
			fontFamily: 'GothamBold',
			hover: true,
			hoverables: { li: true, a:true }
		});
		
		Cufon('.pageHead h4', {
			fontFamily: 'GothamBook'
		});
		 
		$('.rndBox').each(function(item){
			var m = "<span class='btl'></span><span class='btr'></span><span class='bbl'></span><span class='bbr'></span>";
			$(this).append(m);
		});
		
		$('.accordion-header').each(function(item){
			var m = "<span class='btl'></span><span class='btr'></span>";
			$(this).append(m);
		});
		
		if ($(".threeCols .column").length > 0) {
			$('.threeCols .column:last').addClass("lastcolumn");
			$(".threeCols .column").equalHeights();
		}
		
		if ($(".menuAccordion").length > 0) {
			$('.menuAccordion').each(function(){
				//find items that have no submenu and treat them as link
				$(">li", this).each(function(){
					//if ($(">ul", this).length < 1) {
						//to exclude them in ui-accordion plugin
						$(this).addClass("accordion-exclude");
						//emulate skin
						$(this).addClass("ui-accordion-li-fix");
						$(">a",this).addClass("ui-accordion-header ui-helper-reset ui-state-default").prepend('<span class="ui-icon ui-icon-triangle-1-e"></span>');
						
					//}
				});
				
				/*
				var cur = $(">li:not(.accordion-exclude)>a.ui-state-active", this), idx = false;
				if (cur.length > 0) {
					idx = $(">li:not(.accordion-exclude)>a", this).index(cur);
				}
				
				
				$(this).accordion({ 
					autoheight: false,
					active: idx,
					header: '> li:not(.accordion-exclude) > :first-child,> :not(li):even'
				});
				*/
				
				
			});
		}
		
		if ($(".accordion").length > 0) {
			/*
			$(".accordion").accordion({
				header: ".accordion-header",
				autoHeight:false
			});
			*/
			
			$(".accordion").addClass("ui-accordion ui-widget ui-helper-reset ui-accordion-icons");
			$(".accordion>li").each(function(){
				
				$('<span class="ui-icon ui-icon-triangle-1-s"></span>').insertAfter($(".accordion-header>a", this));
			});
			
			$(".accordion>li").showHide();
			
			$(".accordionWrapper").each(function() {
				var wrapper = $(this);
				$(".accordionAction_expand", wrapper).click(function(event){
					$(".accordion>li", wrapper).trigger("expand.showHide");
					this.blur();
					event.preventDefault();
					$(".accordionAction_collapse", wrapper).show();
					$(this).hide();
					return false;
				});
				$(".accordionAction_collapse", wrapper).click(function(event){
					$(".accordion>li", wrapper).trigger("collapse.showHide");
					
					this.blur();
					event.preventDefault();
					$(".accordionAction_expand", wrapper).show();
					$(this).hide();
					return false;
				}).hide();
				
				if ($(".accordion>li", this).length > 0 && ($(".accordion>li", this).length == $(".accordion>li.accordion-selected", this).length)) {
					$(".accordionAction_expand", wrapper).hide();
					$(".accordionAction_collapse", wrapper).show();
				}
				
			});
		}
		
		if ($("body>.twoCols_2 .twoCols_2 .column").length > 0) {
			$("body>.twoCols_2 .twoCols_2 .column").equalHeights();
		}
		
		
		Cufon.now();
	});
})(jQuery);;

/** COUNTRY MENU **/
(function($){
	$(function() {
		/*
		$('.H_Nav>ul>li').each(function(i,item){
			var mover = false;
			var hideTimeout = 0;
			var elem = this;
			
			var clearHideTimeout = function(){
				if ( hideTimeout > 0 ){
					window.clearTimeout(hideTimeout);
				}
				hideTimeout = 0;
			}
			var setHideTimeout = function() {
				clearHideTimeout();
				hideTimeout = window.setTimeout(function(){
					$(elem).removeClass("hover");
				},300);
			};
			
			$(item).bind('mouseover', function(event){
				if (!mover) {
					clearHideTimeout();
					$('.H_Nav>ul>li').removeClass("hover");
					$(this).addClass('hover');
					mover = true;
				}
			});
			$(item).bind('mouseout', function(event){
				if (mover) {
					setHideTimeout();
				}
				mover = false;
			});
			
			var links = $('a', item);
			if (links.length) {
				links = links[0];
				$(links).bind('focus', function(event){
					$(item).addClass('hover');
				});
			}
		});
		// END COUNTRY MENU
		*/
	});
})(jQuery);

(function($){
	var all_menu = [];
	
	function _subnav(elem, submenuSelector) {
		var elem = $(elem);
		
		var	parent = elem.parent(),
			a = $(">a", elem);
			width = elem.outerWidth(),
			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() {
					clearHideTimeout();
					$(all_menu).not(elem).trigger("hidemenu.NAV");
					//siblings.trigger("hidemenu.NAV");
					elem.addClass("active");
					if (SUBMENU.length > 0) {
						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.hide().appendTo( $("body") );
			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 {
				SUBMENU.css({
					width:width+"px",
					left: (offset.left+1) + "px",
					top: (offset.top + height) + "px",
					visibility:"visible"
				});
			}
			
			$(window).bind("resize", function(){
				offset = elem.offset();
				SUBMENU.css({
					left: offset.left
				});
			});
		}
		
		all_menu.push(elem[0]);
	};
	
	$(function(){
		$("#menu-item-230>ul").addClass("SUBNAV_data");
		$("#menu-item-231>ul").addClass("SUBNAV_data");
		$(".NAV>.dmn>ul>li").each(function(){
			var ul = $(">ul:eq(0)", this);
			if (ul.length > 0) {
				ul.addClass("cf").wrap( $("<div />").addClass("SUBNAV"));
				if ( $("ul", ul).length > 0 ) {
					ul.parent().addClass("SUBNAV_custom SUBNAV_Software");
					
					$("ul", ul).each(function(){
						$("a:first", $(this).parent()).addClass("menu-item-header");
					});
				}
			}
		});
		
		$('.H_Nav>ul>li').each(function(){
			var ul = $(">ul:eq(0)", this);
			if (ul.length > 0) {
				$(this).addClass("loc");
				ul.wrap( $("<div />").addClass("loc_holder"));
				new _subnav(this, ".loc_holder");
			}
		});
		
		$(".NAV>.dmn>ul>li").each(function(){
			new _subnav(this, ".SUBNAV");
		});
		
		 
		
		all_menu = $.unique(all_menu);
	});
})(jQuery);

 (function($){
	var AUTO_TIMEOUT = 8000;
	var AUTO_TIMEOUT_AFTER_INTERACTION = 12000;
	var isIE = $.browser.msie;
	$(function(){
		$(".mainSlides").each(function(){
			var elem = $(this),
				slides = $(".slides>li", this),
				buttons = $(".slideButtons a[href]", this),
				curSlide = undefined,
				autoTimeout = 0;
				
			var showSlide = function(idx, anim, nextTimeout) {
				anim = (anim == undefined) ? true : anim;
				nextTimeout = (nextTimeout == undefined) ? 0 : nextTimeout;
				
				if (!anim) {
					$(slides[idx]).stop().css({
						opacity:"",
						display:"block"
					});
					
					curSlide = idx;
					buttons.removeClass("current");
					buttons.filter("[href=#" + $(slides[idx]).attr("id") + "]").addClass("current");
					
					if (nextTimeout) {
						setAutoTimeout(nextTimeout, AUTO_TIMEOUT);
					}
					return;
				}
				
				var toHide = undefined, toShow = undefined;
				
				if (idx == curSlide) return true;
				
				buttons.removeClass("current");
				if (curSlide != undefined && slides[curSlide]) {
					toHide = slides[curSlide];
				}
				
				if (slides[idx]) {
					toShow = slides[idx];
					buttons.filter("[href=#" + $(slides[idx]).attr("id") + "]").addClass("current");
				}
				
				if (toHide != undefined) {
					$(toHide).stop();
					$(toHide).animate({opacity:0}, {queue:false, duration:800, complete:function(){
						$(this).css({
							display:"none",
							opacity:""
						});
					}});
					
				}
				
				if (toShow != undefined) {
					$(toShow).stop();
					
					if ($(toShow).css("opacity") == "" || $(toShow).css("opacity") >= 1) {
						$(toShow).css({
							opacity:0
						});
					}
					if ($(toShow).css("display") == "none") {
						$(toShow).css({
							display:"block"
						});
					}
					
					$(toShow).animate({opacity:1}, {queue:false, duration:1200, complete:function(){
						$(this).css({
							display:"block",
							opacity:""
						});
					}});
					
					if (isIE) {						
						if ($(toShow).css("opacity") == "" || $(toShow).css("opacity") >= 1) {
							$(toShow).css({
								opacity:0
							});
						}
						if ($(toShow).css("display") == "none") {
							$(toShow).css({
								display:"block"
							});
						}
						
						$(toShow).animate({opacity:1}, {queue:false, duration:1200, complete:function(){
							$(this).css({
								display:"block",
								opacity:""
							});
						}});
					}
				}
				
				curSlide = idx;
				
				if (nextTimeout) {
					setAutoTimeout(nextTimeout, AUTO_TIMEOUT);
				}
			};
				
			var clearAutoTimeout = function() { 
				if (autoTimeout > 0) { 
					window.clearTimeout(autoTimeout); 
					autoTimeout = 0;
				}
			};
			
			var setAutoTimeout = function(timeout, nextTimeout) {
				clearAutoTimeout();
				autoTimeout = window.setTimeout(function(){
					if (curSlide >= slides.length-1) {
						showSlide(0, true, nextTimeout);
					} else {
						showSlide(curSlide+1, true, nextTimeout);
					}
				}, timeout);
			};
			
			buttons.bind("click", function(){
				var href = $(this).attr("href").replace("#","") || "";
				if (href != "") {
					if ($("#" + href).length > 0) {
						for (var i = 0; i < slides.length; i++) {
							if (i != curSlide && $(slides[i]).attr("id") == href) {
								clearAutoTimeout();
								showSlide(i, true, AUTO_TIMEOUT_AFTER_INTERACTION);
								break;
							}
						}
					}
				}
				
				this.blur();
				return false;
			});
			
			$(".slideButtons a.next", this).bind("click", function() {
				if (curSlide >= slides.length-1) {
					showSlide(0, true, AUTO_TIMEOUT_AFTER_INTERACTION);
				} else {
					showSlide(curSlide+1, true, AUTO_TIMEOUT_AFTER_INTERACTION);
				}
				this.blur();
				return false;
			});
			
			$(".slideButtons a.prev", this).bind("click", function() {
				if (curSlide <= 0) {
					showSlide(slides.length-1, true, AUTO_TIMEOUT_AFTER_INTERACTION);
				} else {
					showSlide(curSlide-1, true, AUTO_TIMEOUT_AFTER_INTERACTION);
				}
				this.blur();
				return false;
			});
			
			$(".slideButtons", this).show();
			showSlide(0, false, AUTO_TIMEOUT);
		});
	});
})(jQuery);

(function($){
	$(function(){
		$(".contentSlider").each(function(){
			var slider = $(this),
				slidesClipper = $(".contentSlider-slides", slider),
				slidesHolder = $(">ul", slidesClipper),
				slides = $(">li", slidesHolder),
				slidesMaxHeight = 0,
				slideWidth = 0,
				btnNext = $(".buttons .next", slider),
				btnPrev = $(".buttons .prev", slider),
				curSlide = 0;
				
			var AUTO_TIMEOUT = 8000;
			var AUTO_TIMEOUT_AFTER_INTERACTION = 12000;
			var autoTimeout = 0,
				autoStart = true;
				
			var goPrev = function(nextTimeout) {
				var l;
				
				clearTimeout();
				
				slidesHolder.stop();
				l = parseInt(slidesHolder.css("left")) || 0;
				if (curSlide < 1) {
					$(slides[slides.length-1]).hide().insertBefore( slides[0]);
					$(slides[slides.length-1]).show();
					slides = $(">li", slidesHolder);
					slidesHolder.css({
						left: (l-slideWidth) + "px"
					});
					curSlide = 0;
				} else {
					curSlide --;
				}
				
				slidesHolder.animate({left:-(slideWidth*curSlide)+"px"}, {queue:false, duration:900, easing:"easeInOutExpo"});
				
				setAutoTimeout(nextTimeout, AUTO_TIMEOUT);
			};
			
			var goNext = function(nextTimeout) {
				var l;
				
				clearTimeout();
				
				slidesHolder.stop();
				l = parseInt(slidesHolder.css("left")) || 0;
				if (curSlide >= slides.length-1) {
					$(slides[0]).hide().insertAfter(slides[slides.length-1]);
					$(slides[0]).show();
					slides = $(">li", slidesHolder);
					slidesHolder.css({
						left: (l+slideWidth) + "px"
					});
					
					curSlide = slides.length-1;
				} else {
					curSlide++;
				}
				
				slidesHolder.animate({left:-(slideWidth*curSlide)+"px"}, {queue:false, duration:900, easing:"easeInOutExpo"});
				
				setAutoTimeout(nextTimeout, AUTO_TIMEOUT);
			};
			
			var clearAutoTimeout = function() {
				if (autoTimeout > 0) {
					window.clearTimeout(autoTimeout);
					autoTimeout = 0;
				}
			};
			
			var setAutoTimeout = function(timeout, nextTimeout) {
				clearAutoTimeout();
				autoTimeout = window.setTimeout(function(){
					goNext(nextTimeout);
				}, timeout);
			};
				
			slides.each(function(){
				var h = $(this).outerHeight(true);
				if (h > slidesMaxHeight) {
					slidesMaxHeight = h;
				}
			});
			
			slides.each(function(){
				$(this).css({
					height: (slidesMaxHeight - ($(this).innerHeight() - $(this).height())) + "px"
				});
			});
			
			slideWidth = $(slides[0]).outerWidth(true);
			
			slidesHolder.css({
				height: (slidesMaxHeight) + "px",
				width: (slideWidth * slides.length) + "px"
			});
			
			slidesClipper.css({
				height: (slidesMaxHeight) + "px"
			});
			
			btnPrev.bind("click", function(){
				goPrev(AUTO_TIMEOUT_AFTER_INTERACTION);
				this.blur();
				return false;
			});
			
			btnNext.bind("click", function(){
				goNext(AUTO_TIMEOUT_AFTER_INTERACTION);
				this.blur();
				return false;
			});
			
			if (autoStart) {
				setAutoTimeout(AUTO_TIMEOUT);
			}
		});
		
		
	});
})(jQuery);

(function($){
	$(function(){
		$("#submitlink").click(function() {
			
			// validate form on keyup and submit
			$("#contact_form").validate({
				rules: {
					txt_first_name: "required",
					txt_last_name: "required",
					txt_email: {
						required: true,
						email: true
					},
					txt_phone_number: "required",
					txt_company_name: "required"
				},
				messages: {
					txt_first_name: "Please enter your first name",
					txt_last_name: "Please enter your last name",
					txt_email: "Please enter a valid email",
					txt_phone_number: "Please enter your phone",
					txt_company_name: "Please enter your company name"
				}
			});
		});
	});
})(jQuery);

(function($){
	$(function(){
		$('.contact_form .btn31').mouseenter(function() {
			$('.contact_form #submitlink').attr('src','images/submit_hover.png');
		});
		$('.contact_form .btn31').mouseleave(function() {
			$('.contact_form #submitlink').attr('src','images/submit.png');
		});
		
		$('.btn32').mouseenter(function() {
			$('#submitlink').attr('src','images/login_hover.png');
		});
		$('.btn32').mouseleave(function() {
			$('#submitlink').attr('src','images/login.png');
		});
	});
})(jQuery);

/******** global DOM ready actions ************/
(function($){
	$(function(){
		if ($.fn.dropdown !== undefined) {
			$(".customDropdown").dropdown();
		}
		
		$(".cf-ol>li:last").addClass("lastRow");
		
		$(".key_features>li:last").addClass("last");
		
		$(".randomBoxes").each(function(){
			var boxesCount = $(">.randomBox", this).length,
				idx = 0;
				
			idx = Math.floor(Math.random() * boxesCount);
			$($(">.randomBox", this)[idx]).show();
		});
		
		//auto Ellipsis
		if (jQuery.fn.autoEllipsis) {
			(function(){
				var lblMore = "More",
					lblClose = "Less";
				
				if ($(".label-More").length > 0 && $(".label-More:eq(0)").html() != "") {
					lblMore = $(".label-More:eq(0)").html();
				}
				if ($(".label-Close").length > 0 && $(".label-Close:eq(0)").html() != "") {
					lblClose = $(".label-Close:eq(0)").html();
				}
				
				jQuery(".autoEllipsis").ellipsis({
					more: lblMore,
					less: lblClose
				});
			})();
		};
		/*
		$(".frmCareerSearch").each(function() {
			var frm = $(this),
				optCity = $(".optCity", this),
				optDepartment = $(".optDepartment", this);
			
			$(this).bind("submit", function(){
				var city = optCity[0].value,
					department = optDepartment[0].value;
					
				if (city != "" && department != "") {
					window.location = city + "-" + department + ".html";
				}
				return false;
			});
			
			optCity.bind("change", function(){
				var iOpt = 0;
				
				if (this.value == "new_york" || this.value == "") {
					iOpt = $("option", optDepartment).index($("option[value='technology']", optDepartment));
					optDepartment.dropdown("showItem", iOpt);
				} else {
					if (optDepartment[0].value == "technology") {
						optDepartment.dropdown("setValue", "");
					}
					
					iOpt = $("option", optDepartment).index($("option[value='technology']", optDepartment));
					optDepartment.dropdown("hideItem", iOpt);
				}
			});
			
			optCity.triggerHandler("change");
		});
		*/
		
		$(".opt_contact_countries").bind("change", function(){
			var value = this.value;
			window.location = "interior_location_" + value + ".html";
		});
	});
})(jQuery);
