var fileSizeLimit = 6 * 1048576; //default file size for documents

currentpropDescBox = ""

function propDescBox(linkID) {	
	if (currentpropDescBox != "#content_" + linkID) {
		currentpropDescBox = "#content_" + linkID;
		jQuery(".tab_content").each(function (i) {
			jQuery(this).hide(0);
		});
		
		jQuery(".logos_imgs").each(function (i) {
			jQuery(this).css({opacity:1});
		});
		
		jQuery("#link_" + linkID).css({opacity:0.2});

		
		jQuery("#content_" + linkID).show(0);
	}
}


$(document).ready(function(){	
						   
	  
	if ($("#scrollText").height() < 227) {	
		$(".upArrow1").hide(0);
		$(".downArrow1").hide(0);
	}
						   
		$('.case1:last').css("padding", "13px 17px 10px 0px");
		$('.case1:first').css("padding-left", "20px");
		
		
		$('.case1').each(function(index) {
			if($(this).height() < 94) {
			   	$(this).height(94);
			  }
		});
						   
		function mainmenu(){
			$("#super_nav ul ").css({display: "none"});
			$("#super_nav li").hover(function(){	
				$(this).find('ul:first').css({visibility: "visible", display: "none"}).slideDown();
				$(this).find('ul li a').css({opacity:1});
			},function(){
				$(this).find('ul:first').css({visibility: "hidden", display: "none"});
				$(this).find('ul li').css({opacity:1});
			});
		
		}
		
		mainmenu();
	
	$('.res_desc').each(function(index) {
			$(this).find('p:first').css("margin-top", "0px");
			$(this).find('p:last').css("margin-bottom", "0px");
			
			if($(this).height() < $(".res_title:eq("+index+")").height()) {
				$(this).height($(".res_title:eq("+index+")").height());
			}		
			
		});
	
	$('.res_desc_cst').each(function(index) {
			$(this).find('p:first').css("margin-top", "0px");
			$(this).find('p:last').css("margin-bottom", "0px");		
			
			
			if($(this).height() < $(".res_college:eq("+index+")").height()) {
				$(this).height($(".res_college:eq("+index+")").height());
			}
			
			if($(this).height() < $(".res_title_short:eq("+index+")").height()) {
				$(this).height($(".res_title_short:eq("+index+")").height());
			}
			
			if($(this).height() < $(".res_company:eq("+index+")").height()) {
				$(this).height($(".res_company:eq("+index+")").height());
			}
			
		});
	

	
	$('.res_title').each(function(index) {
			if($(this).height() < $(".res_desc:eq("+index+")").height()) {
				$(this).height($(".res_desc:eq("+index+")").height());
			}
		});
	
	$('.res_desc_links').each(function(index) {
			$(this).find('p:first').css("margin-top", "0px");
			$(this).find('p:last').css("margin-bottom", "0px");
			
			if($(this).height() < $(".res_title_long:eq("+index+")").height()) {
				$(this).height($(".res_title_long:eq("+index+")").height());
			}
		});
	
	$('.res_title_long').each(function(index) {
			if($(this).height() < $(".res_desc_links:eq("+index+")").height()) {
				$(this).height($(".res_desc_links:eq("+index+")").height());
			}
		});
	
	$('.res_title_long').each(function(index) {
			if($(this).height() < $(".res_report_type:eq("+index+")").height()) {
				$(this).height($(".res_report_type:eq("+index+")").height());
			}
		});
	
	$('.res_title_short').each(function(index) {
			if($(this).height() < $(".res_desc_cst:eq("+index+")").height()) {
				$(this).height($(".res_desc_cst:eq("+index+")").height());
			}
		});
	
	$('.res_college').each(function(index) {
			if($(this).height() < $(".res_desc_cst:eq("+index+")").height()) {
				$(this).height($(".res_desc_cst:eq("+index+")").height());
			}
		});
	
	$('.res_month_news').each(function(index) {
			if($(this).height() < $(".res_title_news:eq("+index+")").height()) {
				$(this).height($(".res_title_news:eq("+index+")").height());
			}
		});
	
	
	$('.res_report_type').each(function(index) {
			if($(this).height() < $(".res_title_long:eq("+index+")").height()) {
				$(this).height($(".res_title_long:eq("+index+")").height());
			}
		});
	
	$('.res_month').each(function(index) {
			if($(this).height() < $(".res_title_long:eq("+index+")").height()) {
				$(this).height($(".res_title_long:eq("+index+")").height());
			}
		});
	
	$('.res_month').each(function(index) {
			if($(this).height() < $(".res_report_type:eq("+index+")").height()) {
				$(this).height($(".res_report_type:eq("+index+")").height());
			}
		});
	
	$("#members_tbl tr:odd").css("background-color", "#f2f2f2");
	$("#members_tbl tr:even").css("background-color", "#d3d3d3");
	$("#members_tbl tr:last td").css("border-bottom", "none");
	
	
	if ($("#vid_file_j")) {
		$("#vid_file_j").uploadify({
			'uploader'		:	'assets/scripts/uploadify.swf',
			'script'        :	'assets/scripts/uploadify.php',
			'cancelImg'     :	'assets/images/cancel.png',
			'folder'        :	'resources', // Where to save the file
			'auto'			:	true,
			'multi'         :	false, // Allow multiple file uploads? No
			'sizeLimit'		:	fileSizeLimit,
			'queueSizeLimit':	1,
			'simUploadLimit':	1,
			'buttonText'	:	'SELECT A FILE', // Text for the button
			onCheck			:	function (event, checkScript, fileQueue, folder, single) {
				alert("FILE ALREADY EXISTS"); // THIS DOESN'T APPEAR TO WORK
				return false;
			},
			onComplete		:	function (event, queueID, fileObj, response, data) {
				$('#filename').val(response); // Assign the uploaded filename to the relevant hidden field
				$('#filesize').val(fileObj.size);
				$('#type').attr("disabled", false);
				$('#file_info').html(response);
				$('#uploaded_file').html("UPLOADED FILE");
				$('#vid_file_jUploader').hide(0);				
			},
			onSelect	:	function (event, queueID, fileObj, response, data) {
				$('#type').attr("disabled", true);

				$('.uploadifyQueueItem').each(function(index) {
						$(this).hide(0);								   
					});
				$('#error').html("");	
				
				if ($('#type').val() == "") {							
					$('#vid_file_j').uploadifyClearQueue();				
					$('#error').html("Please select the File Type and then select a File.");
					$('#type').attr("disabled", false);
				}
			},
			onCancel	:	function (event, queueID, fileObj, response, data) {
				$('#type').attr("disabled", false);
			}
		});
	}
	
	if ($("#report_file")) {
		$("#report_file").uploadify({
			'uploader'		:	'assets/scripts/uploadify.swf',
			'script'        :	'assets/scripts/uploadify.php',
			'cancelImg'     :	'assets/images/cancel.png',
			'folder'        :	'reports', // Where to save the file
			'auto'			:	true,
			'multi'         :	false, // Allow multiple file uploads? No
			'sizeLimit'		:	fileSizeLimit,
			'fileExt'		:	'*.pdf;*.doc;*.docx;',
			'fileDesc'		:	'Please select a PDF or a MS Word DOC file.',
			'queueSizeLimit':	1,
			'simUploadLimit':	1,
			'buttonText'	:	'SELECT A FILE', // Text for the button
			onCheck			:	function (event, checkScript, fileQueue, folder, single) {
				alert("FILE ALREADY EXISTS"); // THIS DOESN'T APPEAR TO WORK
				return false;
			},
			onComplete		:	function (event, queueID, fileObj, response, data) {
				$('#filename').val(response); // Assign the uploaded filename to the relevant hidden field
				$('#filesize').val(fileObj.size); 
				$('#file_info').html(response);
				$('#uploaded_file').html("UPLOADED FILE");				
				$('#vid_file_jUploader').hide(0);				
			}
		});
	}
	
	if ($("#news_img")) {
		$("#news_img").uploadify({
			'uploader'		:	'assets/scripts/uploadify.swf',
			'script'        :	'assets/scripts/uploadify.php',
			'cancelImg'     :	'assets/images/cancel.png',
			'folder'        :	'assets/images', // Where to save the file
			'auto'			:	true,
			'multi'         :	false, // Allow multiple file uploads? No
			'sizeLimit'		:	2 * 1048576,
			'fileExt'		:	'*.jpg;*.gif;*.png;*.jpeg;',
			'fileDesc'		:	'Please select an image file.',
			'queueSizeLimit':	1,
			'simUploadLimit':	1,
			'buttonText'	:	'SELECT IMAGE', // Text for the button
			onCheck			:	function (event, checkScript, fileQueue, folder, single) {
				alert("FILE ALREADY EXISTS"); // THIS DOESN'T APPEAR TO WORK
				return false;
			},
			onComplete		:	function (event, queueID, fileObj, response, data) {
				$('#filename').val(response); // Assign the uploaded filename to the relevant hidden field				
				$('#uploaded_file').html("UPLOADED IMAGE");
				$('#uploaded_file').show(0);
				$('#news_img_display').attr('src','assets/images/' + response);
				$('#news_img_display').show(0);				
			}
		});
	}
	
	if ($("#about_img1")) {
		$("#about_img1").uploadify({
			'uploader'		:	'assets/scripts/uploadify.swf',
			'script'        :	'assets/scripts/uploadify.php',
			'cancelImg'     :	'assets/images/cancel.png',
			'folder'        :	'assets/images', // Where to save the file
			'auto'			:	true,
			'multi'         :	false, // Allow multiple file uploads? No
			'sizeLimit'		:	1 * 1048576,
			'fileExt'		:	'*.jpg;*.gif;*.png;*.jpeg;',
			'fileDesc'		:	'Please select an image file.',
			'queueSizeLimit':	1,
			'simUploadLimit':	1,
			'buttonText'	:	'SELECT IMAGE', // Text for the button
			onCheck			:	function (event, checkScript, fileQueue, folder, single) {
				alert("FILE ALREADY EXISTS"); // THIS DOESN'T APPEAR TO WORK
				return false;
			},
			onComplete		:	function (event, queueID, fileObj, response, data) {
				$('#filename1').val(response); // Assign the uploaded filename to the relevant hidden field				
				$('#about_img_display1').attr('src','assets/images/' + response);
				$('#about_img_display1').show(0);
				$('#uploaded_file1').show(0);
			}
		});
	}
	
	if ($("#about_img2")) {
		$("#about_img2").uploadify({
			'uploader'		:	'assets/scripts/uploadify.swf',
			'script'        :	'assets/scripts/uploadify.php',
			'cancelImg'     :	'assets/images/cancel.png',
			'folder'        :	'assets/images', // Where to save the file
			'auto'			:	true,
			'multi'         :	false, // Allow multiple file uploads? No
			'sizeLimit'		:	1 * 1048576,
			'fileExt'		:	'*.jpg;*.gif;*.png;*.jpeg;',
			'fileDesc'		:	'Please select an image file.',
			'queueSizeLimit':	1,
			'simUploadLimit':	1,
			'buttonText'	:	'SELECT IMAGE', // Text for the button
			onCheck			:	function (event, checkScript, fileQueue, folder, single) {
				alert("FILE ALREADY EXISTS"); // THIS DOESN'T APPEAR TO WORK
				return false;
			},
			onComplete		:	function (event, queueID, fileObj, response, data) {
				$('#filename2').val(response); // Assign the uploaded filename to the relevant hidden field				
				$('#about_img_display2').attr('src','assets/images/' + response);
				$('#about_img_display2').show(0);
				$('#uploaded_file2').show(0);
			}
		});
	}
	
	if ($("#casest_file")) {
		$("#casest_file").uploadify({
			'uploader'		:	'assets/scripts/uploadify.swf',
			'script'        :	'assets/scripts/uploadify.php',
			'cancelImg'     :	'assets/images/cancel.png',
			'folder'        :	'casestudies', // Where to save the file
			'auto'			:	true,
			'multi'         :	false, // Allow multiple file uploads? No
			'sizeLimit'		:	20,
			'fileExt'		:	'*.jpg;*.gif;*.png;*.zip;*.pdf;*.doc;*.docx;*.xls;*.xlsx;*.csv;*.jpeg;',
			'fileDesc'		:	'Please select a file.',
			'queueSizeLimit':	1,
			'simUploadLimit':	1,
			'buttonText'	:	'SELECT A FILE', // Text for the button
			onCheck			:	function (event, checkScript, fileQueue, folder, single) {
				alert("FILE ALREADY EXISTS"); // THIS DOESN'T APPEAR TO WORK
				return false;
			},
			onComplete		:	function (event, queueID, fileObj, response, data) {
				$('#filename').val(response); // Assign the uploaded filename to the relevant hidden field
				$('#file_info').html(response);
				$('#uploaded_file').html("UPLOADED FILE");
				$('#vid_file_jUploader').hide(0);				
			}
		});
	}
	if ($("#doc_file")) {
		$("#doc_file").uploadify({
			'uploader'		:	'assets/scripts/uploadify.swf',
			'script'        :	'assets/scripts/uploadify.php',
			'cancelImg'     :	'assets/images/cancel.png',
			'folder'        :	'documents', // Where to save the file
			'auto'			:	true,
			'multi'         :	false, // Allow multiple file uploads? No
			'sizeLimit'		:	fileSizeLimit,
			'fileExt'		:	'*.pdf;*.doc;*.docx;*.xls;*.xlsx;*.csv;*.ppt;*.pptx;',
			'fileDesc'		:	'Please select a file.',
			'queueSizeLimit':	1,
			'simUploadLimit':	1,
			'buttonText'	:	'SELECT A FILE', // Text for the button
			onCheck			:	function (event, checkScript, fileQueue, folder, single) {
				alert("FILE ALREADY EXISTS"); // THIS DOESN'T APPEAR TO WORK
				return false;
			},
			onComplete		:	function (event, queueID, fileObj, response, data) {
				$('#filename').val(response); // Assign the uploaded filename to the relevant hidden field
				$('#file_info').html(response);
				$('#filesize').val(fileObj.size);
				$('#uploaded_file').html("UPLOADED FILE");
				$('#vid_file_jUploader').hide(0);				
			}
		});
	}
						   
});

