var wh, ww, shtml, phtml, chtml, feat_w, featb_w;
var uri = window.location.href;
var ANIMSPEED=1000;
var ANIMCLOSE = 800;
var EASINGOPEN = 'easeInOutQuart';
var EASINGCLOSE = 'easeInOutQuart';
var careerPost;
$(function() {
	if( uri.indexOf('#') == -1 ){
		window.location = uri + '#/' + (Math.floor(Math.random() * 6) + 1)
	}

	wh = $(window).height();
	ww = $(window).width();

	if(ww >1024 && wh > 800 ) {
		moveServicesBottomContent();
		saveCont();
		initMeasures();
		initFeat();
		initCarousel()
		initTabber();
		initScroll();
		initNavSlide();
		aboutContent();
		workContent();
		toolTip();
	}else{
		moveServicesBottomContent();
		saveCont();
		initMeasures();
		initFeat();
		initCarousel()
		initTabber();
		initScroll();
		initNavSlide();
		aboutContent();
		workContent();
		initResizeSmallNav();
		initSmallFooter();
		toolTip();
	}
	$("#welcome-screen img").width( ww );

	window.setTimeout('loadFinished()', 2500);

	$('html').click(function() {
		closeNav();	
		closeFeature();
		closeTabber();
	});

	$('#nav,#cboxOverlay,#careers,#press,#colorbox,#featured').click(function(event){
		event.stopPropagation();
	});
	
	//work sample overlay code
	$('.work-list li.box').click(function(){
		var clicked = $(this).children('.img').children('a');
		var elm = $(this).children('.img').children().children('img');
		var style = elm.attr('style');
		
		$('body > #image-box').attr('class', '');
		$('body > #image-box > .content >  h1').text('').attr('style','');
		$('body > #image-box > .content >  p').remove('');
		$('body > #image-box > .visit > a.site').attr('href', '#');
		$('body > #image-box > .visit').css('height', '28px').css('padding-top', '7px').children('a.site').show();
		
		$('body > #image-box').attr('class', clicked.attr('class'));
		$('body > #image-box > .content >  h1').text( elm.attr('title')).attr('style',style);
		
		var p = elm.attr('alt');
		
		p = p.split('@')
				
		for(i = 0; i < p.length; i++){
			$('body > #image-box > .content').append('<p>' + p[i] + '</p>')
		}
		
		if(clicked.attr('title') && clicked.attr('title') != '#'){
			$('body > #image-box > .visit > a.site').attr('href', clicked.attr('title'));
		}else{
			$('body > #image-box > .visit').css('height', 0).css('padding-top', 0).children('a.site').hide();
		}

		$('body > #image-box > .img-holder > img').attr('src', clicked.attr('href')).load(function(){
			w = $(this).width();
			h = $(this).height();
			
			w = w + 246;
			h = h + 80;
			
			$.colorbox({
				top: '10%',
				inline:true, href:"#image-box",	
				opacity: .7,
				onLoad: function(){$('#cboxClose').attr('style','display:none !important;')},
				onComplete: function(){$('#cboxNext,#cboxPrevious, #cboxClose').attr('style','display:block !important;')},
				onCleanup: function(){$('#cboxNext,#cboxPrevious,#cboxClose').attr('style','display:none; !important')}
			});
		});

		return false; 
	});	
	//staff bio overlay code
	$('.people-list li.box').click(function(){
		var clicked = $(this).children('.img').children('a');
		var elm = $(this).children('.img').children('a').children('img');
		/*
		$('body > #people-box').attr('class', '');
		$('body > #people-box > img').attr('src', '');
		$('body > #people-box > .content >  h1, body > #people-box > .content >  h2, body > #people-box > .content > span.quote, body > #people-box > .content > p').text('');
		
		$('body > #people-box').attr('class', clicked.attr('class') + ' ' + elm.attr('data-color-scheme'));
		$('body > #people-box > .content >  h1').text(elm.attr('title'));
		$('body > #people-box > .content >  h2').text('"' + elm.attr('data-quote') + '"');
		$('body > #people-box > .content > span.quote').text('~ '+elm.attr('data-quote-author'));
		$('body > #people-box > .content > p').html(elm.attr('alt'));
		Cufon.replace('.cufon', {fontFamily:"Helvetica Neue LT Std MED", textShadow: '1px 1px #333'});
		*/
		$('body > #people-box').attr('class', '');
		$('body > #people-box > img').attr('src', '');
		$('body > #people-box > .content > p').text('');
		
		$('body > #people-box').attr('class', clicked.attr('class') + ' ' + elm.attr('data-color-scheme'));
		$('body > #people-box > .content > p').html(elm.attr('alt'));
				
		$('body > #people-box > img').attr('src', clicked.attr('href')).load(function(){
			$.colorbox({
				top: '10%',
				inline:true, href:"#people-box",	
				opacity: .7
			});
		});
		
		return false; 
	});
	//overylay next arrow
	$('#cboxNext').click(function(){
		$('#cboxNext,#cboxPrevious').attr('style','display:none !important;');
		$('#cboxLoadedContent > #image-box > .visit').css('height', '28px').css('padding-top', '7px').children('a.site').show();
		$('#cboxLoadedContent > #image-box > .content >  p').remove('');
		group_cur = $('#cboxLoadedContent > #image-box').attr('class');
		group = group_cur.split('-')[0]
		cur = group_cur.split('-')[1]
		next = parseInt(cur) + 1;
		newString = group + '-'+ next;

		if($('.work-list li.box > .img a.'+newString).length > 0){
			$('#cboxLoadedContent > #image-box').attr('class', newString);
			
			var elm = $('.work-list li.box > .img a.'+newString).children('img');
			var style = elm.attr('style');
			
			$('#cboxLoadedContent > #image-box > .content >  h1').text('').attr('style','');
			//$('#cboxLoadedContent > #image-box > .content >  p').text('');
			$('#cboxLoadedContent > #image-box > .visit > a.site').attr('href', '#');
			
			$('#cboxLoadedContent > #image-box > .content >  h1').text( elm.attr('title')).attr('style',style);
			//$('#cboxLoadedContent > #image-box > .content >  p').text( elm.attr('alt'));
			
			var p = elm.attr('alt');
			
			p = p.split('@')
					
			for(i = 0; i < p.length; i++){
				$('#cboxLoadedContent > #image-box > .content').append('<p>' + p[i] + '</p>')
			}
			
			//$('#cboxLoadedContent > #image-box > .visit > a.site').attr('href', elm.parent().attr('title'));
			
			if(elm.parent().attr('title') && elm.parent().attr('title') != '#'){
				$('#cboxLoadedContent > #image-box > .visit > a.site').attr('href', elm.parent().attr('title'));
			}else{
				$('#cboxLoadedContent > #image-box > .visit').css('height', 0).css('padding-top', 0).children('a.site').hide();
			}
			
			
			$('#cboxLoadedContent > #image-box > .img-holder > img').attr('src', elm.parent().attr('href'))
		}else{
			$('.work-list li.box > .img a[class^='+group+']').each(function(){
				if($(this).hasClass('first')){
					var clicked = $(this);
					var elm = clicked.children('img');
					var style = elm.attr('style');
					
					$('#cboxLoadedContent > #image-box').attr('class', clicked.attr('class').split(' ')[0]);
			
					$('#cboxLoadedContent > #image-box > .content >  h1').text('').attr('style','');
					//$('#cboxLoadedContent > #image-box > .content >  p').text('');
					$('#cboxLoadedContent > #image-box > .visit > a.site').attr('href', '#');
					
					$('#cboxLoadedContent > #image-box > .content >  h1').text( elm.attr('title')).attr('style',style);
					//$('#cboxLoadedContent > #image-box > .content >  p').text( elm.attr('alt'));
					
					var p = elm.attr('alt');
					
					p = p.split('@')
							
					for(i = 0; i < p.length; i++){
						$('#cboxLoadedContent > #image-box > .content').append('<p>' + p[i] + '</p>')
					}
					
					
					//$('#cboxLoadedContent > #image-box > .visit > a.site').attr('href', elm.parent().attr('title'));
					
					if(elm.parent().attr('title') && elm.parent().attr('title') != '#'){
						$('#cboxLoadedContent > #image-box > .visit > a.site').attr('href', elm.parent().attr('title'));
					}else{
						$('#cboxLoadedContent > #image-box > .visit').css('height', 0).css('padding-top', 0).children('a.site').hide();
					}

					$('#cboxLoadedContent > #image-box > .img-holder > img').attr('src', elm.parent().attr('href'))
				}
			
			});
		}
		return false;		
	});
	//overly prev arrow
	$('#cboxPrevious').click(function(){
		$('#cboxNext,#cboxPrevious').attr('style','display:none !important;')
		$('#cboxLoadedContent > #image-box > .visit').css('height', '28px').css('padding-top', '7px').children('a.site').show();
		$('#cboxLoadedContent > #image-box > .content >  p').remove('');
		group_cur = $('#cboxLoadedContent > #image-box').attr('class');
		group = group_cur.split('-')[0]
		cur = group_cur.split('-')[1]
		prev = parseInt(cur) - 1;
		newString = group + '-'+ prev;

		if($('.work-list li.box > .img a.'+newString).length > 0){
			$('#cboxLoadedContent > #image-box').attr('class', newString);
			
			elm = $('.work-list li.box > .img a.'+newString).children('img');
			var style = elm.attr('style');
			
			$('#cboxLoadedContent > #image-box > .content >  h1').text('').attr('style','');
			//$('#cboxLoadedContent > #image-box > .content >  p').text('');
			$('#cboxLoadedContent > #image-box > .visit > a.site').attr('href', '#');
			
			$('#cboxLoadedContent > #image-box > .content >  h1').text( elm.attr('title')).attr('style',style);
			//$('#cboxLoadedContent > #image-box > .content >  p').text( elm.attr('alt'));
			
			
			var p = elm.attr('alt');
			
			p = p.split('@')
					
			for(i = 0; i < p.length; i++){
				$('#cboxLoadedContent > #image-box > .content').append('<p>' + p[i] + '</p>')
			}
			
			//$('#cboxLoadedContent > #image-box > .visit > a.site').attr('href', elm.parent().attr('title'));
			if(elm.parent().attr('title') && elm.parent().attr('title') != '#'){
				$('#cboxLoadedContent > #image-box > .visit > a.site').attr('href', elm.parent().attr('title'));
			}else{
				$('#cboxLoadedContent > #image-box > .visit').css('height', 0).css('padding-top', 0).children('a.site').hide();
			}
			
			
			$('#cboxLoadedContent > #image-box > .img-holder > img').attr('src', elm.parent().attr('href'))
		}else{
			$('.work-list li.box > .img a[class^='+group+']').each(function(){
				if($(this).hasClass('last')){
					var clicked = $(this);
					var elm = clicked.children('img');
					var style = elm.attr('style');
					
					$('#cboxLoadedContent > #image-box').attr('class', clicked.attr('class').split(' ')[0]);
					
					$('#cboxLoadedContent > #image-box > .content >  h1').text('').attr('style','');
					//$('#cboxLoadedContent > #image-box > .content >  p').text('');
					$('#cboxLoadedContent > #image-box > .visit > a.site').attr('href', '#');
					
					$('#cboxLoadedContent > #image-box > .content >  h1').text( elm.attr('title')).attr('style',style);
					//$('#cboxLoadedContent > #image-box > .content >  p').text( elm.attr('alt'));
					
					var p = elm.attr('alt');
					
					p = p.split('@')
							
					for(i = 0; i < p.length; i++){
						$('#cboxLoadedContent > #image-box > .content').append('<p>' + p[i] + '</p>')
					}
					
					//$('#cboxLoadedContent > #image-box > .visit > a.site').attr('href', elm.parent().attr('title'));
					if(elm.parent().attr('title') && elm.parent().attr('title') != '#'){
						$('#cboxLoadedContent > #image-box > .visit > a.site').attr('href', elm.parent().attr('title'));
					}else{
						$('#cboxLoadedContent > #image-box > .visit').css('height', 0).css('padding-top', 0).children('a.site').hide();
					}
			
					
					$('#cboxLoadedContent > #image-box > .img-holder > img').attr('src', elm.parent().attr('href'))
				}
			
			});
		}		
		
		return false;		
	});
	//career apply overlay
	$('.apply-btn').click(function(){
		var career = $(this).attr('data-career');
		
		$('body > #career-box span.career').text( career );
		careerPost = career;
		Cufon.replace('.cufon', {fontFamily:"Helvetica Neue LT Std MED"});
		$.colorbox({
			top: '10%',
			inline:true, href:"#career-box",	
			opacity: .7
		});
		return false;
	});
	
	//change press release
	$('.press-list-nav > li > p > a').click(function(){
		$('.press-list li').fadeOut(250);
		var ind = $(this).parent().parent().index();
		$('.press-list > li:eq('+ind+')').fadeIn(250);
		
		return false;
	});
	
	
	
});

