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"); 
*/

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


head.ready(function() {
	
		
  // Jquery styled drop down for recipes
	if ($('body').hasClass('our_work')) {
		$("#project_category").msDropDown({
			mainCSS: 'ei'
		});
	}
	
	
	//------------------------------------------------------------------------------------------------------------
	// iPad Includes - These scripts are applied to iPad/iThing browsers only
	//------------------------------------------------------------------------------------------------------------


	// iPad css include
	if ($.browser.iPad === true) {
	
		$('head').append('<meta http-equiv="X-UA-Compatible" content="chrome=1">')
	
	}
	
	if ($.browser.ithing === true) {
				
		$('head').append('<link rel="stylesheet" href="/css/screen/ipad.css" type="text/css">')
		$('head').append('<link rel="stylesheet" href="/css/screen/ipad_portrait.css" type="text/css" media="all and (orientation:portrait)">')
		$('head').append('<link rel="stylesheet" href="/css/screen/ipad_landscape.css" type="text/css" media="all and (orientation:landscape)">')
				
	}
	
	if ($.browser.chrome === true) {
			
		$('head').append('<link rel="stylesheet" href="/css/screen/chrome.css" type="text/css">')
			
	}
	


	// Applies fullsize background on body class
	var bg = '/images/background/home_bg_alden.jpg' 
	var home_bg = '/images/background/home_bg_alden.jpg'
	var our_expertise_bg = '/images/background/our_expertise_bg.jpg'
	var our_work_bg = '/images/background/our_work_bg.jpg'
	var who_we_are_bg = '/images/background/who_we_are_bg.jpg'
	var blog_bg = '/images/background/blog_bg.jpg'
	var contact_us_bg = '/images/background/contact_us_bg.jpg'
	
	if ($('body').hasClass('home')){
		bg = home_bg
	}
	else if ($('body').hasClass('our_expertise')){
		bg = our_expertise_bg
	}
	else if ($('body').hasClass('our_work')){
		bg = our_work_bg
	}
	else if ($('body').hasClass('who_we_are')){
		bg = who_we_are_bg
	}	
	else if ($('body').hasClass('blog')){
		bg = blog_bg
	}			
	else if ($('body').hasClass('contact_us')) {
		bg = contact_us_bg
	}
	else {
		bg = home_bg
	}
	
	
	if ($('body').hasClass('home')) {
		// Test for IE 7
		var ua = $.browser;
		if (ua.msie && ua.version === 7) {
			$.supersized({
				vertical_center: 0,
				fit_portrait: 0,
				slides: [{
					image: bg
				}]
			});
		}
		else {
			$.supersized({
				vertical_center: 0,
				fit_portrait: 0,
				slides: [{
					image: bg
				}]
			});
		}
	}
	else {
		$.supersized({
			vertical_center: 0,
			fit_portrait: 0,
			slides: [{
				image: bg
			}]
		});
	}
	
	// jQuery UI button
	if ($('div').hasClass('ui-button')) {
		$(".ui-button").button();
	}
	
  /* Light Box */
	if ($('div').hasClass('photo_item')) {
		$('.photo_item a').lightBox();
	}
  
	// Our Work 
	if ($('body').hasClass('our_work')) {
		
		var imageCycle = function(){
		
			/* Thickbox image viewer */
			$('div.project_content div.cycle').cycle({
				fx: 'fade',
				speed: 'fast',
				timeout: 5000,
				next: '.next2',
				prev: '.prev2'
			});
			
		}
		
		imageCycle();
		
		/* Previous / Next Project */
		var currentProject = '';
		var currentProjectId = '';
		var prevProject = '';
		var nextProject = '';
		var hashTag = window.location.hash;
		
		
		
		// Check for other projects
	  $.fn.checkButtons = function() {
		  if (prevProject.length == 0) {
	  	  $('#TB_ajaxContent a.project_prev').hide();
	  	} else if (nextProject.length == 0) {
	  	  $('#TB_ajaxContent a.project_next').hide();
	  	};
		};
		
		// Light box call		
		$.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();
	    
		};
	
		// Light box reload		
		$.fn.runScriptReload = function(cp) {
			
		  currentProject = cp;

		  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();
	    
		};
	
	
		// Check for hash tag param
		if(hashTag != ''){
			
			// Assign the param to a var and convert/delete any non alpha chars 
			linkParam = hashTag.substr(1, hashTag.length).replace(/[^0-9a-zA-Z]/g, '').toLowerCase();
					
			// Check to see if the param matches a project
			if ($('h4').hasClass(linkParam)) {
				var linkImage = $('h4.' + linkParam)
				var projectId = ($(linkImage).parent().parent().parent('.thickbox').attr('id'))
				loadProjectImages(projectId)
			}
			
			// Select light box with url hash tag
			if ($(linkParam === linkImage)) {
			
				$(linkImage).trigger('click', function(){
					$()
					
					currentProject = $(this);
					if ($.browser.iPad === true) {
						scroll(0, 0, 1)
					}
					$(this).runScript(currentProject);
					
				});
		
			}
			
		}
		

		// Load light box and replace url hash tag
		$('a.thickbox').click(function(){
			currentProject = $(this);
			clickedImage = $(this).find('h4').attr('class')
			if ($.browser.iPad === true) {
				scroll(0, 0, 1)
			}
			$(this).runScript(currentProject);
			window.location.hash = clickedImage;
		});
		
		
		// Feature project thumb rollover
		$('#featured_wrapper').hover(
			
			function () {
		    $('#featured_white_frame',this).css({
					'display': 'none'
				})
				$('#featured_green_frame',this).css({
					'display': 'block'
				})
				$('#featured_open_lightbox',this).css({'top':'-135px','height':'135px'})
				$('#featured_open_lightbox h4',this).css({'color':'#FFF'})
				$('#featured_open_lightbox h5',this).css({'display':'block'})
				
			},
		  function () {
		    $('#featured_green_frame',this).css({
					'display': 'none'
				})
				$('#featured_white_frame',this).css({
					'display': 'block'
				})
				$('#featured_open_lightbox',this).css({'top':'0','height':'28px'})
				$('#featured_open_lightbox h4',this).css({'color':'#7A8692'})
				$('#featured_open_lightbox h5',this).css({'display':'none'}) 
		  }

		)
		
		// Project thumb rollover
		$('.thumb_wrapper').hover(
			
			function () {
		    $('.thumb_white_frame',this).css({
					'display': 'none'
				})
				$('.thumb_green_frame',this).css({
					'display': 'block'
				})
				$('.thumb_open_lightbox',this).css({'top':'-50px','height':'80px'})
				$('.thumb_open_lightbox h4',this).css({'color':'#FFF'})
				$('.thumb_open_lightbox h5',this).css({'display':'block'})
				
			},
		  function () {
		    $('.thumb_green_frame',this).css({
					'display': 'none'
				})
				$('.thumb_white_frame',this).css({
					'display': 'block'
				})
				$('.thumb_open_lightbox',this).css({'top':'0','height':'28px'})
				$('.thumb_open_lightbox h4',this).css({'color':'#7A8692'})
				$('.thumb_open_lightbox h5',this).css({'display':'none'})    
		  }

		)
	
		// 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 false;
		})
		
		/* 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
	if ($('body').hasClass('contact')){
	  $('a.mail_link').nospam({
		replaceText: true,
		filterLevel:'low'
	  });
	  $('a.mail_link_text').nospam({
		filterLevel:'low'
	  });
	 } 

 			
    if ($('body').hasClass('home')) {	
			
			$('#slider').nivoSlider({
	        effect:'fold', //Specify sets like: 'fold,fade,sliceDown'
	        slices:15,
	        animSpeed:500, //Slide transition speed
	        pauseTime:9000,
	        startSlide:0, //Set starting Slide (0 index)
	        directionNav:true, //Next & Prev
	        directionNavHide:true, //Only show on hover
	        controlNav:true, //1,2,3...
	        controlNavThumbs:false, //Use thumbnails for Control Nav
	        controlNavThumbsFromRel:false, //Use image rel for thumbs
	        controlNavThumbsSearch: '.jpg', //Replace this with...
	        controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
	        keyboardNav:true, //Use left & right arrows
	        pauseOnHover:true, //Stop animation while hovering
	        manualAdvance:false, //Force manual transitions
	        captionOpacity:1, //Universal caption opacity
	        beforeChange: function(){},
	        afterChange: function(){},
	        slideshowEnd: function(){}, //Triggers after all slides have been shown
	        lastSlide: function(){}, //Triggers when last slide is shown
	        afterLoad: function(){} //Triggers when slider has loaded
	    });
		
		}
			
			/*
			if ($.browser.iPad === false) {
				$.supersized({
					slides: [{
						image: bg
					}]
				});
			}
			else {
				$.supersized({
					vertical_center : 0,
					fit_portrait : 0,					
					slides: [{
						image: bg
					}]
				});
			}	
*/