function change_about() {
	window.location = "edit-about-us.php?id=" + $('#college').val();
}

function select_file_type(){
	
	if ($('#type').val() == "JPG" || $('#type').val() == "GIF" || $('#type').val() == "PNG") {
		fileSizeLimit = 6 * 1048576;
	}
	if ($('#type').val() == "MOV" || $('#type').val() == "AVI" ) {
		fileSizeLimit = 20 * 1048576;
	}
	$("#vid_file_j").uploadifySettings('fileExt','*.' + $("#type").val().toLowerCase());
	$("#vid_file_j").uploadifySettings('fileDesc','Please select a ' + $("#type").val() + ' file.');
	if ($('#type').val() == "JPG" ) {
		$("#vid_file_j").uploadifySettings('fileExt','*.jpg;*.jpeg;');
	}
	if ($('#type').val() == "PPT" ) {
		$("#vid_file_j").uploadifySettings('fileExt','*.ppt;*.pptx;');
	}
	if ($('#type').val() == "DOC" ) {
		$("#vid_file_j").uploadifySettings('fileExt','*.doc;*.docx;');
	}
	$("#vid_file_j").uploadifySettings('sizeLimit',fileSizeLimit);
}

function contact_form() {
	if ($('#name').val() == "") {
		$('#error2').html("Please enter your name.");
		return false;
	}
	if ($('#email').val() == "") {
		$('#error2').html("Please enter your email address.");
		return false;
	}
	if ($('#enquiry').val() == "") {
		$('#error2').html("Please enter your enquiry.");
		return false;
	}
	return true;
}