$(window).bind('resize scroll', function() {
	wh = $(window).height();
	ww = $(window).width();

	if(ww >1024 && wh > 800) {
		appendCont();
		initMeasures();
		initFeat();
		initTabber();
		initScroll();
		resetNav();
	}else{
		appendCont();
		initMeasures();
		initFeat();
		initTabber();
		initScroll();
		initResizeSmallNav();
		initSmallFooter();
	}
}); 

//load finished screen
function loadFinished(){
	//console.log('completed');
	$("#welcome-screen").fadeOut(500)
}
//function to moves elements based on window size.
function initMeasures() {

	var wrap = $('#wrap');

	var logo = $('#logo');
	var nav = $('#nav');
	var tabber = $('.tabber');
	var ctab = $('#careers .tab');
	var ptab = $('#press .tab');
	var ttext = $('.text-wrap');
	var cpane = $('#careers .text .scroll-pane');
	var ppane1 = $('#press .text .scroll-pane');
	var ppane2 = $('#press .text .right-cont');
	var clientbox = $('#client-feature li .client-box');
	var slider_controls = $('#bg-images > ul');
	var client_overlay = $('#client-overlay');
	var arrows = $('.prev, .next');
	var pw;

	$(wrap).width(ww).height(wh);
	$(logo).css({left:((ww-968)/2)+'px'});
	$(nav).css({left:(ww/2)+'px'});
	
	$(ctab).css({width:(((ww-1024)/2)+179)+'px'});
	$(ptab).css({width:(((ww-1024)/2)+870)+'px'});
	$(tabber).css({height:(wh-82)+'px', bottom:(38-(wh-82))+'px'});
	$(ttext).css({height:((wh-82)-25)+'px'});
	
	$(cpane).css({height:((wh-82)-99)+'px'});
	
	$(ppane1).css({height:((wh-82)-113)+'px'});
	$(ppane2).css({height:((wh-82)-178)+'px'});
	
	var ch = $(clientbox).height();
	$(clientbox).css({marginTop:((wh/2)-(ch/2))+'px'}); 
	
	$(slider_controls).css({top: (wh*.25)+'px'});
	
	$(client_overlay).css({top: (wh-260)/2});
	$(arrows).css({top: ((wh-52)/2)-100});
	
}
	//backend code for formatting text(bottom bar text) correctly
	function moveServicesBottomContent(){
		var slides = $('ul#services-features li');
		var footer = $('#myFooter');
		var bg_images = $('#bg-images');
		var html;
		
		footer.append('<ul id="bottom-content">&nbsp;</ul>')
		//bg_images.after('<div id="service_quotes"></div>');
		
		slides.each(function(){
			html = $(this).children('div.attached-content').children('div.bottom-content').html();
			$(this).children('div.attached-content').children('div.bottom-content').remove();
			$('ul#bottom-content').append('<li>' + html + '</li>')

		});

	}

