
var $j = jQuery.noConflict();

/**
* 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 changeCol(col)   
{   
	document.body.background=col;
}   

$j(document).ready(function() {
	var i;
	var title_content = "#content_bottom";
	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();
	}

	//create the central image with link and tab menus
	
	var position = $j('#image_gallery').offset();
	if (position) {
	$j('#title_gallery').animate({opacity: 0.75},10);
	$j('#flash_object_margin ul').css({top:position.top,left:position.left});

	$j('#flash_object_margin ul li').each(function(index) {
		if (index==0) {$j(this).css({'background-color':'#c148a0','color':'white'});}
		if (index==1) {$j(this).css({'background-color':'#4859c1','color':'white'});}
		if (index==2) {$j(this).css({'background-color':'#59c148','color':'white'});}
		$j(this).click(function() {
		var title = $j(this).attr('title');
		var image = $j(".span_image",this).html();
		var url = $j(".url_image",this).html();		
		$j('#image_gallery').attr('src','nav_modules/images/' + image);
		$j('#title_gallery').empty();
		$j('#title_gallery').html('<a href="'+url+'">'+ title +'</a>');						
		});
	});
	}
});

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 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("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("email.php", { subject: topic, from: $j('#email').val(), contents: content, to: "Sue.Bridges@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("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);
	}