function start_upload_resource(details) {
	if ($('#title').val() == "") {
		$('#error').html("Please enter a Title.");
		return false;
	}
	if ($('#keywords').val() == "") {
		$('#error').html("Please enter Keywords.");
		return false;
	}	
	if (details != 'edit') {
		if ($('#type').val() == "") {
			$('#error').html("Please select the File Type.");
			return false;
		}
		if ($('#filename').val() == "") {
			$('#error').html("Please select a File to be uploaded.");
			return false;
		} 
	}
	return true;
}

function start_upload_reports(details) {
	if ($('#title').val() == "") {
		$('#error').html("Please enter a Title.");
		return false;
	}
	if ($('#keywords').val() == "") {
		$('#error').html("Please enter Keywords.");
		return false;
	}
	if ($('#type').val() == "" && $('#newtype').val() == "") {
		$('#error').html("Please select the File Type.");
		return false;
	}
	if ($('#month').val() == "") {
		$('#error').html("Please select the Month.");
		return false;
	}
	if (details != 'edit') {
		if ($('#filename').val() == "") {
			$('#error').html("Please select a File to be uploaded.");
			return false;
		} 
	}
	return true;
}

function start_upload_events() {
	if ($('#title').val() == "") {
		$('#error').html("Please enter a Title.");
		return false;
	}
	if ($('#location').val() == "") {
		$('#error').html("Please enter Location.");
		return false;
	}
	if ($('#datepicker').val() == "") {
		$('#error').html("Please select the Date.");
		return false;
	}
	return true;
}

