/*
 * functions.js
 * http://www.madebybusara.com
 *
 * Date: Wed, 30 Jan 2009
 * Revision: 1
 */
$(document).ready(function(){
    /**
      * Show and Hide CVs on 'team/index' Page
      * @author	Maffo - andy.mathieson@madebybusara.com
      * @version 1.0
      * @uses Jquery
      * @returns void 
    */
 	 $(".partnerPerson").click(function(event)
 	 {
  	 	event.preventDefault();
  	 	// get the id 
  	 	var person = this.id;
  	 	// Hide any open CV's
  	 	$(".cv").hide("slow");
  	 	// If this person is hidden and clicked then show
  	 	if ( $('#'+person+'CV').is(':hidden') )
  	 	{
			$('#'+person+'CV').show("slow");
		}
		else{ // If this person is visible and clicked then hide 
			$(".cv").hide("slow");
		}
 	});// END FUNCTION
 	
 	
 	/**
 	  * Load Job Vacany via AJAX on 'jobs/index' Page
 	  * @author Maffo - andy.mathieson@madebybusara.com
 	  * @version 1.0
 	  * @uses Jquery
 	  * @returns void 
 	*/
 	 $(".jobLink").click(function(event){
  	 	event.preventDefault();
  	 	// get the url (url is set as the id of our hyperlink)
  	 	var url = this.id.replace("_", "/");
  	 	url = url.replace("_", "/");
		//perform the AJAX
		$.get(url, function(data)
		{
  	 		//Hide Old Article
  	 		$("#jobArticle").fadeOut("fast");
 			$("#jobArticle").html(data);
 			// Show new article
 			$('#jobArticle').fadeIn("slow");
 		});
 		
 		
 	});// END FUNCTION
 	
 	
 	/**
 	  * Delete PDF File via AJAX on the 'jobs/edit' page and replace with fresh file upload option
 	  * @author Maffo - andy.mathieson@madebybusara.com
 	  * @version 1.0
 	  * @uses Jquery
 	  * @returns void 
 	*/
 	$(".deletepdf").click(function(event){
  	 	event.preventDefault();
  	 	// get the url (url is set as the id of our hyperlink)
  	 	var url= this.id;
  	 	//Remove Old Pdf From Screen
  	 	$("#pdfCell").fadeOut("fast");;
		//perform the AJAX
		$.get(url, function(data)
		{
 			// Load the table cell with our file upload 
 			$("#pdfCell").html('<input id="JobPdf" type="file" value="" size="23" name="data[Job][pdf]"/>');
 		});
 		
 		// Display the contents of the new table cell
 		$("#pdfCell").fadeIn("slow");
	});  // END FUNCTION
 	
 	/**
 	  * Loads a News Article via AJAX on our 'news/index' and 'reports/index' pages
 	  * @author Maffo - andy.mathieson@madebybusara.com
 	  * @version 1.0
 	  * @uses  Jquery
 	  * @returns void 
 	*/
 	$(".newsLink").live("click",function(event){
  	 	event.preventDefault();
  	 	// get the url (url is set as the id of our hyperlink)
  	 	var url = this.id.replace("_", "/");
  	 	url = url.replace("_", "/");
		//perform the AJAX
		$.get(url, function(data)
		{	
 			//Hide Old Article
  	 		$("#newsArticle").hide(0);
 			// Load the data into our news article div
 			$("#newsArticle").html(data);
 			// Display the contents of our Div
 			$('#newsArticle').show(0); //("slow");;
 		});
 		
	});  // END FUNCTION
	
	/**
 	  * Loads a News Archive via AJAX on our 'news/index' and 'reports/index' pages
 	  * @author Maffo - andy.mathieson@madebybusara.com
 	  * @version 1.0
 	  * @uses  Jquery
 	  * @returns void 
 	*/
 	$(".archiveLink").live("click", function(event){
  	 	event.preventDefault();
  	 	var url = "news/archive/"
		//perform the AJAX
		$.get(url, function(data)
		{	
 			//Hide Old Article
 			$("#newsDiv").fadeOut("fast");
 			// Load the data into our news article div
 			$("#newsDiv").html(data);
 			// Display the contents of our Div
 			$("#newsDiv").fadeIn("slow");
 		});
 		
	});  // END FUNCTION
	
	/**
 	  * Loads a Swarratonian News Archive via AJAX on our 'reports/index' page
 	  * @author Maffo - andy.mathieson@madebybusara.com
 	  * @version 1.0
 	  * @uses  Jquery
 	  * @returns void 
 	*/
 	$(".swarArchiveLink").live("click", function(event){
  	 	event.preventDefault();
  	 	var url = "reports/archive/"
		//perform the AJAX
		$.get(url, function(data)
		{	
 			//Hide Old Article
 			$("#reportsDiv").fadeOut("fast");
 			// Load the data into our news article div
 			$("#reportsDiv").html(data);
 			// Display the contents of our Div
 			$("#reportsDiv").fadeIn("slow");
 		});
 		
	});  // END FUNCTION
	
	/**
 	  * Loads a News Year via AJAX on our 'news/index' and 'reports/index' pages
 	  * @author Maffo - andy.mathieson@madebybusara.com
 	  * @version 1.0
 	  * @uses  Jquery
 	  * @returns void 
 	*/
 	$(".yearLink").live("click", function(event){
  	 	event.preventDefault();
  	 	var url = "news/year/"+this.id;
		//perform the AJAX
		$.get(url, function(data)
		{	
 			//Hide Old Article
 			$("#newsDiv").fadeOut("fast");
 			// Load the data into our news article div
 			$("#newsDiv").html(data);
 			// Display the contents of our Div
 			$('#newsDiv').fadeIn("slow");
 			
 		});
 		
	});  // END FUNCTION
	
	/**
 	  * Loads a News Year via AJAX on our 'news/index' and 'reports/index' pages
 	  * @author Maffo - andy.mathieson@madebybusara.com
 	  * @version 1.0
 	  * @uses  Jquery
 	  * @returns void 
 	*/
 	$(".swarYearLink").live("click", function(event){
  	 	event.preventDefault();
  	 	var url = "reports/year/"+this.id;
		//perform the AJAX
		$.get(url, function(data)
		{	
 			//Hide Old Article
 			$("#reportsDiv").fadeOut("fast");
 			// Load the data into our news article div
 			$("#reportsDiv").html(data);
 			// Display the contents of our Div
 			$('#reportsDiv').fadeIn("slow");
 			
 		});
 		
	});  // END FUNCTION
	
	
	
	/**
	  * Remove images from our 'news/edit' page via AJAX
	  * @author Maffo - andy.mathieson@madebybusara.com
	  * @version 1.0
	  * @uses Jquery
	  * @returns void 
	*/

	 $(".newsRemoveImg").click(function(event){
  	 	event.preventDefault();
  	 	// get the url (url is set as the id of our hyperlink)
  	 	var url= this.id;
  	 	// url looks like 'news/removeimg/article_id/image_id'
  	 	var img = url.substr(-1);
  	 	// Remove Old Image From Screen
  	 	$("#newsImgCell"+img).fadeOut("fast");;
		// Delete Image from Server and update record in table using AJAX
		$.get(url, function(data)
		{
 			// Assing an image upload field to our table cell	
 			$("#newsImgCell"+img).html('<input type="file" id="NewsImg'+img+'Upload" value="" size="23" name="data[News][img'+img+'_upload]"/>');
 		});
 		// Display contents of our Table Cell
 		$("#newsImgCell"+img).fadeIn("slow");;
	}); // END FUNCTION
	
	/**
	  * Remove images from our 'Concerns' page via AJAX
	  * @author Maffo - andy.mathieson@madebybusara.com
	  * @version 1.0
	  * @uses Jquery
	  * @returns void 
	*/

	 $(".concernRemoveLogo").click(function(event){
  	 	event.preventDefault();
		
  	 	// Remove Old Image From Screen
  	 	$("#ConcernLogoCell").fadeOut("fast");;
		// Delete Image from Server and update record in table using AJAX
		var url = "concerns/rmvLogo/"+this.id;
		$.get(url, function(data)
		{
 			// Assing an image upload field to our table cell	
 			$("#ConcernLogoCell").html('<input id="ConcernLogoUpload" type="file" value="" size="23" name="data[Concern][logo_upload]"/>');
 		});
 		// Display contents of our Table Cell
 		$("#ConcernLogoCell").fadeIn("slow");;
	}); // END FUNCTION
	
	/**
	  * Remove picture from our 'Concerns' page via AJAX
	  * @author Maffo - andy.mathieson@madebybusara.com
	  * @version 1.0
	  * @uses Jquery
	  * @returns void 
	*/

	 $(".concernRemovePicture").click(function(event){
  	 	event.preventDefault();
		
  	 	// Remove Old Image From Screen
  	 	$("#ConcernPictureCell").fadeOut("fast");;
		// Delete Image from Server and update record in table using AJAX
		var url = "concerns/rmvPic/"+this.id;
		$.get(url, function(data)
		{
 			// Assing an image upload field to our table cell	
 			$("#ConcernPictureCell").html('<input id="ConcernPictureUpload" type="file" value="" size="23" name="data[Concern][picture_upload]"/>');
 		});
 		// Display contents of our Table Cell
 		$("#ConcernPictureCell").fadeIn("slow");;
	}); // END FUNCTION
	
	//
	
	/**
	  * Cycle images on homepage and our focus page
	  * @author Maffo - andy.mathieson@madebybusara.com
	  * @version 1.0
	  * @uses Jquery
	  * @returns void 
	*/
	$(function()
	{
   		$('#zone1div').cycle('fade');
   	});
	
	/**
	  * Our Team Page, adds mouse over effect to christopje and stephen
	  * @author Maffo - andy.mathieson@madebybusara.com
	  * @version 1.0
	  * @uses Jquery
	  * @returns void 
	*/
	var img1 = "img/company/team/stephen2.jpg";
    var img2 = "img/company/team/stephen_face.gif";
	$("#stephen").hover(function()
	{
		$('#stephen_pic1').fadeTo("fast", 0.1, function()
		{
			this.src =img2;
			$('#stephen_pic1').fadeTo("fast", 1.0);
			$('#stephenText').html('A village in the south of England.');
		 // This sets the opacity to 100% on hover
		});
	},function()
	{
		$('#stephen_pic1').fadeTo("fast", 0.1, function()
		{
			this.src =img1;
			$('#stephen_pic1').fadeTo("fast", 1.0);
			$('#stephenText').html('&#160;');
		 // This sets the opacity to 100% on hover
		});		
			
	});
	
	var img3 = "img/company/team/christophe2.jpg";
    var img4 = "img/company/team/christophe_face.gif";
	$("#christophe").hover(function()
	{
		$('#christophe_pic1').fadeTo("fast", 0.1, function()
		{
			this.src =img4;
			$('#christophe_pic1').fadeTo("fast", 1.0);
			$('#christopheText').html('Early experience of the energy industry in Angola.');
			
		 // This sets the opacity to 100% on hover
		});
	},function()
	{
		$('#christophe_pic1').fadeTo("fast", 0.1, function()
		{
			this.src =img3;
			$('#christophe_pic1').fadeTo("fast", 1.0);
			$('#christopheText').html('&#160;');
			
		 // This sets the opacity to 100% on hover
		});		
			
	});// END FUNCTION

});
