// JavaScript Document
function ie6() {
	var IE6 = (navigator.userAgent.indexOf("MSIE 6")>=0) ? true : false;
	if(IE6) {
	  //$("#subnavBg").css("background", "#000000");
	  //$("#overlay").css("background", "#000000");
  	  //$("#overlay").css("width", "1000px");
	  $("#newsContent").css("display", "none")
	  $("#nav-shadow").css("z-index", "1");
   }
}
/***** EASING *****/

jQuery.easing.jswing=jQuery.easing.swing;jQuery.extend(jQuery.easing,{def:"easeInOutQuad",swing:function(e,f,a,h,g){return jQuery.easing[jQuery.easing.def](e,f,a,h,g)},easeInQuad:function(e,f,a,h,g){return h*(f/=g)*f+a},easeOutQuad:function(e,f,a,h,g){return -h*(f/=g)*(f-2)+a},easeInOutQuad:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f+a}return -h/2*((--f)*(f-2)-1)+a},easeInQuint:function(e,f,a,h,g){return h*(f/=g)*f*f*f*f+a},easeOutQuint:function(e,f,a,h,g){return h*((f=f/g-1)*f*f*f*f+1)+a},easeInOutQuint:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f*f*f*f+a}return h/2*((f-=2)*f*f*f*f+2)+a},easeInExpo:function(e,f,a,h,g){return(f===0)?a:h*Math.pow(2,10*(f/g-1))+a},easeOutExpo:function(e,f,a,h,g){return(f==g)?a+h:h*(-Math.pow(2,-10*f/g)+1)+a},easeInOutExpo:function(e,f,a,h,g){if(f===0){return a}if(f==g){return a+h}if((f/=g/2)<1){return h/2*Math.pow(2,10*(f-1))+a}return h/2*(-Math.pow(2,-10*--f)+2)+a},easeInRegular:function(e,f,a,h,g){return h*(f/=g)*f+a},easeOutRegular:function(e,f,a,h,g){return -h*(f/=g)*(f-2)+a},easeInOutRegular:function(e,f,a,h,g){if((f/=g/2)<1){return h/2*f*f+a}return -h/2*((--f)*(f-2)-1)+a}});


/*
 * Pixastic - JavaScript Image Processing Library
 * Copyright (c) 2008 Jacob Seidelin, jseidelin@nihilogic.dk, http://blog.nihilogic.dk/
 * MIT License [http://www.pixastic.com/lib/license.txt]
 */