//nav menu slide downs
function initNavSlide(){
	var close = $('a.close');
	var dd1 = $('li.btn-1 div.nav-content');
	var c1 = $('li.btn-1 div.nav-content > a.tab');
	var dd2 = $('li.btn-2 div.nav-content');
	var c2 = $('li.btn-2 div.nav-content > a.tab');
	var dd3 = $('li.btn-3 div.nav-content');
	var c3 = $('li.btn-3 div.nav-content > a.tab');
	var dd4 = $('li.btn-4 div.nav-content');
	var c4 = $('li.btn-4 div.nav-content > a.tab');
	//var hash = uri.split('#');
	
	resetNav();
	$('div.nav-content').children(':not(.tab)').hide();
	/*if(hash[1]){
		switch(hash[1].toLowerCase())
		{
		case 'services':
		  $(dd1).css('top','-9px').children('ul').show();
		  break;
		case 'work':
		  $(dd2).css('top','-9px').children('ul').show();
		  break;
		case 'about':
		  $(dd3).css('top','-9px').children('ul').show();
		  break;
		case 'contact':
		  $(dd4).css('top','-9px').children('ul').show();
		  break;
		default:
		  break;
		}
	}*/
	
	$(close).click(function(){
		closeNav();
		return false;
	});

	$(c1).click(function(){
		if( !$(this).parent().parent().hasClass('open') ){
			closeNav();	
			closeFeature();
			closeTabber();
			jQuery.bgSlideshow.pause();
			$(dd1).show().stop(true,true).animate({top:-9},ANIMSPEED,EASINGOPEN).parent().addClass('open').children('div.nav-content').children().show();
		}else{
			closeNav();	
		}
		return false;
	});
	$(c2).click(function(){
		if( !$(this).parent().parent().hasClass('open') ){
			closeNav();	
			closeFeature();
			closeTabber();
			jQuery.bgSlideshow.pause();
			$(dd2).show().stop(true,true).animate({top:-9},ANIMSPEED,EASINGOPEN,function(){}).parent().addClass('open').children('div.nav-content').children(':not(.work-list)').show();
			$(dd2).children('.featured').show();
			$('.work-nav li a.cur').removeClass('cur');
			$('.work-nav li:eq(0) a').addClass('cur');
		}else{
			closeNav();	
		}
		return false;
	});
	$(c3).click(function(){
		if( !$(this).parent().parent().hasClass('open') ){
			closeNav();	
			closeFeature();
			closeTabber();
			jQuery.bgSlideshow.pause();
			$(dd3).show().stop(true,true).animate({top:-9},ANIMSPEED,EASINGOPEN).parent().addClass('open').children('div.nav-content').children(':not(.about-content)').show();
			$(dd3).children('.philosophy').show();
			$('.about-nav li a.cur').removeClass('cur');
			$('.about-nav li:eq(0) a').addClass('cur');
		}else{
			closeNav();	
		}
		return false;
	});
	$(c4).click(function(){
		if( !$(this).parent().parent().hasClass('open') ){
			closeNav();
			closeFeature();
			closeTabber();
			jQuery.bgSlideshow.pause();
			$(dd4).show().stop(true,true).animate({top:-9},ANIMSPEED,EASINGOPEN).parent().addClass('open').children('div.nav-content').children().show();
		}else{
			closeNav();
		}
		return false;
	});
	$('#nav li .nav-content > ul > li ul> li> h2 > a').click(function(){
		closeNav();
	})
	
	//$(':not(#nav)').not('.tab, .btn-1, .btn-2, .btn-3, .btn-4, .nav-content, .nav-content ul, .nav-content ul li').click(function(){
	//	closeNav();
	//});
}

	//close all open alpha nav
	function closeNav(){
		$('div.nav-content').each(function(){
			if($(this).parent().hasClass('open')){
				$(this).stop(true,true).animate({top:-(wh-50)+'px'},ANIMCLOSE, EASINGCLOSE,function(){
					$(this).children(':not(.tab)').hide();
				}).parent().removeClass('open');
			}
		});	
		return false;
	}
	//about tab content swap
	function aboutContent(){
		$('.about-nav li a').click(function(){
			var text = $(this).text();
			if(text == 'careers'){
				closeTabber();
				if($('#'+text).hasClass('open'))
					closeTabber();
				else
					$('#'+text).stop(true,false).animate({bottom:-38},ANIMSPEED,EASINGOPEN,function(){$(this).addClass('open');});
					
				jQuery.bgSlideshow.pause();
				closeNav();
				closeFeature();
				return false;
			}else if(text == 'press releases'){
				closeTabber();
				if($('#press').hasClass('open'))
					closeTabber();
				else
					$('#press').stop(true,false).animate({bottom:-38},ANIMSPEED,EASINGOPEN,function(){$(this).addClass('open');});
					
				jQuery.bgSlideshow.pause();
				closeNav();
				closeFeature();
				return false;
			}else{
				$('.about-nav li a.cur').removeClass('cur');
				$(this).addClass('cur')
				$('.about-content:visible').fadeOut(300, function(){
					$('div.'+text).fadeIn(500);
				});
				return false;
			}
		});
	}
	//work tab content swap
	function workContent(){
		$('.work-nav li a').click(function(){
			var text = $(this).text();
			if(text == 'services')
				return false;
			if(text == 'client list')
				text = 'client-list';
			if(text == 'business development')
				text = 'business-development';
			if(text == 'user experience')
				text = 'user-experience';
			if(text == 'identity/branding')
				text = 'identity-branding';
			if(text == 'emerging media')
				text = 'emerging-media';
			if(text == 'technology')
				text = 'technology';
			if(text == 'design')
				text = 'design';
			if(text == 'print')
				text = 'print';
					
			$('.work-nav li a.cur').removeClass('cur');
			$(this).addClass('cur')
			$('.work-list:visible').fadeOut(300, function(){
				$('ul.'+text).fadeIn(500);
			});
			return false;
		});
		
		var box = $('.work-list .box');
		$(box).each(function(){ $(this).attr('title', '')});

	}
	//resize nav for smaller browsers
	function initResizeSmallNav(){
		$('.prev, .next').css({top: ((wh-52)/2)-25});
		$('#nav').css({left:(ww/2)-15+'px'});
		$('.nav-content').css('right', '10px').css('width','880px').css({height:(wh-110)+'px'});
		$('#nav > ul > li:not(.open)').children('div.nav-content').css({top:-(wh-50)+'px'});

		var dd1a = $('li.btn-1 div.nav-content a.tab');
		var dd2a = $('li.btn-2 div.nav-content a.tab');
		var dd3a = $('li.btn-3 div.nav-content a.tab');
		var dd4a = $('li.btn-4 div.nav-content a.tab');
		
		$(dd1a).css('right', '347px');
		$(dd2a).css('right', '229px');
		$(dd3a).css('right', '111px');
		$(dd4a).css('right', '-7px');	
		
		$('li.btn-4 .nav-content .address-box').css('left','510px').css('bottom', 'auto').css('top', '450px');
		
		$('#nav li .nav-content > ul.services > li').css('clear', 'both').css('width', '800px').css('float', 'none');
		$('#nav li .nav-content > ul.services > li > ul').css('float', 'none');
		$('#nav li .nav-content > ul.services > li > ul > li').css('width', '265px');
		
		$('#nav li .nav-content > ul.work-list, #nav li .nav-content .people ul.people-list').css('width', '650px');		
		$('#nav li .nav-content > ul.work-list').css('margin-left', '30px');
		$('#nav li .nav-content > .about-content').css('margin-left', '50px').css('width','600px');	
		$('#nav li .nav-content > .client-list').css('margin-left', '20px').css('width','720px');
		$('#nav li .nav-content > ul.work-list > li, #nav li .nav-content .people ul.people-list > li').css('clear', 'both').css('width', '800px').css('float', 'none');		
		$('#nav li .nav-content > ul.work-list > li.left, #nav li .nav-content .people ul.people-list > li.left').css('margin-right', '0');
		$('#nav li .nav-content > ul.work-list > li > ul > li, #nav li .nav-content .people ul.people-list > li > ul > li').css('float', 'left');
		
		$('#nav li .nav-content > ul.client-list > li > ul > li').css('float', 'left').css('width', '225px');
		
		var close = $('a.close');
		$(close).css({top: (wh/2)-40 + 'px'});
	}
	//reset nav to larger format
	function resetNav(){
		$('.prev, .next').css({top: ((wh-52)/2)-100});
		$('.nav-content').css('width', '530px').css({height:(wh-110)+'px'});
		
		$('#nav > ul > li:not(.open)').children('div.nav-content').css({top:-(wh-50)+'px'});
		
		var close = $('a.close');
		var dd1 = $('li.btn-1 div.nav-content');
		var dd2 = $('li.btn-2 div.nav-content');
		var dd3 = $('li.btn-3 div.nav-content');
		var dd4 = $('li.btn-4 div.nav-content');
		
		$(close).css({top: (wh/2)-40 + 'px'});
		$(dd1).css('right', '354px');
		$(dd2).css('right', '236px');
		$(dd3).css('right', '118px');
		$(dd4).css('right', '0px');	
		
		var atab = $('li div.nav-content a.tab');
		
		$(atab).css('right', '-7px');
		
		$('li.btn-4 .nav-content .address-box').css('left','30px').css('bottom', '40px').css('top', 'auto');
		$('#nav li .nav-content > ul.services > li').css('clear', 'none').css('width', '230px').css('float', 'left');
		$('#nav li .nav-content > ul.services > li > ul').css('float', 'right');
		$('#nav li .nav-content > ul.services > li > ul > li').css('width', 'auto');
		
		
		$('#nav li .nav-content > ul.work-list, #nav li .nav-content .people ul.people-list').css('width', '350px');
		$('#nav li .nav-content > ul.work-list').css('margin-left', '0');
		$('#nav li .nav-content > .about-content').css('margin-left', '0').css('width','400px');	
		$('#nav li .nav-content > ul.work-list > li, #nav li .nav-content .people ul.people-list > li').css('clear', 'none').css('width', '160px').css('float', 'left');
		$('#nav li .nav-content > ul.work-list > li.left, #nav li .nav-content .people ul.people-list > li.left').css('margin-right', '20px');
		$('#nav li .nav-content > ul.work-list > li > ul > li, #nav li .nav-content .people ul.people-list > li > ul > li').css('float', 'none');
		$('#nav li .nav-content > ul.client-list > li > ul > li').css('width', 'auto');
		
	}
