var aboutactive = false;
var navover = "";
var x = "";
var msgsent = false;
var srchmsg = false;
var hidepdf = true;
var feedbackClick = false;
var feedbackOpen = false;

function iecontact() { }

function navpophide() { if (contactselect != true) { $("#navpop").hide(); $("#navresults").hide(); } }

function menucontactshow(studioID) 
{
	pdfbutton = false;
	hidepdf = false;
	
	$('#globe').hide();
	$('#pdfmessage').hide();
	$('#tabsearch').hide();
	$('#pdfresults').hide();
	$("#navresults2").jScrollPaneRemove();
	$("#pdfbar").hide();
	$("#navresults3").hide();
	$("#popfoot").show();
	$('#moreGlobe').hide();
	$('#moreContact').show();
	$('#morePDF').hide();
	$('#moreSearch').hide();

	if (msgsent == true) {
		$("#navresults1").show();
		$('#searchoptions').hide();
		$('#msgthank').show();
	}
	else {
		$("#navresults1").show();
		$('#searchoptions').show();
		$('#msgthank').hide();
		msgsent = false;
	}
	
	var posa = $('#menucontactcell img').position();
	var posb = $('#ngrid').position();
	$("#poptitle").removeClass(navover);
	$("#poptitle").addClass('contact');
	$("#poptitle").css('left', '309px');
	$("#navpop").css('left', (posa.left-316)+'px');
	$("#navpop").css('top', (Math.floor(posb.top)+21)+'px');
	$("#navpop").show();
	navover = "contact";
	
	if (studioID != undefined) 
	{
		contactselect = true;
		studioclick = true;
		feedbackClick = true;
		//var text = $(this).html();
		if (feedbackOpen == false) 
		{
			$("#ddstudio dt a span").html($("#ddstudio li a:has(span#"+studioID+")").html());
			var x = $.ajax({
				type: "POST",
				url: "/cnavigation/contactbeta.aspx",
				cache: false,
				data: "sid=" + studioID,
				success: function(html) {
					$("#navresults1").hide().html(html).fadeIn();
					$("#flashblock").hide();
					feedbackOpen = true;
				}
			});
		}
	}
}

function msgsendagain() 
{
	msgsent = false;
	contactselect = false;
	$('#msgthank').hide();
	$("#navresults1").html('');
	$('#inforesult').show();
	$('#searchoptions').show();
}

var pdfbutton = false;

function menupdfshow() 
{
	pdfbutton = true;
	pdfshow();
	showPDF();
}

function pdfshow() 
{
	hidepdf = true;
	$('#globe').hide();
	$('#pdfmessage').hide();
	$("#navresults1").css({display:'none',visbility:'hidden'});
	$("#navresults1").hide();
	$("#pdfbar").hide();
	$("#navresults3").hide();
	$('#searchoptions').hide();
	$('#tabsearch').hide();
	$("#popfoot").hide();
	$('#moreGlobe').hide();
	$('#moreContact').hide();
	$('#morePDF').show();
	$('#moreSearch').hide();
	var posa = $('#menupdfcell img').position();
	var posb = $('#ngrid').position();
	$("#poptitle").removeClass(navover);
	$("#poptitle").addClass('pdf');
	$("#poptitle").css('left', '270px');
	$("#navpop").css('left', (posa.left-275)+'px');
	$("#navpop").css('top', (posb.top+21)+'px');
	$("#navpop").show();
	navover = "pdf";
}

function addPDF(cid) 
{
	$('#pdfresults').hide();
	$('#pdfbar').hide();
	pdfshow();
	var x = $.ajax({
	   type: "POST",
	   url: "/cnavigation/pdf_add.aspx",
	   data: "cid="+cid,
	   cache: false,
	   success: function(html){
		 $("#pdfmessage").hide().html(html).fadeIn().animate({ opacity:1 }, 3000).fadeOut(function(){ $("#pdfmessage").hide().html(""); if (hidepdf == true) { navpophide(); } });
	   }
	});
}

function deletePDF(cid) 
{
	var answer = confirm("Are you sure you want to remove the PDF from your custom build?")
	if (answer){
		removePDF(cid)
	}
}

function removePDF(cid)
{
	var cookieArr = new Array();
	cookieArr = $.cookie("PDFStudy").split(",");
	var pdfstring = "";
	var firstpdf = 0;
	for (var i=0; i < cookieArr.length; i++) 
	{
		if (cookieArr[i] != cid)
		{
			if (cookieArr[i] != "")
			{
				if (firstpdf == 0) { pdfstring = cookieArr[i]; }
				else { pdfstring += "," + cookieArr[i]; }
				firstpdf ++;
			}
		}
	}
	$.cookie("PDFStudy", pdfstring, { path: '/', expires: 1 });
	$("#pdfmessage").hide().html("<div class='pdfmsg'>PDF Deleted</div>").fadeIn().animate({ opacity:1 }, 3000).fadeOut();
	$('#navresults2').html('');
	showPDF();
	
	/*
	var x = $.ajax({
	   type: "POST",
	   url: "/cnavigation/pdf_delete.aspx",
	   data: "cid="+cid,
	   cache: false,
	   success: function(html){
		 $("#pdfmessage").hide().html(html).fadeIn().animate({ opacity:1 }, 3000).fadeOut();
		 $('#navresults2').html('');
		 showPDF();
	   }
	});
	*/
}