var Pixastic=(function(){function d(m,n,l){if(m.addEventListener){m.addEventListener(n,l,false)}else{if(m.attachEvent){m.attachEvent("on"+n,l)}}}function g(n){var l=false;var o=function(){if(!l){l=true;n()}};document.write('<script defer src="//:" id="__onload_ie_pixastic__"><\/script>');var m=document.getElementById("__onload_ie_pixastic__");m.onreadystatechange=function(){if(m.readyState=="complete"){m.parentNode.removeChild(m);o()}};if(document.addEventListener){document.addEventListener("DOMContentLoaded",o,false)}d(window,"load",o)}function k(){var l=c("pixastic",null,"img");var o=c("pixastic",null,"canvas");var n=l.concat(o);for(var m=0;m<n.length;m++){(function(){var q=n[m];var s=[];var r=q.className.split(" ");for(var v=0;v<r.length;v++){var x=r[v];if(x.substring(0,9)=="pixastic-"){var u=x.substring(9);if(u!=""){s.push(u)}}}if(s.length){if(q.tagName.toLowerCase()=="img"){var p=new Image();p.src=q.src;if(p.complete){for(var w=0;w<s.length;w++){var t=Pixastic.applyAction(q,q,s[w],null);if(t){q=t}}}else{p.onload=function(){for(var y=0;y<s.length;y++){var z=Pixastic.applyAction(q,q,s[y],null);if(z){q=z}}}}}else{setTimeout(function(){for(var y=0;y<s.length;y++){var z=Pixastic.applyAction(q,q,s[y],null);if(z){q=z}}},1)}}})()}}if(typeof pixastic_parseonload!="undefined"&&pixastic_parseonload){g(k)}function c(r,p,l){var o=new Array();if(p==null){p=document}if(l==null){l="*"}var n=p.getElementsByTagName(l);var m=n.length;var q=new RegExp("(^|\\s)"+r+"(\\s|$)");for(i=0,j=0;i<m;i++){if(q.test(n[i].className)){o[j]=n[i];j++}}return o}var e;function a(m,n){if(!Pixastic.debug){return}try{switch(n){case"warn":console.warn("Pixastic:",m);break;case"error":console.error("Pixastic:",m);break;default:console.log("Pixastic:",m)}}catch(l){}if(!e){}}var b=(function(){var n=document.createElement("canvas");var m=false;try{m=!!((typeof n.getContext=="function")&&n.getContext("2d"))}catch(l){}return function(){return m}})();var f=(function(){var o=document.createElement("canvas");var n=false;var l;try{if(typeof o.getContext=="function"&&(l=o.getContext("2d"))){n=(typeof l.getImageData=="function")}}catch(m){}return function(){return n}})();var h=(function(){var n=false;var p=document.createElement("canvas");if(b()&&f()){p.width=p.height=1;var o=p.getContext("2d");o.fillStyle="rgb(255,0,0)";o.fillRect(0,0,1,1);var l=document.createElement("canvas");l.width=l.height=1;var q=l.getContext("2d");q.fillStyle="rgb(0,0,255)";q.fillRect(0,0,1,1);o.globalAlpha=0.5;o.drawImage(l,0,0);var m=o.getImageData(0,0,1,1).data;n=(m[2]!=255)}return function(){return n}})();return{parseOnLoad:false,debug:false,applyAction:function(E,p,o,n){n=n||{};var r=(E.tagName.toLowerCase()=="canvas");if(r&&Pixastic.Client.isIE()){if(Pixastic.debug){a("Tried to process a canvas element but browser is IE.")}return false}var m,v;var u=false;if(Pixastic.Client.hasCanvas()){u=!!n.resultCanvas;m=n.resultCanvas||document.createElement("canvas");v=m.getContext("2d")}var t=E.offsetWidth;var x=E.offsetHeight;if(r){t=E.width;x=E.height}if(t==0||x==0){if(E.parentNode==null){var s=E.style.position;var C=E.style.left;E.style.position="absolute";E.style.left="-9999px";document.body.appendChild(E);t=E.offsetWidth;x=E.offsetHeight;document.body.removeChild(E);E.style.position=s;E.style.left=C}else{if(Pixastic.debug){a("Image has 0 width and/or height.")}return}}if(o.indexOf("(")>-1){var A=o;o=A.substr(0,A.indexOf("("));var q=A.match(/\((.*?)\)/);if(q[1]){q=q[1].split(";");for(var B=0;B<q.length;B++){thisArg=q[B].split("=");if(thisArg.length==2){if(thisArg[0]=="rect"){var l=thisArg[1].split(",");n[thisArg[0]]={left:parseInt(l[0],10)||0,top:parseInt(l[1],10)||0,width:parseInt(l[2],10)||0,height:parseInt(l[3],10)||0}}else{n[thisArg[0]]=thisArg[1]}}}}}if(!n.rect){n.rect={left:0,top:0,width:t,height:x}}else{n.rect.left=Math.round(n.rect.left);n.rect.top=Math.round(n.rect.top);n.rect.width=Math.round(n.rect.width);n.rect.height=Math.round(n.rect.height)}var y=false;if(Pixastic.Actions[o]&&typeof Pixastic.Actions[o].process=="function"){y=true}if(!y){if(Pixastic.debug){a('Invalid action "'+o+'". Maybe file not included?')}return false}if(!Pixastic.Actions[o].checkSupport()){if(Pixastic.debug){a('Action "'+o+'" not supported by this browser.')}return false}if(Pixastic.Client.hasCanvas()){if(m!==E){m.width=t;m.height=x}if(!u){m.style.width=t+"px";m.style.height=x+"px"}v.drawImage(p,0,0,t,x);if(!E.__pixastic_org_image){m.__pixastic_org_image=E;m.__pixastic_org_width=t;m.__pixastic_org_height=x}else{m.__pixastic_org_image=E.__pixastic_org_image;m.__pixastic_org_width=E.__pixastic_org_width;m.__pixastic_org_height=E.__pixastic_org_height}}else{if(Pixastic.Client.isIE()&&typeof E.__pixastic_org_style=="undefined"){E.__pixastic_org_style=E.style.cssText}}var z={image:E,canvas:m,width:t,height:x,useData:true,options:n};var D=Pixastic.Actions[o].process(z);if(!D){return false}if(Pixastic.Client.hasCanvas()){if(z.useData){if(Pixastic.Client.hasCanvasImageData()){m.getContext("2d").putImageData(z.canvasData,n.rect.left,n.rect.top);m.getContext("2d").fillRect(0,0,0,0)}}if(!n.leaveDOM){m.title=E.title;m.imgsrc=E.imgsrc;if(!r){m.alt=E.alt}if(!r){m.imgsrc=E.src}m.className=E.className;m.style.cssText=E.style.cssText;m.name=E.name;m.tabIndex=E.tabIndex;m.id=E.id;if(E.parentNode&&E.parentNode.replaceChild){E.parentNode.replaceChild(m,E)}}n.resultCanvas=m;return m}return E},prepareData:function(q,m){var l=q.canvas.getContext("2d");var o=q.options.rect;var n=l.getImageData(o.left,o.top,o.width,o.height);var p=n.data;if(!m){q.canvasData=n}return p},process:function(m,l,n,q){if(m.tagName.toLowerCase()=="img"){var p=new Image();p.src=m.src;if(p.complete){var o=Pixastic.applyAction(m,p,l,n);if(q){q(o)}return o}else{p.onload=function(){var r=Pixastic.applyAction(m,p,l,n);if(q){q(r)}}}}if(m.tagName.toLowerCase()=="canvas"){var o=Pixastic.applyAction(m,m,l,n);if(q){q(o)}return o}},revert:function(l){if(Pixastic.Client.hasCanvas()){if(l.tagName.toLowerCase()=="canvas"&&l.__pixastic_org_image){l.width=l.__pixastic_org_width;l.height=l.__pixastic_org_height;l.getContext("2d").drawImage(l.__pixastic_org_image,0,0);if(l.parentNode&&l.parentNode.replaceChild){l.parentNode.replaceChild(l.__pixastic_org_image,l)}return l}}else{if(Pixastic.Client.isIE()){if(typeof l.__pixastic_org_style!="undefined"){l.style.cssText=l.__pixastic_org_style}}}},Client:{hasCanvas:b,hasCanvasImageData:f,hasGlobalAlpha:h,isIE:function(){return !!document.all&&!!window.attachEvent&&!window.opera}},Actions:{}}})();Pixastic.Actions.desaturate={process:function(b){var c=!!(b.options.average&&b.options.average!="false");if(Pixastic.Client.hasCanvasImageData()){var d=Pixastic.prepareData(b);var l=b.options.rect;var m=l.width;var e=l.height;var a=m*e;var f=a*4,k,g;if(c){while(a--){d[f-=4]=d[k=f+1]=d[g=f+2]=(d[f]+d[k]+d[g])/3}}else{while(a--){d[f-=4]=d[k=f+1]=d[g=f+2]=(d[f]*0.3+d[k]*0.59+d[g]*0.11)}}return true}else{if(Pixastic.Client.isIE()){b.image.style.filter+=" gray";return true}}},checkSupport:function(){return(Pixastic.Client.hasCanvasImageData()||Pixastic.Client.isIE())}};

