$(document).ready(function(){

	pngenius(ie);

	$('#nav a').qtip({
		style: { 
	      background: '#0e7153',
   	   color: '#ffffff',
   	   border: {
				width: 2,
				color: '#ffffff'
   	   },
			tip: 'topMiddle',
			width: 300
      },
		hide: { when: 'mouseout', fixed: true  },
		position: { adjust: { x: -250, y: 10 } }

	});


	$('#nav a.selected').qtip('destroy');



	$('#nav a.selected').qtip({
		style: { 
	      background: '#0e7153',
   	   color: '#ffffff',
   	   border: {
				width: 2,
				color: '#ffffff'
   	   },
			tip: 'topMiddle',
			width: 300
      },
		hide: { when: 'mouseout', fixed: true  },
		position: { adjust: { x: -250, y: -90 } }

	});


	$("#subnav a").removeAttr('title');


	$('a[rel=external]').click(function(){
		window.open( $(this).attr('href') );
		return false;
	}); 




	$("#subnav li ul").hide();

//	$(".parent").click(function(){
//		$(this).next('ul').slideToggle("fast");
//		return false;
//	});



	if ( $("#subnav .selected").length > 0 ) {
		$("#subnav").find(".selected").each(function(i) {
			$(this).parents().show();
		});
	} 


	if ( $("#subnav .open").length > 0 ) {
		$("#subnav").find(".open").each(function(i) {
			$(this).find('ul').show();
		});
	} 



	$("a.fancy").fancybox({
		'zoomSpeedIn'			: 600,
		'zoomSpeedOut'			: 500,
		'easingIn'				: 'easeOutBack',
		'easingOut'				: 'easeInBack'
	});


	$("a.fancyvideo").fancybox({
		'zoomSpeedIn'			: 600,
		'zoomSpeedOut'			: 500,
		'easingIn'				: 'easeOutBack',
		'easingOut'				: 'easeInBack',
		'hideOnContentClick': false,
		'frameWidth': 550,
		'frameHeight': 430
		
	});


	
});



function HexToR(h) {return parseInt((cutHex(h)).substring(0,2),16)}
function HexToG(h) {return parseInt((cutHex(h)).substring(2,4),16)}
function HexToB(h) {return parseInt((cutHex(h)).substring(4,6),16)}
function cutHex(h) {return (h.charAt(0)=="#") ? h.substring(1,7):h}



function plainUrl(url)
{

	var cleanStart;
	var cleanEnd;
	

	//alert(url.charAt(4));


	if(url.charAt(4) == '"')
	{
		cleanStart = url.slice(5);
		cleanEnd = cleanStart.slice(0,(cleanStart.length-2));
	
	} else {

		cleanStart = url.slice(4);
		cleanEnd = cleanStart.slice(0,(cleanStart.length-1));	
	}


	return cleanEnd;
}



function pngenius(ie)
{
	$("h3").each(function(){

		var colour;
		
		if(ie)
		{

			var r = HexToR($(this).css('color'));
			var g = HexToG($(this).css('color'));
			var b = HexToB($(this).css('color'));
			
			colour = 'rgb(' + r + ', ' + g + ', ' + b + ')';

		
		} else {
		
			colour = $(this).css('color');
		
		}
	
	
		$(this).css({ 'backgroundImage' : 'url("/util/pngenius/pngenius.php?width=' + $(this).css('width') + '&height=' + $(this).css('height') + '&size=' + $(this).css('fontSize') + '&colour=' + colour + '&trans=' + $(this).css('textTransform') + '&text=' + escape($(this).text()) + '")' });


		var header = $(this);


		var dummyImage = document.createElement("img");

		dummyImage.onload = function()
		{
			newHeight = this.height;
			header.css({ 'height': newHeight + 'px'});
		};

		dummyImage.src = plainUrl($(this).css('backgroundImage'));
		
		

		
	});




}