function start_upload_links() {
	if ($('#url').val() == "") {
		$('#error').html("Please enter URL.");
		return false;
	}	
	return true;
}

function start_upload_news() {
	if ($('#title').val() == "") {
		$('#error').html("Please enter a Title.");
		return false;
	}
	if ($('#keywords').val() == "") {
		$('#error').html("Please enter Keywords.");
		return false;
	}	
	return true;
}

function start_upload_publiccasest() {
	if ($('#title').val() == "") {
		$('#error').html("Please enter a Title.");
		return false;
	}
	if ($('#filename').val() == "") {
		$('#error').html("Please select an image to be uploaded.");
		return false;
	} 
	return true;
}

function start_upload_case_studies(details) {
	if ($('#title').val() == "") {
		$('#error').html("Please enter a Title.");
		return false;
	}
	if ($('#company').val() == "") {
		$('#error').html("Please enter the Company.");
		return false;
	}
	if ($('#keywords').val() == "") {
		$('#error').html("Please enter Keywords.");
		return false;
	}
	if ($('#college').val() == "") {
		$('#error').html("Please enter a College.");
		return false;
	}	
	return true;
}

function start_upload_documents(details) {
	if ($('#title').val() == "") {
		$('#error').html("Please enter a Title.");
		return false;
	}
	if ($('#author').val() == "") {
		$('#error').html("Please enter the Author.");
		return false;
	}
	if ($('#keywords').val() == "") {
		$('#error').html("Please enter Keywords.");
		return false;
	}
	if ($('#category').val() == "" && $('#newcategory').val() == "") {
		$('#error').html("Please select the Subject Area.");
		return false;
	}
	if ($('#type').val() == "" || $('#type').val() == "e.g. white paper") {
		$('#error').html("Please enter Document Type.");
		return false;
	}
	if (details != 'edit') {
		if ($('#filename').val() == "") {
			$('#error').html("Please select a File to be uploaded.");
			return false;
		} 
	}
	return true;
}