/* Note: commented out by Alden due to lack of cross domain AJAX Support
$.ajax({
    url: '/jobs.xml',
    type: 'GET',
    success: function(res) {
       console.log("yes")
    },
		failure: function(res) {
			 console.log("no")
		}
});
*/
	

	
}); // End dom ready


$(window).load(function(){
	

	
	// Hides linkedIn icon till it is fully loaded 
	$('.IN-widget').css({'visibility':'visible'})
	
	$('#bg').css({'display':'block'})
	
	if ($('body').hasClass('our_work')) {
		//un hide dropdown
		$('#project_category_wrapper').css({
			'visibility': 'visible'
		})
	}
	
/*
	// Flickr API
	if ($('body').hasClass('culture')) {
			$('.flickr').flickrGallery('72157626340739558','838c281ed3cde91a8de5d2f5cdd1ad52');
		}	
*/
	
});
	
// Bind an event to window.onhashchange that, when the history state changes,
// gets the url from the hash and displays either our cached content or fetches
// new content to be displayed.
$(window).bind('hashchange', function(e) {
			
	// Assign the param to a var and convert/delete any non alpha chars 
	changedLinkParam = window.location.hash.substr(1, window.location.hash.length).replace(/[^0-9a-zA-Z]/g, '').toLowerCase();

	if (changedLinkParam != "") {
	
		// Check to see if the param matches a project
		if ($('h4').hasClass(changedLinkParam)) {
			var linkImage = $('h4.' + changedLinkParam)
			var projectId = ($(linkImage).parent().parent().parent('.thickbox').attr('id'))
			loadProjectImages(projectId)
		}
		else {
			// Close thick box
			tb_remove()
			return false
		}
		
		// Remove current content
		$('#TB_window,#TB_overlay,#TB_HideSelect').trigger("unload").unbind()
		
		// Load the project into the thickbox 
		$(linkImage).trigger('click', function(){
			currentProject = $(this);
			$(this).runScriptReload(currentProject);
		});
	
	}
	else {
		// Close thick box
		tb_remove()
		return false
	}
	
})



/* $(document).ready(function() {

	$('#TB_closeWindowButton').click(function() {
 	   window.location.hash = '';
	});

}); // in progress */




$.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);
			}
		}
	});
};


//project category filter sidebar dd
function categorySubmit(){
		var selectedElement = $("#project_category option:selected");
		var selectedElementValue = selectedElement.val(); 
		if (selectedElementValue.length > 0) {
			window.location = '/our_work/category/' + selectedElementValue;
		}else{
			window.location = '/our_work';
		}
	}


