//fix background image flickering in IE

/*@cc_on 
	@if (@_win32)
	try {
	  document.execCommand('BackgroundImageCache', false, true);
	} catch(e) {}
	@end
@*/
/*Fazal Khan at Fortune Cookie dot co dot uk*/

var	FCfunctions = {
	textresize : function(){
		var $_cookie_name = "oxfam_textsize";
		var $_originalFontSize = $("html").css("font-size");
		var $_date = new Date();
        $_date.setTime($_date.getTime() + 2419200000);//28 days	
		if($.cookie($_cookie_name)){
			var $_getSize = $.cookie($_cookie_name);
			/*@cc_on
   				/*@if (@_win32)
      				$("html").css({fontSize : $_getSize});
   				@else @*/
      				$("html").css({fontSize : $_getSize + "px"});
   				/*@end
			@*/
		} else{
			$.cookie($_cookie_name, $_originalFontSize, { expires : $_date });
		}
		$(".textSize").find("li a").each(function(){
			$(this).bind("click", function(){
				var $_currentFontSize = $("html").css("font-size");
				var $_currentFontSizeNum = parseFloat($_currentFontSize, 10);				
					if ( $(this).is("#text-smaller")){
						var $_newFontSize = $_currentFontSizeNum*0.9;
						if ($_newFontSize > 12) {
							$("html").css({fontSize : $_newFontSize});
							$.cookie($_cookie_name, $_newFontSize, { expires : $_date });	
						}
					} else if ( $(this).is("#text-larger")){
						var $_newFontSize = $_currentFontSizeNum*1.2;
						if ($_newFontSize < 20) {
							$("html").css({fontSize : $_newFontSize});
							$.cookie($_cookie_name, $_newFontSize, { expires : $_date });
						}
					} else	{
						$("html").css({fontSize : $_originalFontSize});
						$.cookie($_cookie_name, $_originalFontSize, { expires : $_date });
					}
					return false
			});
		});
	},
	fancybox : function(){
		var $container = ".related-image-library";
		var $preloadersrc = "images/ajax-loader.gif"; 
		var $preloader = '<div style="position:absolute;top:100px;left:100px;"><img src="'+$preloadersrc+'"/></div>';
		var $strbefore = '<div id="fancybox" class="clear"><div id="closebox"><img src="images/fancy-closebox.png" /></div><div id="fancybox-left" class="fancyshadow"></div><div id="fancybox-middle"><div id="fancybox-top" class="fancyshadow"></div><div id="fancy-image"><img src="';
		var $strafter = '" width="488" height="351" alt="large image" /></div><div id="fancybox-bottom" class="fancyshadow"></div></div><div id="fancybox-right" class="fancyshadow"></div></div>';
		var $fancyimg = "#fancy-image";
		var $fancybox = "#fancybox";
		
		$($container).children(".content").append('<div id="fancybox-wrapper" class="clear"></div>');
		
		$($container).find("a").each(function (i){
			var $src = $(this).attr("href");
			$(this).bind("click",function(){
				attachImage($src);
				return false;
			});
		});	
		function attachImage($newsrc){	
		/*var $imgpreload = new Image();
   			$imgpreload.src = $newsrc;*/      
			$fancystr = $strbefore+$newsrc+$strafter;
			//if($imgpreload.complete){
			$("#fancybox-wrapper").append($fancystr);
			$($fancyimg).animate({"opacity": "toggle"}, "slow", function() {
				fadeInshadow();
			});		
			//}
		}
		
		function fadeInshadow(){
			$($fancyimg).css("padding","0");
			$(".fancyshadow").animate({"opacity": "toggle"}, "fast", function() {
					addFunctionality();
			});		
		}
		
		function addFunctionality(){
			$("#closebox").fadeIn("fast");
			$("#closebox").bind("click",function(){
				$($fancybox).animate({"opacity": "toggle"},  "fast", function() {
					removefancyBox()
				});			
			});
		}
		
		function removefancyBox(){
			$("#closebox").unbind("click");
			if($($fancybox).not(":visible")){
				$("#fancybox-wrapper").empty();
			}
		}
	}
}
$(document).ready(function(){
		FCfunctions.textresize();		
		FCfunctions.fancybox();
/*		FCfunctions.printpage(); */
})

/*	printpage : function(){
	//change the print this page option to use javascript otherwise will redirect to a print only view
	var $str = PRINT_PAGE_LABEL;
	//$("#print-view a").text($str).addClass("print-page").bind("click", function(){window.print(); return false;});
	$("#print-view").append("<a href='javascript:self.print();'>" + PRINT_PAGE_LABEL + "</a>");
}, */