function start_edit_member(details) {
	if ($('#firstname').val() == "") {
			$('#error').html("Please enter First Name.");
			return false;
		}
		if ($('#surname').val() == "") {
			$('#error').html("Please enter Surname.");
			return false;
		}
		if ($('#email').val() == "") {
			$('#error').html("Please enter Email address.");
			return false;
		}
		if ($('#job').val() == "") {
			$('#error').html("Please enter Job Title.");
			return false;
		}
		if ($('#college').val() == "") {
			$('#error').html("Please select College.");
			return false;
		}
		if ($('#sector1').val() == "" && $('#newsector1').val() == "") {
		$('#error').html("Please select or add Sector One.");
		return false;
	}
		
	if (details == "yes") {
		if (($('#newpw').val() != "" || $('#newpw2').val() != "") && ($('#newpw').val() != $('#newpw2').val())) {
			$('#error').html("Please make sure both Password fields match.");
			return false;
		}
	} 
	
	return true;
}

function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}

				
//********************************//
//** Menu rollovers functions  **//
//*******************************//

function navRollOver(panel){	
	
	$('.bands').each(function(index) {
			if ("#" + $(this).attr("id") != panel) {
				$(this).animate({
				height: 7
				}, 100);
			}
		});
		
		$(panel).animate({
			height: 42
		}, 400);
	
}