function hideUiTitlebar() {
	$(".ui-dialog-titlebar").hide();
}

function showUiTitlebar() {
	$(".ui-dialog-titlebar").show();
}

$( document ).ready( function() {

	var $button, $dialog;
	
	/*
	var $subnavBg 		= $('#subnavBg');

	$('#mainNav > ul > li' ).each( function ( i, el ) {
	
		var $menu 		= $( el );
		var $subMenu	= $menu.children().filter( 'ul.subnav' );
		
		if ( $subMenu.length > 0 ) {
			
			
			
			$menu.hover( function() {
				var offset = -( $subnavBg.height() - $subMenu.height() - 72 );
				//var offset = -250;
				$subnavBg.stop(false,true).css({
					'margin-top': offset + 'px'
				}).slideDown(500);
				$subMenu.slideDown(750);
				
			}, function () {
				$subMenu.stop(false,true).slideUp(250);
				$subnavBg.stop(false,true).slideUp(250);
				
			});
		}
	});
	
	*/
	
	
	/**********************************************
	*  Code for the right-nav
	**********************************************/
	
	if ( $.fn.dialog ) {
	
		/**********************************************
		*  Enquiry form
		**********************************************/
	
		$enquiryButton = $( '#btn-open-booking-enquiry' );
		$enquiryDialog = $( '#dlg-booking-enquiry' );

		if ( ( $enquiryButton.length > 0 ) && ( $enquiryDialog.length > 0 ) ) {
		
			$enquiryDialog.dialog({
				'autoOpen': false,
				'modal': true,
				'resizable': false,
				'width': 600
			});
			
			//$enquiryDialog.find( 'form fieldset div:odd' ).css( 'clear', 'left' );
		
			//  Open button
			$enquiryButton.click( function( ev ) {

				ev.preventDefault();
				//  hideUiTitlebar();
				$enquiryDialog.dialog( 'open' );
		
			});
			
		}
		/**********************************************
		*  Brochure form or similar
		**********************************************/
	
		$brochureButton = $( '#btn-open-brochure-download' );
		$brochureDialog = $( '#popout-download-brochure' );

		if ( ( $brochureButton.length > 0 ) && ( $brochureDialog.length > 0 ) ) {
		
			$brochureDialog.dialog({
				'autoOpen': false,
				'modal': true,
				'resizable': false,
				'width': 600
			});
			
			$brochureDialog.find( 'form fieldset div:odd' ).css( 'clear', 'left' );
		
			//  Open button
			$brochureButton.click( function( ev ) {

				ev.preventDefault();
				//  hideUiTitlebar();
				$brochureDialog.dialog( 'open' );
		
			});
			
		}
		
		
		/**********************************************
		*  Call me back
		**********************************************/
	
		$button = $( '#btn-open-call-me-back' );
		$dialog = $( '#popout-call-me-back' );
		
		if ( ( $button.length > 0 ) && ( $dialog.length > 0 ) ) {
		
			//  Open button
			$button.click( function( ev ) {
			
				ev.preventDefault();
				
				$dialog.show();
				
				var regexp = /^\d+/
				var offset = parseInt( regexp.exec( $('#rightColumn').css('margin-top') )[0] );
				
				$button.parent().prevAll().each( function( i, el ) {
					$link = $( el );
					offset += parseInt( $link.height() ) + parseInt( regexp.exec( $link.css('margin-bottom') )[0] );
				});
				
				$dialog.css({
					'top': offset + 'px',
					'right': 0
				});
			
			});
			
			
			//  Close button
			$( '#btn-close-call-me-back' ).click( function( ev ) {
				ev.preventDefault();
				$dialog.hide();
			});
			
			
			//  Date picker
			$( '#cmb-date' ).datepicker({
				'buttonImage': '/static/images/conference/datepicker-calendar.png',
				'minDate': 0,
				'showOn': 'button'
			});
		
		}
		
	}
	
	
	/**********************************************
	*  Form elements
	**********************************************/
	
	if ( $.fn.dropkick ) {
		$( 'select.pseudo-select' ).dropkick();
	}
	
});