//function to start bottom slide out in footer. (careers, press releases)
function initTabber() {
	var tabh = $('.tabber').outerHeight();
	var panew;
	
	$('.tab a').click(function() {
		closeTabber();
		if($(this).parents('.tabber').hasClass('open'))
			closeTabber();
		else
			$(this).parents('.tabber').stop(true,false).animate({bottom:-38},ANIMSPEED,EASINGOPEN,function(){$(this).addClass('open');});
			
		jQuery.bgSlideshow.pause();
		closeNav();
		closeFeature();
		return false;
	});
	
	$('.gray-close-btn').click(function() {
		closeTabber();
		return false;
	});
}
	//close tabber
	function closeTabber(){
		var tabh = $('.tabber').outerHeight();
		$('.tabber').stop(true,false).animate({bottom:(38 - tabh)},ANIMSPEED,EASINGCLOSE,function(){$(this).removeClass('open');});
	}
	//function for custom scroll bars in footer slide out
	function initScroll(){
		//$('.scroll-pane').jScrollPane({showArrows:true, scrollbarWidth:14, scrollbarMargin:0});
		
		var settings = {
			showArrows:true, scrollbarWidth:14, scrollbarMargin:0
		};
		var pane = $('.scroll-pane')
		pane.jScrollPane(settings);
		var api = pane.data('jsp');
		api.reinitialise();
	}

	//reinitializes saved html. this is necessary when resizing the scroller bar in footer tab
	function appendCont(){
		$('#careers .text').empty().html(chtml);
		$('#press .text').empty().html(phtml);
	}

	//saves html in memory
	function saveCont(){
		chtml = $('#careers .text').html();
		phtml = $('#press .text').html();
	}