function showPDF() 
{
	if ($.cookie("PDFStudy") != null && $.cookie("PDFStudy").length > 0) 
	{
		$('#pdfbar').show();
		$('#pdfresults').hide();
		$('#pdfbar').addClass('pdfbarspin');
		var x = $.ajax({
		   type: "GET",
		   url: "/cnavigation/pdf.aspx",
		   cache: false,
		   success: function(html){
			  if (pdfbutton == true) {
				  if (html == "NO") 
				  {
					  $("#popfoot").hide();
					  $('#morePDF').hide();
					  $('#pdfbar').hide();
					  $('#pdfresults').show();
				  }
				  else
				  {
					  $('#pdfbar').removeClass('pdfbarspin');
					  $("#navresults2").hide().html(html).fadeIn('slow');
					  if (parseInt($("#navresults2").find("div.pdftitle span").html()) > 5) {
						  $("#navresults2").css({"height":"330px"});
					  	  $("#navresults2").jScrollPane({ showArrows: true, scrollbarWidth: 13, scrollbarTrackWidth: 8, scrollbarMargin: 0 });
					  } else {
						  $("#navresults2").css({"height":"auto"});
						  $("#navresults2").jScrollPane({ showArrows: true, scrollbarWidth: 13, scrollbarTrackWidth: 8, scrollbarMargin: 0 });
					  }
					  $("#popfoot").show();
					  $('#morePDF').show();
				  }
			  }
		   }
		});
	} 
	else 
	{
		$("#popfoot").hide();
		$('#morePDF').hide();
		$('#pdfbar').hide();
		$('#pdfresults').show();
		//$('#pdfresults').html("<h1>Custom PDF</h1><div class='pdftitle' style='margin-left:10px;'>Items (0)</div><div class='pdfitemna'><p>You currently have no saved items.</p><p>To add items to your Custom PDF while you browse, simply click the <span><strong>+Add To CUSTOM PDF</strong></span> buttons found on each case study page.</p><p>If you already know what case studies you would like to add to your Custom PDF, click the link below to build your Custom PDF now.</p></div>");
	}
}

function printPage() 
{
	$("#newsblock").jScrollPaneRemove();
	window.print();
}

function menusearchshow() 
{
	pdfbutton = false;
	hidepdf = false;
	if (srchmsg == true) {
		$("#navresults3").show();
		$("#popfoot").show();
		$('#moreSearch').show();
	} else {
		$("#navresults3").hide();
		$("#popfoot").hide();
		$('#moreSearch').hide();
	}
	$('#globe').hide();
	$('#pdfmessage').hide();
	$('#pdfresults').hide();
	$("#navresults1").hide();
	$("#navresults2").jScrollPaneRemove();
	$("#pdfbar").hide();
	$('#searchoptions').hide();
	$('#tabsearch').show();
	$('#moreGlobe').hide();
	$('#moreContact').hide();
	$('#morePDF').hide();
	var posa = $('#menusearchcell img').position();
	var posb = $('#ngrid').position();
	$("#poptitle").removeClass(navover);
	$("#poptitle").addClass('search');
	$("#poptitle").css('left', '191px');
	$("#navpop").css('left', (posa.left-194)+'px');
	$("#navpop").css('top', (posb.top+21)+'px');
	$("#navpop").show();
	navover = "search";
}

function searchsite()
{
	if ($('#searchsite').val().length > 0) 
	{
	$('#searchbutton').hide();
	$('#searchspinner').show();
	var x = $.ajax({
	   type: "POST",
	   url: "/cnavigation/search.aspx",
	   data: "search=" + $('#searchsite').val(),
	   cache: false,
	   success: function(html){
		 srchmsg = true;
		 $("#navresults3").hide().html(html).fadeIn();
		 $("#popfoot").show();
		 $('#moreSearch').show();
		 var searchtextArr = $('#searchsite').val().split(" ");
		 var searchText = "";
		 var searchcount = 0;
		 while (searchcount < searchtextArr.length)
		 {
			 if (searchcount == 0) 
			 { 
			 	searchText = searchtextArr[searchcount];
			 }
			 else
			 {
			 	searchText = searchText + "+" + searchtextArr[searchcount];
			 }
			 searchcount+=1;
		 }
		 $('#moreSearch').html("<a href='/search/?term="+searchText+"'>View all results</a>");
		 $('#searchspinner').hide();
		 $('#clearbutton').show();
	   }
	 });
	} else {
		$("#navresults3").hide().html("<div id='searchresults'><div class='searchtitleenter'>Please enter a search term</div>").fadeIn();
	}
}

function searchclear()
{
	srchmsg = false;
	$("#searchsite").val("Search terms...");
	$('#searchbutton').show();
	$('#clearbutton').hide();

	var x = $.ajax({
	   type: "GET",
	   url: "/cnavigation/search_delete.aspx",
	   cache: false,
	   success: function(html){
		 	$("#navresults3").fadeOut().empty().hide();
			$("#popfoot").hide();
			$('#moreSearch').show();
	   }
	 });
}

function menuglobeshow() 
{
	pdfbutton = false;
	hidepdf = false;
	$('#pdfmessage').hide();
	$('#pdfresults').hide();
	$("#navresults1").hide();
	$("#navresults2").jScrollPaneRemove();
	$("#navresults3").hide();
	$('#moreSearch').hide();
	$("#pdfbar").hide();
	$('#searchoptions').hide();
	$('#tabsearch').hide();
	$('#moreGlobe').show();
	$('#moreContact').hide();
	$('#morePDF').hide();
	$("#popfoot").show();
	$('#globe').show();
	var posa = $('#menusearchcell img').position();
	var posb = $('#ngrid').position();
	$("#poptitle").removeClass(navover);
	$("#poptitle").addClass('globe');
	$("#poptitle").css('left', '184px');
	$("#navpop").css('left', (posa.left-334)+'px');
	$("#navpop").css('top', (posb.top+21)+'px');
	$("#navpop").show();
	navover = "globe";
}