if (window.location.toString().indexOf('empirestaging') < 0) {
  try {
  var pageTracker = _gat._getTracker("UA-8356891-1");
  pageTracker._trackPageview();
  } catch(err) {}
}

// SWF Object
var flashvars = {};
	//flashvars.source_file = "/swf/techdemo.flv";
	var params = {};
	params.wmode = "transparent";
	params.allowfullscreen = "true";
	var attributes = {};
	attributes.id = "video_holder";
	swfobject.embedSWF("/swf/video.swf", "video_holder", "377", "335", "9.0.0", "/swf/expressInstall.swf", flashvars, params, attributes);

swfobject.registerObject("myFlashContent", "9.0.0", "/swf/expressInstall.swf");

$(document).ready(function() {
  
  // Home Page Pop Up
  $('#homepage_popup_link').click(function () {
    tb_show();
  });
    
  if (displayReferPopUp) {
    $('#homepage_popup_link').trigger('click');
  };
  
  $('#continue_button').click(function () {
    tb_remove();
    return false;
  });
  
	// Activate SuperFish with Supersubs
  $("ul.sf-menu").supersubs({ 
    minWidth:    12,
    maxWidth:    27,
    extraWidth:  1
  }).superfish({
    animation: {
      height: 'show',
		  opacity: 'show',
			marginTop:"-3.3em"
    },
    speed: 'fast',
    delay: 500,
		autoArrows: false,
		dropShadows: false,
    onHide: function(){
			$(this).css({marginTop:"3.3em"}, 500)
		} 
  });
	
  // Home Page News and Library Slider
  $("div#slider1").cycle({
	  fx:     'fade',
	  speed:  'fast',
	  timeout: 5000,
	  next:   '#news_next',
	  prev:   '#news_prev',
	  fx: 'fade' 
	});;
  $("div#slider2").cycle({
	  fx:     'fade',
	  speed:  'fast',
	  timeout: 5000,
	  next:   '#library_next',
	  prev:   '#library_prev',
	  fx: 'fade' 
	});;
  
  
	// Client Login Dialog
	$("#dialog").dialog({
    bgiframe: true,
    autoOpen: false,
		draggable: false,
		width: 193,
    height: 143,
		minWidth: 193,
		minHeight: 143,
		resizable: false,
    modal: true,
		hide: 'explode',
		show: 'drop',
		position: 'center',
		zIndex: 3999
  });
  // Open Dialog
  $('#client_login_link').click(function() {
    $('#dialog').dialog('open');
	  return false;
  })
  // Close Dialog and Login
  $('#client_login_button').click(function() {
    $('.ui-dialog').effect('shake',500);

	  return false;
  })
	// Clear text on Focus 
  $('.client_login_textbox').click(function(){
    $(this).val('');
  })
  
  
  /* Random Promo*/
  var totalNum = 4; // Total DIV's minus 1
  var rndNum = Math.floor(Math.random() * totalNum);
  var promo = '#promo_' + rndNum;
  $(promo).show();
  
  /* Content Switcher*/
  $('#main_starter').fadeIn(1000);
  
  $('#breadcrumb_wrapper a').click(function() {
    $('#breadcrumb_wrapper a').removeClass();
    $(this).addClass('active');
    var panel_link = $(this).attr("href");
    $('.content_panel').fadeOut(1000).hide();
    $(panel_link).fadeIn(1000);
    return false;
  });
  
  /* Project Thumb Roll Over */
  $('.project_thumb').hover(
    function () {
      $('img', this).hide();
      $('div', this).show();
			$(this).addClass('project_thumb_hover');
    }, 
    function () {
      $('img', this).show();
      $('div', this).hide();
			$(this).removeClass('project_thumb_hover');
    }
  );
  
  /* Light Box */
  $('.photo_item a').lightBox();
  
  /* Thickbox image viewer */
  $('div.project_content div.cycle').cycle({
	  fx:     'fade',
	  speed:  'fast',
	  timeout: 5000,
	  next:   '.next2',
	  prev:   '.prev2'
	});
  /* Thickbox image viewer */
  $('div.project_content div.rich').cycle({
	  fx:     'fade',
	  speed:  'fast',
	  timeout: 12000,
	  next:   '.next2',
	  prev:   '.prev2'
	});

	/* Previous / Next Project */
	var currentProject = '';
	var currentProjectId = '';
	var prevProject = '';
	var nextProject = '';
	
	$('a.thickbox').click(function() {
	  currentProject = $(this);
	  $(this).runScript(currentProject);
	});
	
	$.fn.runScript = function(cp) {

	  currentProject = cp;

	  var currentProjectHref = currentProject.attr('href');

	  var underscoreindex = currentProjectHref.lastIndexOf("_");
	  currentProjectId = currentProjectHref.substring(underscoreindex + 1, currentProjectHref.length);
	  
	  prevProject = currentProject.prev();
	  var prevProjectLink = prevProject.attr('href');
	  
	  nextProject = currentProject.next();
	  var nextProjectLink = nextProject.attr('href');
	  
    $('#TB_ajaxContent .project_prev').attr({ href: prevProjectLink });
    $('#TB_ajaxContent .project_next').attr({ href: nextProjectLink });
    
    $(this).checkButtons();
    
    $('#TB_ajaxContent .project_prev').click(function() {	    
  	  $(this).openProject(prevProject);
  	  return false;
  	});
  	
  	$('#TB_ajaxContent .project_next').click(function() {	    
  	  $(this).openProject(nextProject);
  	  return false;
  	});
	};

	$.fn.openProject = function(cp) {

	  currentProject = cp;
	  var currentProjectHref = currentProject.attr('href');
	  var underscoreindex = currentProjectHref.lastIndexOf("_");
	  currentProjectId = currentProjectHref.substring(underscoreindex + 1, currentProjectHref.length);
	  
  	$('div.project_' + currentProjectId).clone().prependTo('#TB_ajaxContent');

  	//$('#TB_ajaxContent').fadeOut();
  	//$('#TB_ajaxContent').html(tempHtml);
  	
  	sIFR.replace(euro, {
      selector: 'h6',
    	css: [
        '.sIFR-root { color: #0082c8; font-size: 22px; line-height: 1em; }'
      ]
    });
    $(this).checkButtons();
    $(this).runScript(currentProject);

    //$('#TB_ajaxContent').fadeIn();

  };
  
  $.fn.checkButtons = function() {
	  if (prevProject.length == 0) {
  	  $('#TB_ajaxContent a.project_prev').hide();
  	} else if (nextProject.length == 0) {
  	  $('#TB_ajaxContent a.project_next').hide();
  	};
	};

	// Project Filter Widget
  $('#project_filters a.filter_category').click(function() {
    $('#project_filters a.project_filter_button').removeClass('selected');
    $(this).addClass('selected');
    var type = $(this).attr('title');
    $('#col3 a.thickbox:visible').fadeOut();
    $('#col3 a.thickbox[rel~='+type+']').fadeIn();   
    return true;
  })
    
    /* Clear by Sector */
    $('#project_filters #filter_all_button').click(function() {
      $(this).clearSector();
      return false;
    })
	
	/* Clearing Functions */
  $.fn.clearSector = function() {
    $('#project_filters a').removeClass('selected');
    $('#filter_all_button').addClass('selected');
    $('#col3 a.thickbox:hidden').fadeIn();
    return false;
  };
  
  
  
  
  // Mail address replace
  $('a.mail_link').nospam({
	replaceText: true,
	filterLevel:'low'
  });
  $('a.mail_link_text').nospam({
	filterLevel:'low'
  });
  
  
  /* IE6 PNG image replacement */
  if(jQuery.browser.version=="6.0"){
	 jQuery.each(jQuery.browser, function(i, val) {
  		if(i=="msie"&&val==true){
			$('img.ie6_replace').each(function(){
				//$(this).attr('src',$(this).attr('src').replace(".png",".gif"));
				var cloneImage = $(this).clone().insertAfter(this);
				$(this).makeAbsolute();
				cloneImage.css({ visibility:"hidden" });
			});
			$('div#col1').pngFix();
		}
  });

 }
});

