
var $j = jQuery.noConflict();
var indexNews=0;
var number=0;
/**
* This function changes the background colour of
* a web page based on a colour specified when the
* function is called
* @param {string} col Colour
*/

function moveImage() {
	if (number>=2) number=0;
        else number = number+1;
	$j("#newspannel").scrollTop(number*352);
}

function changeCol(col)
{
	document.body.background=col;image_Accessibility_XHTML
}

function movesizeandopen()
{
	var uagent = navigator.userAgent.toLowerCase();
	if((uagent.match(/iAndroid/i)) || (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
		window.location.href = "http://www.thomroth.ac.uk/web/phone/index.php";
	}
}

$j(document).ready(function() {
	var i;
	var title_content = "#content_bottom";

	setInterval("moveImage()",8000);

	if ($j(title_content)) $j(title_content).hide();
	for (i=0;i<myBlocks.length;i++)
	{
		id_block = myBlocks[i];
		title_content = "#content_bottom"+id_block;
		if ($j(title_content)) $j(title_content).hide();
	}

	//check if the device is an iphone
	movesizeandopen();

	//create the central image with link and tab menus, just for the homepage
	if ($j("#flash_object_margin").length >0) {
	//clicking an image
	$j("#flash_object_margin .tabs li a").click(function() {
				number = parseInt(this.hash.substr(1));
				var description = $j(".news li img").eq(number).attr("alt").split("-");
				document.location.href = "http://www.thomroth.ac.uk/web/website/index.php?id_user=0&id_layer=0&id=" + description[1];
	});
	//mouse over the image
	$j("#flash_object_margin .tabs li a").mouseover(function() {
				number = parseInt(this.hash.substr(1));
				var description = $j(".news li img").eq(number).attr("alt").split("-");
				$j("#newspannel").scrollTop(number*352);
				$j(".pannel").html("<a style='color:white' href='http://www.thomroth.ac.uk/web/website/index.php?id_user=0&id_layer=0&id="+description[1]+"'>" + description[0] + "</a>");
	});
	//init the first pannel
	var description = $j(".news li img").eq(0).attr("alt").split("-");
	$j(".pannel").html("<a style='color:white' href='http://www.thomroth.ac.uk/web/website/index.php?id_user=0&id_layer=0&id="+description[1]+"'>" + description[0] + "</a>");
	}

	//twitter logo
	var topTwitter = $j("#header").position().top + 18;
	var leftTwitter = $j("#header").position().left + 780;
	$j("#twitter_logo").css({"top":topTwitter + "px","left":leftTwitter + "px"});
	$j("#twitter_logo").click(function() {
			document.location.href="http://www.twitter.com/ThomRothCol";
	});

	//facebook logo
	var leftFacebook = $j("#header").position().left + 820;	
	$j("#facebook_logo").css({"top":topTwitter + "px","left":leftFacebook + "px"});
	$j("#facebook_logo").click(function() {
			document.location.href="http://www.facebook.com/pages/Thomas-Rotherham-College/197021846989735";
	});

	//short cut to administration site
	/*
	$j("#image_Accessibility_XHTML").click( function() {
			document.location.href="http://www.thomroth.ac.uk/web/admin/admin.php";
	});
	*/
});

function searchBox()
{
	//set the values and send the post form
	if ($j('#id')) 			$j('#id').val(1000);
	if ($j('#id_user')) 		$j('#id_user').val(0);
	if ($j('#id_layer')) 		$j('#id_layer').val(0);
	if ($j('#value')) 		$j('#value').val($j('#searchBox').val());
	if ($j('#sendFormElement')) 	$j('#sendFormElement').submit();
}

function sendFeedback()
{
	var d = new Date();
	var find_information = $j('input[name=find_information]:checked').val();
	var friendly_way = $j('input[name=friendly_way]:checked').val();
	var sections_careers =$j('#sections_careers').val();
	var missing_careers =$j('#missing_careers').val();
	var request_reference = $j('input[name=request_reference]:checked').val();
	var more_information = $j('#more_information').val();

	var content = "<h3>We have received this Feedback</h3>";
	content = content + "Did you manage to find the information and advice you needed on the website?" + find_information +"<br/>";
	content = content + "Was the information set out in a user friendly way?" + friendly_way +"<br/>";
	content = content + "Which sections did you find most useful?" + sections_careers +"<br/>";
	content = content + "Is there anything missing that would be useful for ex-students?" + missing_careers +"<br/>";
	content = content + "If you requested a reference did you receive it in the allocated 7 working days?" + request_reference +"<br/>";
	content = content + "Is there anything else that you’d like to say about the ex trc section of the website?" + more_information +"<br/>";

	$j.get("http://www.thomroth.ac.uk/web/website/email.php", { 
		subject: "Careers Feedback",  
		contents: content , 
		to: "Cerise.Walters@thomroth.ac.uk" , 
		from:"Cerise.Walters@thomroth.ac.uk" ,
		time: d.getTime()},
  	function(data){
    		alert('Your feedback has been sent');
  	});

  	$j.get("http://www.thomroth.ac.uk/web/website/insertFeedback.php", { 
  		find_information: find_information,
  		friendly_way: friendly_way,
  		sections_careers: sections_careers,
  		missing_careers: missing_careers,
  		request_reference: request_reference,
  		more_information: more_information,
		time: d.getTime()},
  	function(data){
  	});
}

function sendEmail(topic)
{
	var content = "";
	var d = new Date();
	var url;
	if (topic == "recommend") {
		content = "Your friend " + $j('#name').val() + " has recommend you this page: http://www.thomroth.ac.uk";
		$j.get("http://www.thomroth.ac.uk/web/website/email.php", { subject: topic, from: $j('#email').val(), contents: content , to: $j('#address').val() , time: d.getTime()},
  		function(data){
    		document.location.href="http://www.thomroth.ac.uk/web/website/index.php?id_user=1&id_layer=0&id=346&value=";
  		});
	} else {
	   if (topic == "prospectus_request") {
		if ($j('#further').attr('checked'))	result = "yes";
		else result = "no";
		content = "Name: " + $j('#name').val() + ", telephone:" + $j('#telephone').val() + ", email:" + $j('#email').val() + ", address:" + $j('#address').val() + ", further information:" + result;
		$j.get("http://www.thomroth.ac.uk/web/website/email.php", { subject: topic, from: $j('#email').val(), contents: content, to: "Carolyn.Granger@thomroth.ac.uk" , time: d.getTime()},
  		function(data){
    		document.location.href="http://www.thomroth.ac.uk/web/website/index.php?id_user=1&id_layer=0&id=347&value=";
  	        });
			} else {
	 	content = "Name: " + $j('#name').val() + ", telephone:" + $j('#telephone').val() + ", email:" + $j('#email').val() + ", message:" + $j('#message').val();
		$j.get("http://www.thomroth.ac.uk/web/website/email.php", { subject: topic, from: $j('#email').val(), contents: content, to: "enquiries@thomroth.ac.uk" , time: d.getTime()},
  		function(data){
    		alert('Your message has been sent');
  		});
			}
	}
}

/**
*	Function that goes to another part of the website using the POST method
*
*	@param href_text	url of the address that we want to use
*/
function sendElement(href_text) {

	var id_user = 0;
	var id_layer = 0;
	var id_block = 0;

	var init_position = href_text.indexOf('&');
	if (init_position >=0) {
		var id_block = href_text.substring(13,init_position);
		var second_position = href_text.indexOf('&',init_position+1);
		if (second_position >=0) { //3 parameters
			id_block = href_text.substring(13,init_position);
			var firstEqual = href_text.indexOf('=',init_position + 1);
			if (href_text.substring(init_position+1,firstEqual) == "id_user") {
				id_user = href_text.substring(firstEqual+1,href_text.length);
			}
			if (href_text.substring(init_position+1,firstEqual) == "id_layer") {
				id_layer = href_text.substring(firstEqual+1,href_text.length);
			}
			var secondEqual = href_text.indexOf('=',second_position + 1);
			if (href_text.substring(second_position+1,secondEqual) == "id_user") {
				id_user = href_text.substring(secondEqual+1,href_text.length);
			}
			if (href_text.substring(second_position+1,firstEqual) == "id_layer") {
				id_layer = href_text.substring(secondEqual+1,href_text.length);
			}
		} else { //2 parameters
			id_block = href_text.substring(13,init_position);
			var firstEqual = href_text.indexOf('=',init_position + 1);
			if (href_text.substring(init_position+1,firstEqual) == "id_user") {
				id_user = href_text.substring(firstEqual+1,href_text.length);
			}
			if (href_text.substring(init_position+1,firstEqual) == "id_layer") {
				id_layer = href_text.substring(firstEqual+1,href_text.length);
			}
		}
	} else { //1 parameter
	 	id_block = href_text.substring(13,href_text.length);
	}

	//set the values and send the post form
	if ($j('#id')) 			$j('#id').val(id_block);
	if ($j('#id_user')) 		$j('#id_user').val(id_user);
	if ($j('#id_layer')) 		$j('#id_layer').val(id_layer);
	if ($j('#sendFormElement')) 	$j('#sendFormElement').submit();
}

/**
*
*/
function showBlock(id_block)
{
	var title_content = "#content_bottom" + id_block ;

	if ($j(title_content)) {
		if ($j(title_content).is(":visible")) {
			if ($j('#content_block_init' + id_block)) Effect.BlindDown('content_block_init' + id_block);
			if ($j('#content_block_end' + id_block)) Effect.BlindDown('content_block_end' + id_block);
			if ($j(title_content)) $j(title_content).hide();
		} else {
			if ($j('#content_block_init' + id_block)) Effect.BlindUp('content_block_init' + id_block);
			if ($j('#content_block_end' + id_block)) Effect.BlindUp('content_block_end' + id_block);
			if ($j(title_content)) $j(title_content).show();
		}
	}
	return false;
}

/**
*	This function hides all blocks on the page
*/
function hideAllBlock()
{
	var id_block;

	for (i=0;i<myBlocks.length;i++)
	{
		id_block = myBlocks[i];
		var title_content = "content_bottom" + id_block;
		if ($j(title_content)) {
		if ($(title_content).visible()) {
			if ($j('#content_block_init' + id_block)) Effect.BlindDown('content_block_init' + id_block);
			if ($j('#content_block_end' + id_block)) Effect.BlindDown('content_block_end' + id_block);				
			if ($j(title_content)) $j(title_content).hide();
		} else {
			if ($j('#content_block_init' + id_block)) Effect.BlindUp('content_block_init' + id_block);
			if ($j('#content_block_end' + id_block)) Effect.BlindUp('content_block_end' + id_block);
			if ($j(title_content)) $j(title_content).show();
		}
		}
	}
	return false;
}


/**
* This function formats text as a heading 1 by
* wrapping HTML tags around it
* @param {string} text Text
*/

function heading(text){
	document.write('<h1>' + text + '<h1>');
}

/**
* This function formats text as a heading 2 by
* wrapping HTML tags around it
* @param {string} text Text
*/

function subHeading(text){

	document.write('<h2>' + text + '<h2>');
}

/**
* This function formats text as a paragraph by
* wrapping HTML tags around it
* @param {string} text Text
*/

function paragraph(text){
	document.write('<p>' + text + '<p>');
}
/** 
* This function opens a popup window
* @param {string} url URL
*/

function popUpWin(url){
	window.open(url, "myPopUp" , 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=500,left = 200,top = 200');
}

function writit(text,id)
{
	$j(id).html(text);
}

function generalInfo()
{
	writit("If you want to see more information about the Corporation members move your mouse over the pictures","#card");
}

function ShowOrHide2(d1, d2,d3) {
	  if (d1 != '') DoDiv(d1);
	  if (d2 != '') DoDiv(d2);
	  if (d3 != '') DoDiv(d3);
}


