/*********************************

©2009 Ukoh William @ http://www.williamukoh.com. All rights reserved. Forget it, I will sue!!!

************

META-DATA

************

@ date created :: 28 January 2009

@ last modified :: 28 January 2009

@ description :: Contains client-side logic for all pages :) requires jQuery javascript library

*/

//Add my custom functions to the jQuery object

jQuery.extend(jQuery,

			  {

				  "namespace" : function(ns,obj){

	

						var obj = obj || window, i=0, e = ns.split(".");

						

						while(e[i]){		

							if(typeof obj[e[i]] == "undefined"){			

								obj[e[i]] = {};

								obj = obj[e[i++]];

							}else

								obj = obj[e[i++]];

						}

						return obj;

				  }

			  });



//Create dedicated namespace for this site

jQuery.namespace("org.africafc.pages");

jQuery.namespace("org.africafc.utils");



//populate namespace

org.africafc.pages = 

{

	init : function(){

		

		$("div.page-controls a")

		.bind("click",function(e){

						alert("This portion of the website still under construction");

						return false;

		});

													   

		//Fix PNG in IE6

		if($.browser.msie && parseInt($.browser.version) <= 6){

				$LAB.script("/assets/js/lib/DD_belatedPNG.js")

				.block(function(){

					DD_belatedPNG.fix("img,div.search-holder");

				});

		}

		

		//Configure Search Input field

		$("#q").

		focus(function(){

					$(this).val() == "Search" ? $(this).val("") : void(0);

			}).

		blur(function(){

					$.trim($(this).val()) == "" ? $(this).val("Search") : void(0);

		});

		

		//Configure external links

		$("a.external,area.external").click(function(){

				window.open($(this).attr("href"));

				return false;

		 });

		

		$("img.zoom").each(function(){

				$(this).wrap("<a href='"+$(this).attr("src")+"' class='fancybox' />");

		});

		

		//Load CSS

		org.africafc.utils.loadCSS("/assets/js/plugins/fb/jquery.fb.css");

		

		$LAB.toBODY().script("/assets/js/plugins/fb/jquery.fb.js")

		.block(function(){

					   $("a.fancybox").fancybox({

									'zoomSpeedIn' :	300,

									'zoomSpeedOut':	300,

									'overlayOpacity' : 0.6

						});

		});

	},

	

	home :

	{

		init : function(images)

		{

			var _bg,_c;

			var _ns = org.africafc;

			
			/*
			if(images.length){

			

				_c = _ns.utils.get_cookie("currentIndex");

				

				if(!_c){

					_ns.utils.set_cookie("currentIndex",0,2020,"11","30");

					_c = 0;

				}else{

					_c++;

					

					if(_c >= images.length)

						_c = 0;

					_ns.utils.set_cookie("currentIndex",_c,"2011","11","30");

					

				}

				

				_bg = "/assets/images/banners/" + images[_c];

				//alert(_bg);

				//console.dir($);

				//$("div.banners-holder").html("<img src='"+_bg+"' height='300' width='950' />");

			}else

				$("div.banners-holder").html("<img src='/assets/images/default_banner.jpg' height='300' width='950' />");

				
			*/
			$("#marq").hover(function(){

									  $(this).get()[0].stop();

									  },

							function(){

										$(this).get()[0].start();

							});

		}

	},

	

	services :

	{

		init : function()

		{

			var _ns = org.africafc;

			

			$LAB.script("/assets/js/lib/swfobject_modified.js");

		}

	}



}



org.africafc.utils = 

{

	"set_cookie" : function(name, value, exp_y, exp_m, exp_d, path, domain, secure){

		

		var cookie_string = name + "=" + escape ( value );



		if ( exp_y )

		{

			var expires = new Date ( exp_y, exp_m, exp_d );

			cookie_string += "; expires=" + expires.toGMTString();

		}

		

		if ( path )

			cookie_string += "; path=" + escape ( path );

		

		if ( domain )

			cookie_string += "; domain=" + escape ( domain );

		

		if ( secure )

			cookie_string += "; secure";

		

		document.cookie = cookie_string;

	},

	

	"get_cookie" : function(cookie_name){

		var results = document.cookie.match (cookie_name + '=(.*?)(;|$)');

		if ( results )

			return ( unescape ( results[1] ) );

		else

			return null;

	},

	

	"delete_cookie" : function(cookie_name){

		var cookie_date = new Date ( );  // current date & time

		cookie_date.setTime ( cookie_date.getTime() - 1 );

		document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();

	},



	loadCSS:  function(url){

		var newCSS = document.createElement('link');

		   newCSS.href = url; //path to CSS file

		   newCSS.type = 'text/css';

		   newCSS.rel = 'stylesheet';



			//Add CSS to Document

		   var head = document.getElementsByTagName('head')[0];

		   if(!head) return;

		   head.appendChild(newCSS);

	},

	

	preloadImages: function(){

		var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

		var i,j=d.MM_p.length,a=this.preloadImages.arguments; for(i=0; i<a.length; i++)

		if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}	

	}

}

//initialize for all pages of this site
$(document).ready(function(){
	org.africafc.pages.init();
});