function greyScale(){
	
	$('.greyScale').each(function(){
		
		var $this = $(this);
		
		var img = new Image();
		img.onload = function() {
			Pixastic.process(img, "desaturate", {average : false});
			$this.find('.colour').not($('.slider .colour:eq(1), .quoteList .colour:eq(0)')).stop().fadeTo(500,0);
		}
		$(img).insertAfter($this.find('img:first'));
		$this.find('> *:first').addClass('colour');
		img.src = $this.find('img:first').attr('src');
	});
	$('.greyScale').not('.offset .greyScale, .quoteTop .greyScale').hover(function(){
		$(this).find('> *:first').stop().fadeTo(500,1);
	},function(){
		$(this).find('> *:first').stop().fadeTo(500,0);
	});
}

function removeLast(){
        $('#mainNav li:first').css("border-left","0");
}

function removescroll(){
	$('#viewport').css("overflow","hidden");
}

function homeback() {
	 $('.slideshow').cycle({
		fx: 'fade', 
		speed:    1000, 
    	timeout:  4500,
		fit: 0
	});
}
function topNav(){
	$('#mainNav > ul > li > a').css('padding-left', '0').css('padding-right', '0');
	var remainingWidth = 946 - $('#mainNav > ul').outerWidth();
	var navTotal = $('#mainNav > ul > li > a').size();
	var newPadding = Math.floor((remainingWidth/navTotal)/2);
	//$('#mainNav a').css('padding-left', newPadding).css('padding-right', newPadding);
	//remainingWidth = 946 - $('#mainNav > ul').outerWidth();
	//var leftOver = Math.floor(remainingWidth/2);
	//$('#mainNav > ul > li > a:first').css('padding-left', newPadding + leftOver);
	//$('#mainNav > ul > li > a:last').css('padding-right', newPadding + leftOver);
	$('#mainNav > ul > li').hover(function(){
		if($(this).find('ul > li').size() > 0){
			$(this).addClass('over').find('> ul').show();
			var navHeight = $(this).find('ul').outerHeight() + 32;
			$('#subnavBg').stop().animate({
				height: navHeight
			}, 100, "easeOutQuint");
			}
	},function(){
		if($(this).find('ul > li').size() > 0){
			$(this).removeClass('over').find('> ul').hide();
			$('#subnavBg').stop().animate({
				height: 0
			}, 100, "easeOutQuint", function(){
				$('#subnavBg').removeClass('over');
			});
		}
	});
}