$.fn.makeAbsolute = function(rebase) {
    return this.each(function() {
        var el = $(this);
        var pos = el.position();
        el.css({ position: "absolute",
            marginLeft: 0, marginTop: 0,
            top: pos.top, left: pos.left });
        if (rebase)
            el.remove().appendTo("body");
    });
}

jQuery.fn.nospam = function(settings) {
	settings = jQuery.extend({
		replaceText: false, 	// optional, accepts true or false
		filterLevel: 'normal' 	// optional, accepts 'low' or 'normal'
	}, settings);
	
	return this.each(function(){
		e = null;
		if(settings.filterLevel == 'low') { // Can be a switch() if more levels added
			if($(this).is('a[rel]')) {
				e = $(this).attr('rel').replace('//', '@').replace(/\//g, '.');
			} else {
				e = $(this).text().replace('//', '@').replace(/\//g, '.');
			}
		} else { // 'normal'
			if($(this).is('a[rel]')) {
				e = $(this).attr('rel').split('').reverse().join('').replace('//', '@').replace(/\//g, '.');
			} else {
				e = $(this).text().split('').reverse().join('').replace('//', '@').replace(/\//g, '.');
			}
		}
		if(e) {
			if($(this).is('a[rel]')) {
				$(this).attr('href', 'mailto:' + e);
				if(settings.replaceText) {
					$(this).text(e);
				}
			} else {
				$(this).text(e);
			}
		}
	});
};


/* Our Work section image loader */
loadProjectImages = function(projectID){
	$('#project_'+projectID+ ' img.lazyload').each(function(){
		$(this).attr('src',$(this).attr('rel'));
	});
}