//function for featured slide out box.
function initFeat(){
	var feat = $('#featured');
	var featb = $('#featured .boxes');
	var box = $('#featured .box');
	var box_w = 159;
	var extras_w = 117;
	var total_fw;
	
	//$(feat).width((ww-((ww-1014)/2))).css({left:(47-(ww-((ww-1014)/2)))+'px'});
	//$(featb).width((ww-((ww-1014)/2))-88);
	
	total_fw = (box.length * box_w) + extras_w;
	if(total_fw > ww){
		feat_w = (ww-((ww-1014)/2));
	}else{
		feat_w = total_fw;
	}
	featb_w = feat_w - extras_w;
	$(feat).width(feat_w).css({left:47-feat_w+'px'});
	featb.width(featb_w);

	$('.btn-feat-close').click(function(){
		$('.jcarousel-next').trigger('click');
		return false;
	});
	//slider
	$('#btn-feat-open').click(function() {
		if(feat.hasClass('open')){
			closeNav();
			$(feat).stop(true,false).animate({left:-(feat_w - 47)},ANIMCLOSE,EASINGCLOSE,function(){$(this).removeClass('open');});
		}else{
			closeNav();
			closeTabber();
			$(feat).stop(true,false).animate({left:0},ANIMSPEED,EASINGOPEN,function(){$(this).addClass('open');});
		}
		jQuery.bgSlideshow.pause();
		return false;
	});
	
	$(box).click(function(){
		var cur = $(this).attr('title');
		//var num_features =  $('.boxes').find('.box').length;
		//cur = -(cur -  num_features) + 1;

		$(feat).stop(true,false).animate({left:-(feat_w - 47)},ANIMCLOSE,EASINGCLOSE,function(){$(this).removeClass('open');});
		window.location = 'http://' + window.location.hostname +window.location.pathname+ '#/clients/' + cur;
		//alert(window.location.pathname)
		//moveThumbs();
		return false;
	});
	
	$(box).hover(function() {
		$(this).find('.desc').stop(true, false).animate({top:0},ANIMSPEED,EASINGCLOSE);
	},function() {
		$(this).find('.desc').stop(true, false).animate({top:105},ANIMSPEED,EASINGCLOSE);
	});
}
	//close feature slide out
	function closeFeature(){
		var feat = $('#featured.open');
		$(feat).stop(true,true).animate({left:-(feat_w - 47)},ANIMCLOSE,EASINGCLOSE).removeClass('open');
		return false;
	}
	//starts feature box slider
	function initCarousel(){
		$('#mycarousel').jcarousel({
			wrap: 'circular',
			rtl: false,
			scroll: 2,
			easing: 'easeOutSine',
			itemFallbackDimension: 149
		});
	}