function hideem() {
	$('#bighall-1').css('display', 'none');
	$('#bighall-2').css('display', 'none');
	$('#bighall-3').css('display', 'none');
	$('#bighall-4').css('display', 'none');
	$('#bighall-5').css('display', 'none');
	$('#bighall-6').css('display', 'none');
	$('#bighall-7').css('display', 'none');
	$('#bighall-8').css('display', 'none');
	$('#bighall-9').css('display', 'none');
	$('#myBox1').css('display', 'none');
	$('#myBox2').css('display', 'none');
	$('#myBox3').css('display', 'none');
	$('#myBox4').css('display', 'none');
	$('#myBox5').css('display', 'none');
	$('#myBox6').css('display', 'none');
	$('#myBox7').css('display', 'none');
	$('#myBox8').css('display', 'none');
	$('#myBox9').css('display', 'none');	
	$('#bighall-details-wrap .lightBox').css('display', 'inline');		
}

function bighall() {
	$('div').removeClass('full');
	$('#bighallselecta').css('display', 'inline');
	hideem();
	$( "div" ).removeClass("full");
	$('#bighallselecta').change(function() {
	  if ($(this).val() == 'GH1') { 
	  	hideem();
		 $('#bighall-1').css('display', 'inline');
	  }
	  if ($(this).val() == 'GH2') { 
	  	hideem();
		 $('#bighall-2').css('display', 'inline');
	  }
	   if ($(this).val() == 'GH3') { 
	  	hideem();
		 $('#bighall-3').css('display', 'inline');
	  }
	   if ($(this).val() == 'GH4') { 
	  	hideem();
		 $('#bighall-4').css('display', 'inline');
	  }
	   if ($(this).val() == 'GH5') { 
	  	hideem();
		 $('#bighall-5').css('display', 'inline');
	  }
	   if ($(this).val() == 'GH6') { 
	  	hideem();
		 $('#bighall-6').css('display', 'inline');
	  }
	   if ($(this).val() == 'GH7') { 
	  	hideem();
		 $('#bighall-7').css('display', 'inline');
	  }
	   if ($(this).val() == 'GH8') { 
	  	hideem();
		 $('#bighall-8').css('display', 'inline');
	  }
	   if ($(this).val() == 'GH9') { 
	  	hideem();
		 $('#bighall-9').css('display', 'inline');
	  }
	});
}

