
$(document).ready(function() {


	flashReplace();
    correctHuntercombe();

	$('.title').corner("7px top");
	$('.subHeading').corner("7px top");
	$('.photoInner').corner("5px top");


	var nospam = $("#bodyWrap").html();
	clean = nospam.replace(/@NOSPAM/g, "@")
	//console.log(nospam);
	$("#bodyWrap").html(clean);

	//parent div, centre div
	centreGallery('galleryBlock', 'galleryBlockInner');	

	if(document.getElementById('quicklinkBut'))
		document.getElementById('quicklinkBut').style.display = 'none';

	pinballEffect();
	initPopUps();
	externalPDFlinks();

	var movie = 'uploads/animated_header.swf';



	$(function() {
		// Use this example, or...
		$('a[@rel*=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel
		// This, or...
// 		$('#gallery a').lightBox(); // Select all links in object with gallery ID
		// This, or...
		$('a.lightbox').lightBox(); // Select all links with lightbox class
		// This, or...
// 		$('a').lightBox(); // Select all links in the page
		// ... The possibility are many. Use your creative or choose one in the examples above
	});


});


function centreGallery(parentDiv, centreDiv) {

	if(!document.getElementById(parentDiv))
		return;

	var par = document.getElementById(parentDiv);
	var parW = par.offsetWidth;
	var cen = document.getElementById(centreDiv);
	var cenW = cen.offsetWidth;

	var marg = parW - cenW;
	offSet = (marg / 2);
	if($.browser.version == '6.0' && $.browser.msie) {
		offSet = offSet / 2;
	}

		cen.style.marginLeft = offSet+"px";

}



function showWidth(ele, w) {
	$("div").text("The width for the " + ele + " is " + w + "px.");
}


function externalPDFlinks() {

	var theLinks = document.links;

	if (!document.links)
		{
		document.links = document.getElementsByTagName('a');
		}


	var thisDomain = window.location.hostname;


	for (i=0; i < theLinks.length; i++) {
		var thisLink = theLinks[i];
		  if (thisLink.href.indexOf(thisDomain) == -1 && thisLink.href.indexOf("javascript") == -1) {
    			thisLink.target = "_blank";
   			}
		else if (thisLink.href.indexOf('.pdf') !== -1){
    			thisLink.target = "_blank";
		}
  	}

}

function flashReplace() {
	if(!document.getElementById('flashSrc'))
		return;

	var movie = document.getElementById('flashSrc').innerHTML;

	var v_flash = flashDetect();

	if(!v_flash) 
		return;
	

	var flash = '<object type="application/x-shockwave-flash" data="'+movie+'" width="413" height="100">';
	 flash = flash + '<param name="movie" value="'+movie+'" />';
	 flash = flash +'<param name="wmode" value="transparent" />';
	 flash = flash +'<param name="autoStart" value="-1"></object>';

	var flash = '<object width="413" height="100">';
	 flash = flash + '<param name="movie" value="'+movie+'">';
	 flash = flash + '<embed src="'+movie+'" width="413" height="100">';
	 flash = flash + '</embed>';
	 flash = flash + '</object>';
 //	alert(flash);
	document.getElementById('flashContent').innerHTML = flash;







}

//		 Check if flash player is present / up-to-date
//
function flashDetect() {
  var flashVersion = new Array();

  flashVersion["major"] = 0;
  flashVersion["build"] = 0;

  if (navigator.plugins && typeof navigator.plugins["Shockwave Flash"] == "object")
  {
    var description = navigator.plugins["Shockwave Flash"].description;

    if (description != null)
    {
      var versionString = description.replace(/^.*\s+(\S+\s+\S+$)/, "$1");

      flashVersion["major"] = parseInt(versionString.replace(/^(.*)\..*$/, "$1"));
      flashVersion["build"] = parseInt(versionString.replace(/^.*r(.*)$/, "$1"));
    }
  }
  else if (typeof window.ActiveXObject != "undefined")
  {
    try
    {
      var flashObject = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
      var description = flashObject.GetVariable("$version");

      if (description != null)
      {
        var versionNumbers = description.replace(/^\S+\s+(.*)$/, "$1").split(",");

        flashVersion["major"] = parseInt(versionNumbers[0]);
        flashVersion["build"] = parseInt(versionNumbers[2]);
      }
    }
    catch(error)
    {
    }
  }


  if (flashVersion["major"] > 6) {
	return true;
  }
  else {
	return false;
  }

}