//==============::FORM VALIDATIONs && AJAX-Call::====================
function checkEmail(email){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if(filter.test(email)) return true; else return false;
}

function chkValidity(id){
	var formName = document.getElementById(id);
	var reqFields = $('#'+id+' .mandatory');
	var err=false;
	//check for empty fields:
	for(i=0; i < reqFields.length; i++){
		if(reqFields[i].value=='' || reqFields[i].value.indexOf('We Really Need')!=-1 || reqFields[i].value.indexOf('Please complete the field')!=-1 || reqFields[i].value.indexOf('Please enter a valid Email address')!=-1){
			err=true;
			if(reqFields[i]===formName.name)
				reqFields[i].value='We Really Need Your Name';
			else if(reqFields[i]===formName.phone)
				reqFields[i].value='We Really Need Your Number';
			else if(reqFields[i]===formName.email)
				reqFields[i].value='We Really Need Your Email Address';
			
			else if(reqFields[i]===formName.fname)
				reqFields[i].value='We Really Need Your First Name';
			else if(reqFields[i]===formName.lname)
				reqFields[i].value='We Really Need Your Last Name';
			else if(reqFields[i]===formName.cletter)
				reqFields[i].value='We Really Need Your Cover Letter';
			else if(reqFields[i]===formName.city)
				reqFields[i].value='We Really Need Your City';
			else if(reqFields[i]===formName.address)
				reqFields[i].value='We Really Need Your Address';
			else if(reqFields[i]===formName.state)
				reqFields[i].value='We Really Need Your State';
			else if(reqFields[i]===formName.zipcode)
				reqFields[i].value='We Really Need Your Zipcode';
			else if(reqFields[i]===formName.resume)
				reqFields[i].value='We Really Need Your Resume';
			else
				reqFields[i].value='Please complete the field';
			$(reqFields[i]).addClass('mandatoryErr');
		}
		else $(reqFields[i]).removeClass('mandatoryErr');
	}
	if(err) return false;
	
	//check valid email:
	if(!checkEmail(formName.email.value)){
		$(formName.email).addClass('mandatoryErr');
		formName.email.value='Please enter a valid Email address';
		return false;
	}
	
	//as the form is valid do the followings:
	ajaxCall(id, formName);
	return false;
}