function navRollOut(panel){
	
	$(panel).animate({
			height: 7
		}, 400, function() {
    		// Animation complete.
  		});
	
}

//*********************************************//
//** Function to resize the text on the page **//
//*********************************************//
function jsTextResize(mode) {
	var cookieName  = "pccTextSize"
	var sizeDefault = 8;
	var sizeNow, sizeNew;
	
	if (document.getElementsByTagName) {
		// Get the necessary nodes...
		var elHTML = document.getElementsByTagName("html")[0];
		var elBody = document.getElementsByTagName("body")[0];
		// Get the current text size...
		sizeNow = parseInt(jsTextSize(elBody));
		if (!sizeNow) sizeNow = sizeDefault;
		// Process according to the specified mode...
		switch (mode) {
			case "small":
				sizeNew = sizeNow - 1;
				break;
			case "large":
				sizeNew = sizeNow + 1;
				break;
			case "reset":
				// Reset the size to the default
				sizeNew = sizeDefault;
				break;
			default:
				// Called onLoad to set the value to the cookie value...
				try {sizeNew = parseInt(jsCookieRead(cookieName));}
				catch (e) {alert(e);}
				if (!sizeNew || isNaN(sizeNew)) sizeNew = sizeDefault;
				break;
		}
		// Set the Font Sizes...
		var sizeNewString = sizeNew + "pt";
		elHTML.style.fontSize = sizeNewString;
		elBody.style.fontSize = sizeNewString;
		//Write the Cookie to store the value...
		jsCookieWrite(cookieName, sizeNew, 365);
	}
}


//**********************************************//
//** Function to return the current font size **//
//**********************************************//
function jsTextSize(el) {
	var size = 0;
	if (el.style && el.style.fontSize) size = el.style.fontSize;
	else if (typeof(getComputedStyle) != 'undefined') size = getComputedStyle(el, '').getPropertyValue('font-size');
	else if (el.currentStyle) size = el.currentStyle.fontSize;
	// May return "XX" or "XXpt", so trim the alpha-characters...
	if (isNaN(size)) {
		for (var end = size.length - 1; end >= 0; end--) {
			if (!isNaN(size.substr(end, 1))) break;
		}
		size = size.substr(0, ++end);
	}
	return (isNaN(size) ? null : size);
}

//************************************************//
//** Function to write a new client-side Cookie **//
//************************************************//
function jsCookieWrite(name, value, daysToExpiry) {
	if (name && value) {
		var cookie = name + "=" + value + ";path=/;";//domain=.plymouth.gov.uk;";
		if (daysToExpiry) {
			if (isNaN(daysToExpiry)) days = 365;
			var expires = new Date((new Date()).getTime() + (daysToExpiry * 24 * 60 * 60 * 1000));
			cookie += "expires=" + expires.toGMTString() + ";";
		}
		document.cookie = cookie;
	}
}


//*******************************************//
//** Function to read a client-side Cookie **//
//*******************************************//
function jsCookieRead(name) {
	var value = null;
	var reg = new RegExp("\\b" + name + "\\b");
	var cookies = document.cookie.split(";");
	for(var i = 0; i < cookies.length; i++) {
		var cookie = cookies[i].split("=");
		if (reg.test(cookie[0])) {
			value = cookie[1];
			break;
		}
	}
	return value;
}


