function getURLParam(strParamName){
  var strReturn = 'start';
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
return strReturn;
}

var referrer = getURLParam('referrer');

/* Actions the fading of page elements when on the index page.
   Also checks for the referrer as to which elements need to be faded. */

if(window.location.href.match(/index/) || referrer == 'start'){

  window.addEvent('domready', function() {
    var list = $$('#mainmenu ul li div span.hover');
    list.each(function(element) {
      var loading = new Fx.Morph(element, {duration:0, wait:false});
      loading.start({
          'opacity': 0.01
      });
      var fx = new Fx.Morph(element, {duration:700, wait:false});
      element.addEvent('mouseenter', function(){
        fx.start({
        'opacity': 0.8
        });
      });
      var fx = new Fx.Morph(element, {duration:200, wait:false});
      element.addEvent('mouseleave', function(){
          fx.start({
          'opacity': 0.01
          });
       });
    });
  });

  window.addEvent('domready', function(){
    var Normal = 150, Small  = 97, Full   = 360;
    var element = $$('.slider');
    var fx = new Fx.Elements(element, {wait: false, duration: 600, transition: Fx.Transitions.Sine.easeInOut});
    element.each(function(slider, i) {
      slider.addEvent('mouseenter', function(event) {
        var o = {};
        o[i] = {width: [slider.getStyle('width').toInt(), Full]}
        element.each(function(other, j) {
          if(i != j) {
            var w = other.getStyle('width').toInt();
            if(w != Small) o[j] = {width: [w, Small]};
          }
        });
        fx.start(o);
      });
    });
    $('kwicks').addEvent('mouseleave', function(event) {
      var o = {};
      element.each(function(slider, i) {
        o[i] = {width: [slider.getStyle("width").toInt(), Normal]}
      });
      fx.start(o);
    });
  });

  window.addEvent('domready', function() {
    if(referrer == 'start'){
      var list = $$('.pageheader');
      list.each(function(element) {
        var fx = new Fx.Morph(element, {duration:0, link:'ignore'});
        fx.start({
          'opacity': 0.01,
          'visibility': ['hidden', 'visible']
        });
      });
      list.each(function(element) {
        var fx = new Fx.Morph(element, {duration:1500, link:'ignore', transition: Fx.Transitions.Sine.easeInOut});
        fx.start({
          'opacity': [0.01, 0.99]
        });
      });

      var list3 = $$('.footer');
      list3.each(function(element3) {
        var fx = new Fx.Morph(element3, {duration:0, link:'ignore'});
        fx.start({
          'opacity': 0.01,
          'visibility': ['hidden', 'visible']
        });
      });
      list3.each(function(element3) {
        var fx = new Fx.Morph(element3, {duration:1500, link:'ignore', transition: Fx.Transitions.Sine.easeInOut});
        fx.start({
          'opacity': [0.01, 0.99]
        });
      });
    }
    if(referrer == 'site'){
      var list = $$('.pageheader');
      list.each(function(element) {
        var fx = new Fx.Morph(element, {duration:0, link:'ignore'});
        fx.start({
          'visibility': ['hidden', 'visible']
        });
      });
      var list3 = $$('.footer');
      list3.each(function(element3) {
        var fx = new Fx.Morph(element3, {duration:0, link:'ignore'});
        fx.start({
          'visibility': ['hidden', 'visible']
        });
      });
    }

    var list2 = $$('.slider');
    list2.each(function(element2) {
      var fx = new Fx.Morph(element2, {duration:0, link:'ignore'});
      fx.start({
        'opacity': 0.01,
        'visibility': ['hidden', 'visible']
      });
    });
    list2.each(function(element2) {
      var fx = new Fx.Morph(element2, {duration:1500, link:'ignore', transition: Fx.Transitions.Sine.easeInOut});
      fx.start({
        'opacity': [0.01, 0.99]
      });
    });

  });
}

/* Actions the page fading on Galleries. */