function makeFormsActive(){
	if($('#contact_form .thankYou').css('display')!='none'){
		$('#contact_form .thankYou').css('display','none');
		$('#contact_form .formLeft, #contact_form .subRightContainer').css('display','');
	}
	if($('#careerApplyFormCenter .thankYou').css('display')!='none'){
		$('#careerApplyFormCenter .thankYou').css('display','none');
		$('#careerApplyFormCenter .careerForms').css('display','');
	}
}

function resetForm(id){
	//clear fields:
	$('#'+id+' input:text, #'+id+' textarea').val('');
	$('#'+id+' input:checkbox').attr('checked', false).parent('li').removeClass('fakechecked');
	$('#'+id+' .mandatoryErr').removeClass('mandatoryErr');
}

function showThanks(id, formName){
	//display Thanks:
	$('#'+id+' .formLeft, #'+id+' .subRightContainer, #'+id+' .careerForms').fadeOut(ANIMSPEED/2, function(){
		resetForm(id);
		$('#'+id+' .thankYou').fadeIn(ANIMSPEED/2);
	});

}

function ajaxCall(id, formName, index){
	parms = 'id=' + id;
	if(formName===undefined || formName==''){
		if(index!=undefined){
			var temporaryIMG='';
			if(id==='featureEnlarge'){
				temporaryIMG='<img src="'+preAjaxLoaderImg.src+'" alt="" style="display:block; margin:200px auto 300px;" />';
				$("#featureEnlarge ul:first li:eq("+index+")").html(temporaryIMG);
				showFeatures(index);
			}
			else if(id==='peopleEnlarge'){
				temporaryIMG='<img src="'+preAjaxLoaderImg.src+'" alt="" style="display:block; position:relative; left:50px; top:160px; margin:0 auto" />';
				$("#peopleDetails li:eq("+index+")").html(temporaryIMG);
				showPeoples(index);
			}
		}
	}
	else if(id==='careerApplyFormCenter' && careerPost!='')
		parms+='&appliedPost='+careerPost+'&'+jQuery(formName).serialize();
	else
		parms+='&'+jQuery(formName).serialize();

	$.ajax({
	   type: "POST",
	   url: "includes/php/ajax.php",
	   data: parms,
	   error: function(){
			alert('Error while loading....');
		},
	   success: function(msg){
			if(msg==1){
				//alert('mail sent');
				if(id==='contact_form' || id==='careerApplyFormCenter'){
					showThanks(id, formName);
				}
			}
			else if(msg==0)
				alert('mail not sent');
			else if(msg!=''){//Get HTML by request:
				if(id==='featureEnlarge'){
					pattern = /<li>(.*?)<\/li>/g;
					
					if(index===undefined){//just get structure:
						var newstring=msg.replace(pattern,'<li></li>');
						$("#allPopUpsInner").append(newstring);
						$.timer(200,function(){
							bindClickFeature();
						});
					}
					else{//as structure is ready, just add new content inside of target li-tag:
						var newstringArr=msg.match(pattern);
						var newHTML=get_string_between(newstringArr[index],'<li>','</li>');
						$("#temporaryLoad").html(newHTML);
						checkIframeLoading(index,newHTML);
					}
				}
				else if(id==='peopleEnlarge'){
					pattern2 = /<li>(.*?)<\/li>/g;
					var splitBY='<ul id="peopleBox">';
					var splitArr=msg.split(splitBY);
					var newstring=cleanHtml(splitArr[0]);
					
					if(index===undefined){//just get structure:
						newstring=newstring.replace(pattern2,'<li></li>');
						newstring=newstring.concat(splitBY,splitArr[1]);
						$("#allPopUpsInner").append(newstring);
						$.timer(200,function(){
							bindClickPeople();
						});
					}
					else{//as structure is ready, just add new content inside of target li-tag:
						var newstringArr=newstring.match(pattern2);
						var newHTML=get_string_between(newstringArr[index],'<li>','</li>');
						$("ul#peopleDetails li:eq("+index+")").html(newHTML);
					}
				}
			}
	   }
	 });
}

