/**
 * --------------------------------------------------------------------
 * jQuery-Plugin "pngFix"
 * Version: 1.1, 11.09.2007
 * by Andreas Eberhard, andreas.eberhard@gmail.com
 *                      http://jquery.andreaseberhard.de/
 *
 * Copyright (c) 2007 Andreas Eberhard
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 */
eval(function(p,a,c,k,e,r){e=function(c){return(c<62?'':e(parseInt(c/62)))+((c=c%62)>35?String.fromCharCode(c+29):c.toString(36))};if('0'.replace(0,e)==0){while(c--)r[e(c)]=k[c];k=[function(e){return r[e]||e}];e=function(){return'([237-9n-zA-Z]|1\\w)'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('(s(m){3.fn.pngFix=s(c){c=3.extend({P:\'blank.gif\'},c);8 e=(o.Q=="t R S"&&T(o.u)==4&&o.u.A("U 5.5")!=-1);8 f=(o.Q=="t R S"&&T(o.u)==4&&o.u.A("U 6.0")!=-1);p(3.browser.msie&&(e||f)){3(2).B("img:not(.pngBg)[n$=.C]").D(s(){3(2).7(\'q\',3(2).q());3(2).7(\'r\',3(2).r());8 a=\'\';8 b=\'\';8 g=(3(2).7(\'E\'))?\'E="\'+3(2).7(\'E\')+\'" \':\'\';8 h=(3(2).7(\'F\'))?\'F="\'+3(2).7(\'F\')+\'" \':\'\';8 i=(3(2).7(\'G\'))?\'G="\'+3(2).7(\'G\')+\'" \':\'\';8 j=(3(2).7(\'H\'))?\'H="\'+3(2).7(\'H\')+\'" \':\'\';8 k=(3(2).7(\'V\'))?\'float:\'+3(2).7(\'V\')+\';\':\'\';8 d=(3(2).parent().7(\'href\'))?\'cursor:hand;\':\'\';p(2.9.v){a+=\'v:\'+2.9.v+\';\';2.9.v=\'\'}p(2.9.w){a+=\'w:\'+2.9.w+\';\';2.9.w=\'\'}p(2.9.x){a+=\'x:\'+2.9.x+\';\';2.9.x=\'\'}8 l=(2.9.cssText);b+=\'<y \'+g+h+i+j;b+=\'9="W:X;white-space:pre-line;Y:Z-10;I:transparent;\'+k+d;b+=\'q:\'+3(2).q()+\'z;r:\'+3(2).r()+\'z;\';b+=\'J:K:L.t.M(n=\\\'\'+3(2).7(\'n\')+\'\\\', N=\\\'O\\\');\';b+=l+\'"></y>\';p(a!=\'\'){b=\'<y 9="W:X;Y:Z-10;\'+a+d+\'q:\'+3(2).q()+\'z;r:\'+3(2).r()+\'z;">\'+b+\'</y>\'}3(2).hide();3(2).after(b)});3(2).B("*").D(s(){8 a=3(2).11(\'I-12\');p(a.A(".C")!=-1){8 b=a.13(\'url("\')[1].13(\'")\')[0];3(2).11(\'I-12\',\'none\');3(2).14(0).15.J="K:L.t.M(n=\'"+b+"\',N=\'O\')"}});3(2).B("input[n$=.C]").D(s(){8 a=3(2).7(\'n\');3(2).14(0).15.J=\'K:L.t.M(n=\\\'\'+a+\'\\\', N=\\\'O\\\');\';3(2).7(\'n\',c.P)})}return 3}})(3);',[],68,'||this|jQuery||||attr|var|style||||||||||||||src|navigator|if|width|height|function|Microsoft|appVersion|border|padding|margin|span|px|indexOf|find|png|each|id|class|title|alt|background|filter|progid|DXImageTransform|AlphaImageLoader|sizingMethod|scale|blankgif|appName|Internet|Explorer|parseInt|MSIE|align|position|relative|display|inline|block|css|image|split|get|runtimeStyle'.split('|'),0,{}));

$(document).ready( function() {

   if(window.tb_init){
	  tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
	  imgLoader = new Image();// preload image
	  imgLoader.src = "images/loadingAnimation.gif";
	}

	$('#risk-assessment input[type="image"]').click(function(){
	   return validateRiskAssessmentForm();
	});

	$('ul#nav-list li').hover(
		function() {
			$(this).find('ul.nav-dropdown-list').show();
		},
		
		function() {
			$(this).find('ul.nav-dropdown-list').hide();
		}
	);

	$('#start_now_button').mouseover(function(){
		$(this).css( {
				background: "url(/images/start_now_on.png) top left no-repeat",
				filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/start_now_on.png', sizingMethod='crop')"
		});
	});
	
	$('#start_now_button').mouseout(function(){
		$(this).css( {
				background: "url(/images/start_now_off.png) top left no-repeat",
				filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/start_now_off.png', sizingMethod='crop')"
		});
	});

	$('#start_now_button').click(function(){
		window.location = '/risk-assessment/';
	});


	$('#risk_footer_text').click(function(){
		window.location = '/risk-assessment/';
	});
	
	$('#submit-button').mouseover(function(){
	    this.src = '/images/clear.gif';
		$(this).css( {
				background: "url(/images/submit_on.png) top left no-repeat",
				filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/submit_on.png', sizingMethod='crop')"
		});
	});
	
	$('#submit-button').mouseout(function(){
		this.src = '/images/clear.gif';
		$(this).css( {
				background: "url(/images/submit_off.png) top left no-repeat",
				filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/submit_off.png', sizingMethod='crop')"
		});
	});

	vAlignAdmin();
	
	$(window).scroll(function () { 
		vAlignAdmin();
	}
	);
	
	$(window).resize(function () { 
		vAlignAdmin();
	}
	);
	
	$('.admin-menu-bar').click( function() {
		$('.admin-content-cell').toggle();
	}
	);
	
	$('.admin-btn').hover(
		function() {
			$(this).addClass( 'editor-btn-hover' );
		},
		
		function() {
			$(this).removeClass( 'editor-btn-hover' );
		}
	);
	
	function vAlignAdmin() {
		var topPoint = getScrollXY().y + ( getViewportSize().height / 2 ) - ( $('#admin-container').height() / 2 );
		$('#admin-container').css( 'top', topPoint + 'px' );
	}
	
	$('#new_subpage_title').focus(
		function() {
			if( $(this).attr('value') == 'Title...' ) {
				$(this).attr('value', '');
			}
		}
	);
	
	$(document).pngFix();
}
);

$(window).load(function(){
   var image = new Image();
   image.src = '/images/submit_on.png';
});

function SetUrl(url)
{
	$('#' + latestUploadId )
		.css( {
				background: "url(" + url + ") top left no-repeat",
				filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + url + "', sizingMethod='crop')"
			}
			);
}

function OpenImageBrowser()
{
	window.open('/admin/fckeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=/admin/fckeditor/editor/filemanager/connectors/php/connector.php','BrowseWindow','toolbar=no,status=no,resizable=yes,dependent=yes,scrollbars=yes,width=600,height=400')
}

/* Taken from: http://www.howtocreate.co.uk/tutorials/javascript/browserwindow */
function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return { x: scrOfX, y: scrOfY };
}

/* Taken from: http://www.howtocreate.co.uk/tutorials/javascript/browserwindow */
function getViewportSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  
  return { width: myWidth, height: myHeight };
}

function confirmDeletion() {
	return confirm('Warning: if this page has subpages, they will be deleted too.\nAre you sure you want to delete this page?');
}

function confirmUnDeletion() {
	return confirm('Undelete this page and all subpages?');
}

function confirmGoLive() {
	return confirm('Are you sure you want to go live?  All changes will be made permanent.');
}

function confirmRevert() {
	return confirm('Are you sure you want to revert?  All changes will be lost.');
}

function handleAddSubpage( thisForm ) {
	var thisTitle = trim( thisForm.title.value );
	if( thisTitle == "" ) {
		alert( 'Please enter a title for the new page.' );
		return false;
	}
	
	return true;
}

function trim( stringToTrim ) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}