  var currPage = window.location.pathname;
  var prevPage = '';

  $.ajaxSetup ({ cache: false });

  $('<img />')
  .attr('src', 'images/alt-bg.jpg');

  function changePage(newPage) {
    prevPage = currPage;

    if($.browser.msie) $.fx.off;

    if(currPage != newPage) {
      document.title = document.title = newPage.replace(/-/g, ' ').replace(/\b[a-z]/g,function($0){ return $0.toUpperCase(); });
      $('.main').stop(true, true).fadeOut('400', function() {
        $.get('/'+newPage+'/', { json: true }, function(data) {
          var data = data;

          $('.main').html(data).fadeIn();

          updateBG(newPage);
          encodeFlash();

        });
      });

      currPage = newPage;
       //
      //document.title = page.replace(/-/g, ' ').replace(/\b[a-z]/g,function($0){ return $0.toUpperCase(); });
    }

  }

  function highlight(obj) {
    $('#highlight').remove();
    obj.append('<div id="highlight"></div>');
  }

  function capitalize(incomingString) {
  	var letter = incomingString.substr(0,1);

  	var str = incomingString.toLowerCase();

  	return letter.toUpperCase() + str.substr(1);
  }

  function updateBG(p) {
    switch(p) {
      case 'www.digitellinc.com':
      case 'live-broadcasting':
      case 'webinar-services':
      case 'conference-services':
      case 'virtual-worlds':
      case 'digitell-difference':
      case 'schedule-demo':
      case 'toolkit':
        $('.main').css({ 'background-color': 'transparent' });
        bg = 'bg.jpg';
      break;
      case 'live-broadcasting-more':
        $('.main').css({ 'background-color': '#fff' });

        bg = 'alt-bg.jpg';    
      break;
      default:
        $('.main').css({ 'background-color': '#e9e9e9' });

        bg = 'alt-bg.jpg';
      break;
    }
    bg = 'bg.jpg';

    $('body').css('backgroundImage', 'url(/images/'+bg+')' );
  }

  $.fn.smartBackgroundImage = function(url) {
    var t = this;

    //create an img so the browser will download the image:
    $('<img />')
    .attr('src', url)
    .load(function() { //attach onload to set background-image
      t.each(function() {
        $(this).css('backgroundImage', 'url('+url+')' );
      });
    });

    return this;
 }
  /*
  $('a').live('click', function(event) {
    event.preventDefault();
    changePage($(this).attr('href'));
  });
  */

  $(window).bind('hashchange', function(e) {
    e.stopPropagation();
    e.preventDefault();

    changePage(location.hash.replace( /#/, ""));
  });

  $(document).ready(function() {
    if(location.hash) $(window).trigger( 'hashchange' );

    var splittedURL = window.location.href.split(/\/+/g);
    var path = splittedURL[splittedURL.length-2];

    updateBG(path);
    encodeFlash();    
    //location.hash = 'live-broadcasting';
  });