function toolTip(){
	$('#content_wrap > .thumbs a').live('mouseover', function(e){
		if( $(this).attr('title') != ''){
			$(this).data('title',$(this).attr('title') );
			parts = $(this).data('title');
			if(parts){
				parts = parts.split(':');
				$(this).data('tool_title', parts[0]);
				$(this).data('tool_text', parts[1]);
			}else{
				return false;
			}
		}
		$(this).removeAttr('title');
		
		$('#wrap').append('<div class="tooltip"><strong>'+$(this).data('tool_title')+'</strong><br/><p>'+$(this).data('tool_text')+'</p></div>');
		$('#wrap > .tooltip').css('bottom', 110 + 'px' ).css('left',(e.clientX -145)+ 'px' ).stop(true, true).fadeIn(775);
		return false;
	});
	$('#content_wrap > .thumbs a').live('mouseout', function(e){
		$('#wrap > .tooltip').stop(true, true).hide(function(){$(this).remove();});
		return false;
	});
	$('#content_wrap > .thumbs a:not([class^=visit])').live('click', function(){
		return false;
	});
	
	$('#services-features > li').hover(
		function(e){
			if($(this).hasClass('cur')){
				return false;
			}else{
				var service = $(this).attr('data-service');
				$('#wrap').append('<div class="tooltip2"><img src="'+service+'" /></div>');
				$('#wrap > .tooltip2').css('top',(wh*.2)+'px').css('left',($(this).offset().left -25)+ 'px' ).stop(true, true).fadeIn(775);

				return false;
			}
		},
		function(e){
			$('#wrap > .tooltip2').stop(true, true).hide(function(){$(this).remove();});
			return false;
		}
	);

}
function initSmallFooter(){
	$('#careers	.jspContainer').width(700);
	$('#careers	.jspPane').width(650);
	$('#careers	.gray-close-btn').css('right', '170px');	
	
	$('#press .scroll-pane').width(580);
	$('#press .jspContainer').width(570);
	$('#press .jspPane').width(500);
	$('#press .gray-close-btn').css('right', '70px');
	$('#press .right-cont').css('padding-right', '85px');
	
	
}