function commingsoon() {
	$("#askteambutton").click(function() {
	  $("#ask-team-wrap").stop().animate({width: "200px"}, 1000, function(){
		  setTimeout('commingsoonclose()',3000);
	});
	});
}
function commingsoonclose() {
	  $("#ask-team-wrap").stop().animate({width: "0px"}, 1000);
}

// template amimation 

function makesmallcookie() {
	$.cookie('section', 'small', { expires: 2, path: '/', domain: 'www.priestfield.com' });
}
function makemediumcookie() {
	$.cookie('section', 'medium', { expires: 2, path: '/', domain: 'www.priestfield.com' });
}
function makelargecookie() {
	$.cookie('section', 'large', { expires: 2, path: '/', domain: 'www.priestfield.com' });
}
function hidemaincontentsmall() {
	$('#overlaycontent').fadeTo(0,1);
	$('#overlaycontent').animate({marginLeft: "-767px"},0);
}
function hidemaincontentmedium() {
	$('#overlaycontent').fadeTo(0,1);
	$('#overlaycontent').animate({marginLeft: "-403px"},0);
}
function hidemaincontentlarge() {
	$('#overlaycontent').fadeTo(0,1);
	$('#overlaycontent').animate({marginLeft: "0px"},0);
}
function finnishanddisplaymedium() {	
	setTimeout('slideemovermedium()',500);
	setTimeout('mainContent()',1800);
}
function finnishanddisplaylarge() {	
	setTimeout('slideemoverlarge()',500);
	setTimeout('mainContent()',1800);
}
function slideemoversmall() {
	$('#overlaycontent').animate({marginLeft: "-767px"},{queue:false, duration:1200, easing: "easeInOutQuint"});
}
function slideemovermedium() {
	$('#overlaycontent').animate({marginLeft: "-403px"},{queue:false, duration:1200, easing: "easeInOutQuint"});
}
function slideemoverlarge() {
	$('#overlaycontent').animate({marginLeft: "0px"},{queue:false, duration:1200, easing: "easeInOutQuint"});
}
function mainContent() {
	$("#mainContent").animate({opacity: 1.0},{queue:false, duration:1500, easing: "easeOutSine"}, function(){$('*[filter]').removeAttr('filter')});
}
runone = function() {
	$('#mainContent').fadeTo(0,0);
}
runtwo = function() {
	$('#overlaycontent').fadeTo(0,0);
}
// Meet team Hover show
abouthover = function()  {
	
	/*$('.anotherone').mouseover(function() {
		
		divToSlide = $(this).parent().find('.notstrong');
		divToSlide.css({display: "inline"});
		divToSlide.css({opacity: "1"});
		divToSlide.stop().animate({marginTop: -100}, 1000, function(){
			
			divToSlide.stop().animate({marginTop: 0}, 1000);
			$('.notstrong').mouseout(function() {
				
				divToSlide = $(this).parent().find('.notstrong');
				divToSlide.stop().animate({marginTop: 0});
				
				});	
			});
		});	*/
		
$('.dept-team-member').mouseenter(function(){
    $(this).children(".notstrong").css({opacity: "1"});
	 $(this).children(".notstrong").css({display: "inline"});
	 $(this).children(".notstrong").stop().animate({marginTop: -100}, 1000);
	
}).mouseleave(function(){
    $(this).children(".notstrong").stop().animate({marginTop: 0}, 1000);
});
		


}


$(function(){
	greyScale();
	removeLast();
	removescroll();
	topNav();
	commingsoon();
	ie6();
});

