//var $=jQuery.noConflict();

$(document).ready(function() {
	var originalSizes = new Array();
	$('.gallery').jScrollHorizontalPane({scrollbarHeight:10, scrollbarMargin:0});
});

$(document).ready(function() {
	$.featureList(
		$("#tabs li a"),
		$("#output li"), {
			start_item	:	0
			//transition_interval : 0 //comment this out to auto rotate
		}
	);
	
	if ($(".rotate_1>ul>li").length > 0) {
		$(".rotate_1>ul>li").equalHeights();
	}
	if ($(".rotate_1").length > 0) {
		$(".rotate_1").jCarouselLite({
			btnNext: ".next1",
			btnPrev: ".prev1",
			visible: 1,
			circular: true
		});
	}
	if ($(".rotate_client>ul>li").length > 0) {
		$(".rotate_client>ul>li").equalHeights();
	}
	
	if ($(".rotate_client").length > 0) {
		$(".rotate_client").jCarouselLite({
			btnNext: ".next_client",
			btnPrev: ".prev_client",
			visible: 1,
			auto: 5000,
			circular: true
		});
	}
	
	if ($(".rotate_2>ul>li").length > 0) {
		$(".rotate_2>ul>li").equalHeights();
	}
	
	if ($(".rotate_2").length > 0) {
		$(".rotate_2").jCarouselLite({
			btnNext: ".next2",
			btnPrev: ".prev2",
			visible: 1,
			circular: true
		});
	}
	
	$(".rotate_3>ul>li").equalHeights();
		if ($(".rotate_3").length > 0) {
		$(".rotate_3").jCarouselLite({
			btnNext: ".next3",
			btnPrev: ".prev3",
			visible: 1,
			circular: true
		});
	}
	
	if ($(".rotate_4>ul>li").length > 0) {
		$(".rotate_4>ul>li").equalHeights();
	}

	$(".newsTicker").jCarouselLite({
		btnNext: ".next3",
		btnPrev: ".prev3",
		visible: 1,
		circular: true
	});

	if ($(".rotate_4").length > 0) {
		$(".rotate_4").jCarouselLite({
			btnNext: ".next4",
			btnPrev: ".prev4",
			visible: 1,
			circular: true
		});
	}
	
	if ($(".rotate_news>ul>li").length > 0) {
		$(".rotate_news>ul>li").equalHeights();
	}
	if ($(".newsTicker").length > 0) {
		$(".newsTicker").jCarouselLite({
			btnNext: ".next3",
			btnPrev: ".prev3",
			visible: 1,
			circular: true
		});
	}
	
	if ($(".text-wrapper").length > 0) {
		$(".text-wrapper").truncate( 350, {
			chars: /\s/,
			trail: ["...<a href='#' class='truncate_show'>More</a>", "<a href='#' class='truncate_hide'>Less</a>"]
		});
	}
	
	if ($("#accordion").length > 0) {
		$("#accordion").accordion({collapsible: true});
	}
	
	
	if ($("#tabs2").length > 0) { $("#tabs2").tabs(); } 
	if ($("#clients_tabs").length > 0) { $("#clients_tabs").tabs();  } 
	if ($("#contacts_tabs").length > 0) { $("#contacts_tabs").tabs(); } 
	if ($(".product_tabs").length > 0) { $(".product_tabs").tabs(); } 
	if ($(".product_tabs2").length > 0) { $(".product_tabs2").tabs(); } 
	
	if ($(".see-more-fold a").length > 0) {
	
		$(".see-more-fold a").each(function() {
			var elem = this,
				href = $(this).attr("href").replace("#", "") || "",
				target,
				tab, tabIndex, tabsNav;
				
			if (href != "") {
				if ( $("#" + href).length > 0 ) {
					tab = $(".ui-tabs-nav a[href='#" + href + "']");
					if ( tab.length > 0) {
						tabsNav = tab.parents(".ui-tabs-nav:eq(0)");
						tabIndex = $("a", tabsNav).index(tab);
						$(elem).bind("click", function(event) {
							tabsNav.parent().tabs("select", tabIndex);
							return false;
						});
					}
				}
			}
		});
	}
	
	
	$('#navcontainer>ul>li>ul').css({
		display:"none"
	});
	var nav_initial_hover = $('#navcontainer>ul>li.hover');
	var current_hover = null;
	
	$('#navcontainer>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(){
				if ( current_hover == null && nav_initial_hover.length > 0 && nav_initial_hover[0] == elem ) {
				} else {
					$(">ul",elem).hide();
					$(elem).removeClass("hover");
					
				}
				if ( current_hover == null && nav_initial_hover.length > 0 ) {
					$(">ul",nav_initial_hover).show();
					$(nav_initial_hover).addClass("hover");
				}
				
			},400);
		};
		
		$(item).bind('mouseover', function(event){
			if (!mover) {
				clearHideTimeout();
				$('#navcontainer>ul>li.hover>ul').hide();
				$('#navcontainer>ul>li').removeClass("hover");
				
				$(">ul",this).show();
				$(this).addClass('hover');
				
				
				mover = true;
				current_hover = elem;
			}
		});
		$(item).bind('mouseout', function(event){
			if (mover) {
				setHideTimeout();
			}
			mover = false;
			current_hover = null;
		});
		
		if ($.browser.msie && $.browser.version < 8 &&  $(">ul",elem).length) {
			var w = $(">ul",elem).outerWidth();
			$(">ul",elem).show();
			if (w < $(elem).outerWidth()) {
				$(">ul",elem).css("width",$(elem).outerWidth());
				w = $(elem).outerWidth(true);
			}
			var pl,pr;
			$(">ul a", elem).each(function(){
				pl = parseInt($(this).css("paddingLeft")) || 0;
				pr = parseInt($(this).css("paddingRight")) || 0;
				$(this).css({width:(w-pl-pr)+'px'});
			});
			$(">ul",elem).hide();
		}
		
		
		var links = $('a', item);
		if (links.length) {
			links = links[0];
			$(links).bind('focus', function(event){
				$(item).addClass('hover');
			});
		}
	});
	if (nav_initial_hover.length > 0) {
		nav_initial_hover.addClass("initial_hover");
		$(">ul",nav_initial_hover).show();
	}
	
	
	
	if ($(".columns").length > 0) {
		$(".columns").equalHeights();
	}
	if ($(".inner_column").length > 0) {
		$(".inner_column").equalHeights();
	}
	
	if ($("#industry").length > 0) {
		$('#industry').sSelect();
	}
	if ($("select#industry").length > 0 && $(".roi-calculations").length > 0) {
		$("select#industry").bind("change", function() {
			var value = this.value;
			var targetID = $("#roi_" + value);
			if (targetID.length > 0) {
				$(".roi-calculations").hide();
				targetID.show();
			}
		});
		
		$("select#industry").change();
	}
});



$(document).ready(function() {
	//$("a[rel='gallery']").colorbox();
	$("a[rel='gallery']").fancybox();
	if ($(".gallery").length > 0) {
		$(".gallery a").fancybox();
	}
	if ($(".share").length > 0) {
		$(".share").fancybox({
			'modal':true
		});
	}
});
	 