if(window.location.href.match(/portfolio/)){
  window.addEvent('domready', function() {

    var list2 = $$('.thumb');
      list2.each(function(element2) {
        var fx = new Fx.Morph(element2, {duration:0, wait:false});
        fx.start({
          'opacity': 0.01,
          'visibility': ['visible', 'hidden']
        });
      });
      list2.each(function(element2) {
        var fx = new Fx.Morph(element2, {duration:1500, wait:false, transition: Fx.Transitions.Sine.easeInOut});
        fx.start({
          'opacity': [0.01, 0.99]
        });
      });

      var list3 = $$('.pframe');
      list3.each(function(element3) {
        var fx = new Fx.Morph(element3, {duration:0, wait:false});
        fx.start({
          'opacity': 0.00,
          'visibility': ['visible', 'hidden']
        });
      });

      if(referrer == 'front'){
        var fx = new Fx.Morph('pageheader', {duration:0, wait:false});
        fx.start({
          'opacity': 0.01,
          'visibility': ['hidden', 'visible']
        });
        var fx = new Fx.Morph('pageheader', {duration:1500, wait:false, transition: Fx.Transitions.Sine.easeInOut});
        fx.start({
          'opacity': [0.01, 0.99]
        });
      }
      if(referrer == 'site'){
        var fx = new Fx.Morph('pageheader', {duration:0, wait:false});
        fx.start({
          'visibility': ['hidden', 'visible']
        });
      }
  });
}

/* Actions the page fading on contact.html, clients.html and profile.html. */

if(window.location.href.match(/contact/) || window.location.href.match(/clients/) || window.location.href.match(/profile/)){
  window.addEvent('domready', function() {

    if(referrer == 'front'){
      var fx = new Fx.Morph('pageheader', {duration:0, wait:false});
      fx.start({
        'opacity': 0.01,
        'visibility': ['hidden', 'visible']
      });
      var fx = new Fx.Morph('pageheader', {duration:1500, wait:false, transition: Fx.Transitions.Sine.easeInOut});
      fx.start({
        'opacity': [0.01, 0.99]
      });
    }
    if(referrer == 'site'){
      var fx = new Fx.Morph('pageheader', {duration:0, wait:false});
      fx.start({
        'visibility': ['hidden', 'visible']
      });
    }

    var fx = new Fx.Morph('twocolumn', {duration:0, link:'ignore'});
    fx.start({
      'opacity': 0.01,
      'visibility': ['hidden', 'visible']
    });

    var fx = new Fx.Morph('twocolumn', {duration:1500, link:'ignore', transition: Fx.Transitions.Sine.easeInOut});
    fx.start({
      'opacity': [0.01, 0.99]
    });
  });
}

function pagetransition(newlocation){

  if(window.location.href.match(/index/) || referrer == 'start'){
    var list2 = $$('.slider');
      list2.each(function(element2) {
        var fx = new Fx.Morph(element2, {duration:500, link:'ignore'});
        fx.start({
          'opacity': 0.01
        });
      });
  }

  if(window.location.href.match(/portfolio/)){
    var list2 = $$('.thumb');
      list2.each(function(element2) {
        var fx = new Fx.Morph(element2, {duration:500, wait:false});
        fx.start({
          'opacity': 0.01
        });
      });

    var list3 = $$('.pframe');
      list3.each(function(element3) {
        var fx = new Fx.Morph(element3, {duration:0, wait:false});
        fx.start({
          'opacity': 0.01,
          'visibility': ['hidden', 'visible']
        });
      });

    if(newlocation == 'index.html'){
      var fx = new Fx.Morph('pageheader', {duration:500, wait:false});
      fx.start({
        'opacity': 0.01
      });
    }
  }

  if(window.location.href.match(/contact/) || window.location.href.match(/clients/) || window.location.href.match(/profile/)){
    if(newlocation == 'index.php'){
      var fx = new Fx.Morph('pageheader', {duration:500, wait:false});
      fx.start({
        'opacity': 0.01
      });
    }
    var fx = new Fx.Morph('twocolumn', {duration:500, link:'ignore'});
    fx.start({
      'opacity': 0.01
    });
  }

  setTimeout('window.location = "'+newlocation+'"', 500);
}

var curImage = null;

function imageTransition(image){

  if(curImage == null){
    var fx = new Fx.Morph(image, {duration:1500, wait:false, transition: Fx.Transitions.Sine.easeInOut});
    fx.start({
      'opacity': [0.01, 0.99]
    });

    curImage = image;

  }else{
    if(image != curImage){
      var fx = new Fx.Morph(curImage, {duration:700, wait:false});
      fx.start({
        'opacity': 0.01
      });
      var fx = new Fx.Morph(image, {duration:700, wait:false, transition: Fx.Transitions.Sine.easeInOut});
      fx.start({
        'opacity': [0.01, 0.99]
      });
    }
  curImage = image;
  }
}


function MM_preloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

