$(document).ready(function(){

	
	// secondary navigation last item bar
	$(".secondaryNav li:last, #footer .nav li:last").addClass('last');
	
	
	// Toggle Box 
	$(".toggle").toggle(
		function(){
			if ( $(this).hasClass('commentPlus')==false ) {
				$(this).next().slideUp(300);
				$(this).html("show <span>+</span>");
			}
		},
		function(){
			if ( $(this).hasClass('commentPlus')==false ) {
				$(this).next().slideDown(300);
				$(this).html("hide <span>-</span>");
			}
		}
	);
	
	$(".commentPlus").click(function() {
		window.location = $(this).attr('href');		
	});
	
	
	// Modal Popup
	positionModal = function(){
		 var wWidth = window.innerWidth;
		 var wHeight = window.innerHeight;
	
		 if (wWidth==undefined) {
			 wWidth = document.documentElement.clientWidth;
			 wHeight = document.documentElement.clientHeight;
		 }
	
		 var boxLeft = parseInt((wWidth / 2) - ( $("#modal").width() / 2 ));
		 var boxTop = parseInt((wHeight / 2) - ( $("#modal").height() / 2 ));
	
		 // position modal
		 $("#modal").css('margin', boxTop + 'px 0 0 ' + boxLeft + 'px');		
	}
	$(".modal").click(function(){
		if ($("#modalWrapper").length>0) {
			$("#modalWrapper").show();
			$("#modalBackground").show();
		} else {
			$("body").append('<div id="modalBackground"></div>');
			$("#modalBackground").css("opacity", 0).fadeTo("slow", "0.8");
			$("body").append('<div id="modalWrapper"></div>');
			$("#modalWrapper").append('<div id="modal"><div class="bodyWrap"><div class="bodyWrapVer"><div class="bodyWrapHor"><div class="bodyContent"></div></div></div></div></div>');
		}
		
		positionModal();
		if ( $(this).hasClass('pressRelease') ) {
			$("#modal .bodyContent").html('<ul class="pressReleaseList">'+$(this).prev().html()+'</ul>');	
			$("#modal .bodyContent").append('<a href="#" class="closeModal"><span class="hide">close<span></a>');
			$("#modal .pressReleaseList").before('<div id="modalPressRelease" />');
			$("#modalPressRelease").html($("#pressReleaseTitle").html());
			$("li#pressReleaseTitle").hide();
		} else {
			$("#modal .bodyContent").html( $(this).prev().html() );	
			$("#modal .bodyContent").append('<a href="#" class="closeModal"><span class="hide">close<span></a>');
			$("#modal .bodyContent").prepend('<div class="logo"><span class="hide">ThreadStone Consulting Group LLC</span></div>');
		}
		$("#modalBackground, #modalWrapper").bgiframe();				   
		return false;						   
	});
	$(".closeModal").live('click', function(){
		 $("#modalWrapper").hide();
		 $("#modalBackground").hide();		
		return false;										
	});
	$(".printModal").live('click', function(){
		window.print();
		return false;										
	});
	
	
	// comment carousel
	$('.movePrev').click(function(){
		var $ul = $(this).parent().prev();
		var li_w = $ul.children().eq(0).width();
		var index = $ul.children('li.active').index();
		$ul.children().removeClass('active');
		if (index==0) {
			index = $ul.children('li:last').index();
		} else {
			index--;
		}
		
		$ul.animate({
			marginLeft: -li_w*index
		},300);
		
		$ul.children().eq(index).addClass('active');
		return false;
	});

	$('.moveNext').click(function(){
		var $ul = $(this).parent().prev();
		var li_w = $ul.children().eq(0).width();
		var index = $ul.children('li.active').index();
		$ul.children().removeClass('active');
		if (index==$ul.children('li:last').index()) {
			index = 0;
		} else {
			index++;
		}
		
		$ul.animate({
			marginLeft: -li_w*index
		},300);
		
		$ul.children().eq(index).addClass('active');
		return false;
	});

	
	// main top background position adjustment
	windowResize = function(){
		var offsetLeft = parseInt($(".mainTop .wrap").offset().left) - 135;
		$(".mainTop .wrapper").css('background-position', offsetLeft+'px 0');
	}
	windowResize();
	$(window).resize(function() {
		windowResize();
	});	
	
	
	
	/* Tooltip */
	if ($(".tooltipBox").length>0) {
		$(".tooltipBox").css({
			'box-shadow': '5px 5px 5px #ccc',
			'-moz-box-shadow': '5px 5px 5px #ccc',
			'-webkit-box-shadow': '5px 5px 5px #ccc'					  
		});
	}
	$(".tooltip").hover(
		function(){
			$(this).next().show();	
		},
		function(){
			$(this).next().hide();	
		}
	);
	
	
	/* Contact Form */
	if ( $(".wpcf7-form").length>0 ) {
		$(".wpcf7-form p br").remove();
	}
	$("#contactForm p:last").addClass('last');
	$("#contactForm p:last input").val('submit');
	
	
	
});