 $(document).ready(function() {
							
//this preloads images for site
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  };
			
		
jQuery.preLoadImages("images/teamImage.jpg", "images/teamImage1.jpg", "images/teamImage2.jpg", "images/approachImage.jpg", "images/peets1.jpg", "images/nuggets.jpg", "images/skiing.jpg", "images/warrenMiller.jpg", "images/avalanche.jpg", "images/vibes.jpg", "images/a2b.jpg", "images/fieldandstream.jpg", "friendFormBack.png");
							
							
var current_tab = 'home';

var home_loaded = 'true';
var approach_loaded = '';
var team_loaded = '';
var services_loaded = '';
var clients_loaded = '';
var contact_loaded = '';
var presentPage = "home_content";
var present_tab = "home";
var current_tab = $.cookie('active');
var active = "home";
var pageLoaded = "null";
$('#' + current_tab).addClass('activeAnchor');


$.cookie('active', 'home');	

$(".testCase").mouseenter(testIn).mouseleave(testOut);
$(".testCase").click(function(){testCase();});

$("#active-bg").animate({backgroundColor:'#FFF',left: '0',width:'320'});
$(".nav").click(function(e) {
					 
var page_title = $(this).attr("title");	
var element_id = e.target.id;
current_tab = element_id;	
var slideLeft = "";
document.title = 'Movement Strategy :: ' + page_title;

$('#' + current_tab).addClass('activeAnchor');
$('#' + present_tab).removeClass('activeAnchor');


switch(current_tab) {
	case 'home': 
if(home_loaded != "true")
	{
		loadContent();
	}else {
	}
	loadHome();
	$.cookie('active', 'home');	

break;

case 'approach': 
if(approach_loaded != "true")
	{
		loadContent();
	}else {
	}
	loadApproach(); 
	$.cookie('active', 'approach');	

break;

case 'team':
if(team_loaded != "true")
	{
	loadContent();
	
	setTimeout(function() {  loadTeamImages();},500);
	}else 
	{
	}
	loadTeam();
	$.cookie('active', 'team');	
	var scook = $.cookie('active');
	
	
	
break;

case 'services': 
	
if(services_loaded != "true")
	{
		loadContent();
  loadServices();
	
	}else {
	loadServices();
	}
	$.cookie('active', 'services');	
break;


case 'clients':
if(clients_loaded != "true")
	{
loadContent();
loadClients();
	}else {
	loadClients();
	}
	$.cookie('active', 'clients');	
break;

case 'contact':
if(contact_loaded != "true")
	{
		loadContent();
	}
	loadContact();
	$.cookie('active', 'contact');
break;
case 'touch':
current_tab = 'contact';
$('#' + current_tab).addClass('activeAnchor');
if(contact_loaded != "true")
	{
		loadContent();
	}
	loadContact();
	$.cookie('active', 'contact');
break;

case 'blog': loadBlog();
break;
}
});

//load approach page and tab
function loadHome() {
	
	home_loaded = "true";
	$("#active-bg").animate({backgroundColor:'#FFF',left: '0',width:'320'}, 300, function() {
	
	slideHome() ;
	
	present_tab = "home";
	active = current_tab;
	
});
};


//load approach page and tab
function loadApproach() {
	approach_loaded = "true";
	$("#active-bg").animate({backgroundColor:'#bdec55',left: '355',width:'120'}, 300, function() {
	if(active == "home") {
		slidePageLeft() ;
	}else{
	slidePageRight() ;
	}
	present_tab = "approach";
	active = current_tab;
	
});
};



//load team page and tab
function loadTeam() {
	
	team_loaded = "true";
	$("#active-bg").animate({backgroundColor:'#90d5f6',left: '488',width:'80'}, 300, function() {
    
	if(active == "approach" || active == "home" ) {
	slidePageLeft() ;
	}else{
	slidePageRight() ;
	}
	present_tab = "team";
	active = current_tab;
	
	
  });
};


//load team page and tab
function loadServices() {
	//
	services_loaded = "true";
	$("#active-bg").animate({backgroundColor:'#f467b6',left: '660',width:'80'}, 300, function() {
    
	if(active == "approach" || active == "home" || active == "clients" || active == "team") {
		slidePageLeft() ;
	}else{
	slidePageRight() ;
	}
	present_tab = "services";
	active = current_tab;
  });
	
}


//load clients page and tab
function loadClients(){
	clients_loaded = "true";
$("#active-bg").animate({backgroundColor:'#fe620e',left: '584',width:'60'}, 300, function() {
    
	if(active == "team" || active == "approach" || active == "home"){
		slidePageLeft() ;
	}else{
	slidePageRight() ;
	}
	present_tab = "clients";
	active = current_tab;
  });
};


//load clients page and tab
function loadContact(){
$("#active-bg").animate({backgroundColor:'#e4f31e',left: '755',width:'95'}, 300, function() {
	
	slidePageLeft();
	present_tab = "contact";
	active = current_tab;
  });
};

//load clients page and tab
function loadBlog(){
$("#active-bg").animate({backgroundColor:'#e4f31e',left: '860',width:'60'}, 300, function() {
    loadContent();
	
	slidePageLeft();
	present_tab = "blog";
	active = current_tab;
  });
};


// Changes start by Harsh -- Use below function and comment the second
// loads content 
function loadContent() {
	
    $.get(current_tab + '/index.html', function(data) {
												
        var currentPage = current_tab + '_container';
        var content = $(data).find('#' + currentPage);
        content.appendTo('#content');
		$(content).hide();
        // or, just $(html).find('#approachContent').appendTo('#content');
        
    });
    
}
// Comment this one
/*function loadContent() {
    $.ajax( 
        { 
            url: current_tab + '/index.html', 
            success: function(data) {
										
                var currentPage = current_tab + '_container';
                var content = $(data).find('#' + currentPage);
                content.appendTo('#content');
                
		        $(content).hide();
		     
		   }
        }); 
}*/
// Changes end by Harsh

//slides page 
function slidePageLeft() {

	$('#' + presentPage).animate({left: '-1400'}, 700, 'easeOutQuint', function() {
    $('#' + presentPage).hide();
	$('#' + current_tab + '_container').addClass('pageLeft').show().animate({left: '0'}, 500, 'easeOutQuint');
	presentPage  = current_tab + '_container';
    
  });
};

//slides page 
function slidePageRight() {
	$('#' + presentPage).animate({left: '1400'}, 700, 'easeOutQuint', function() {
    $('#' + presentPage).hide();
	$('#' + current_tab + '_container').addClass('pageRight').show().animate({left: '0'}, 500, 'easeOutQuint');
	presentPage  = current_tab + '_container';
    
  });
};


function slideHome() {
	
	$('#' + presentPage).animate({left: '1400'}, 700, 'easeOutQuint', function() {
    $('#' + presentPage).hide();
	$('#' + current_tab + '_container').addClass('pageLeft').show().animate({left: '1400'}, 500, 'easeOutQuint');
	$('#home_content').show();
	presentPage  = current_tab + '_container';
    
  });
};


//cookies 
if(current_tab == 'services') {
	
	
	loadContent();
	loadServices();
	loadScroller();
}else if(current_tab == 'approach') {
	
	
	loadContent();
	loadApproach();
	
	
}else if(current_tab == 'team') {
	
	
	loadContent();
	loadTeam();
	
	setTimeout(function() {  loadTeamImages();},500);
	
	
}else if(current_tab == 'clients') {
	
	
	loadContent();
	loadClients();
	
}else if(current_tab == 'contact') {
	
	
	loadContent();
	loadContact();
	
}

function testIn() {
$('p', this).fadeIn();
}

function testOut() {
$('p', this).fadeOut();
}

function testCase() {
	current_tab = 'clients';
	$('#' + current_tab).addClass('activeAnchor');
if(clients_loaded != "true")
	{
loadContent();
loadClients();
	}else {
	loadClients();
	}
	$.cookie('active', 'clients');	

}

							
});


// team page js
var currentMember = "";
$(".member").live('mouseenter', teamNameIn).live('mouseleave', teamNameOut);

// Changes start by Harsh -- Replace old with this new function
function teamNameIn() {
	
	currentMember = $(this).attr('id'); 
	
	$('#memberName').show();
	$('#memberName').append(currentMember);
	var position, leftPosition;
		
	if(currentMember == 'jason') {
	    $('#memberName').css('left', '0');
	}else if(currentMember == 'eric') {
	    position = $('#eric').offset();
	    leftPosition = parseInt(position.left) - 100;
	    $('#memberName').css('left', leftPosition);
	
	}else if(currentMember == 'christy') {
	    position = $('#christy').offset();
	    leftPosition = parseInt(position.left) - 100;
		$('#memberName').css('left', leftPosition);
	}else if(currentMember == 'jared') {
	    position = $('#jared').offset();
	    leftPosition = parseInt(position.left) - 100;
		$('#memberName').css('left',leftPosition);
	}else if(currentMember == 'clay') {
	    position = $('#clay').offset();
	    leftPosition = parseInt(position.left) - 100;
		$('#memberName').css('left', leftPosition);
	}else if(currentMember == 'nick') {
	    position = $('#nick').offset();
	    leftPosition = parseInt(position.left) - 100;        
		$('#memberName').css('left', leftPosition);
	}else if(currentMember == 'caitlin') {
	    position = $('#caitlin').offset();
	    leftPosition = parseInt(position.left) - 100;
	    $('#memberName').css('left', leftPosition);
	}
	
};
// Changes end by Harsh

function teamNameOut() {
	$('#memberName').hide();
	$('#memberName').empty();

};


function loadTeamImages() {
var images = ['teamImage.jpg', 'teamImage1.jpg', 'teamImage2.jpg', 'teamImage3.jpg', 'teamImage4.jpg'];	
$('<img src="images/' + images[Math.floor(Math.random() * images.length)] + '">').appendTo('#teamGallery');
	
}

//client page js
var current_client = '';

$('.client').live('click', loadClient);

$('#prev').live('click', prevSlide);			  
						  
$('#next').live('click',nextSlide);			
$('.back').live('click',hideClientTest);		

$('.clientTest').live('click', showClientTest);		
$('#close').live('click', hideStudies);


function loadClient(e) {
	current_client = e.target.id;
	$("#caseStudies").fadeIn("normal");
	$('#' + current_client + '_study').fadeIn("normal");
	
	
}

function nextSlide() {
	$('#' + current_client + '_study').fadeOut("fast");
	switch(current_client) {
		case 'peets':
	 current_client = 'denverNuggets';
	break;
	case 'denverNuggets':
	 current_client = 'warrenMiller';
	break;
	
	case 'warrenMiller':
	current_client = 'skiing';
	break;
	
	case 'skiing':
	current_client = 'coloradoAvalanche';
	break;
	
	case 'coloradoAvalanche':
	current_client = 'vibes';
	break;
	
	case 'vibes':
	current_client = 'cu';
	break;
	
	case 'cu':
	current_client = 'fieldandstream';
	break;
	
	case 'fieldandstream':
	current_client = 'peets';
	break;
	}
	setTimeout(function() {   $('#' + current_client + '_study').fadeIn("slow"); },400);
	
}

function prevSlide() {
	$('#' + current_client + '_study').fadeOut("fast");
	switch(current_client) {
		case 'peets':
	 current_client = 'fieldandstream';
	break;
	
	case 'denverNuggets':
	 current_client = 'peets';
	break;
	
	case 'warrenMiller':
	current_client = 'denverNuggets';
	break;
	
	case 'skiing':
	current_client = 'warrenMiller';
	break;
	
	case 'coloradoAvalanche':
	current_client = 'skiing';
	break;
	
	case 'vibes':
	current_client = 'coloradoAvalanche';
	break;
	
	case 'cu':
	current_client = 'vibes';
	break;
	
	case 'fieldandstream':
	current_client = 'cu';
	break;
	}
	setTimeout(function() {   $('#' + current_client + '_study').fadeIn("slow"); },400);
	
	
}
function hideStudies() {
	
	$("#caseStudies").fadeOut("fast");
	$('#' + current_client + '_study').fadeOut("fast");
	
};
function showClientTest() {
	
	$('#' + current_client + '_study .studyContent .text').fadeOut('fast');	
	
	setTimeout(function() { $('#' + current_client + '_study .studyContent .test').fadeIn('normal');},300);
	
}

function hideClientTest() {
	
	$('#' + current_client + '_study .studyContent .test').fadeOut('fast');	
	
	setTimeout(function() { $('#' + current_client + '_study .studyContent .text').fadeIn('normal');},300);
	
}



//contact page js

$('#shareIcon').live('click', showform);	
$('#formClose').live('click', hideform);
function showform() {
$('#friendForm').show();

};

function hideform() {
$('#friendForm').hide();

};



//services page js
$('#more').live('click',scrollDown);	
$('#lastService').live('click',scrollUp);	
var scrollClick = '0';
function scrollDown() {
	
	if(scrollClick == '0') {
		$('#lastService').fadeIn('fast');
		$("#service").animate({top:'-205'}, 900, 'easeOutQuint');
		scrollClick = '1';
	}else if(scrollClick == '1') {
		scrollClick = '2';
		$("#service").animate({top:'-405'}, 900, 'easeOutQuint');
	}
	else if(scrollClick == '2') {
		scrollClick = '3';
		$("#service").animate({top:'-600'}, 900, 'easeOutQuint');
	}else if(scrollClick == '3') {
		$("#service").animate({top:'-800'}, 900, 'easeOutQuint');
		$("#more").hide();
		$("#serviceEnd").show();
		scrollClick = '4';
	}
	
			
};

function scrollUp() {
	
	if(scrollClick == '4') {
		$('#lastService').fadeIn('fast');
		$("#serviceEnd").hide();
		$("#more").show()
		$("#service").animate({top:'-600'}, 900, 'easeOutQuint');
		scrollClick = '3';
	}else if(scrollClick == '3') {
		$("#service").animate({top:'-405'}, 900, 'easeOutQuint');
		scrollClick = '2';
	}else if(scrollClick == '2') {
		$("#service").animate({top:'-205'}, 900, 'easeOutQuint');
		scrollClick = '1';
	}else if(scrollClick == '1') {
		scrollClick = '0';
		$("#service").animate({top:'20'}, 900, 'easeOutQuint');
		$('#lastService').fadeOut('fast');
	}
	
			
};

// Changes start by Harsh -- Replace with this one
var iScroll = 0;			
$('#team_container').live('mouseenter', function(){
    if(iScroll == 0)
    {
        initScrollLayer1();
        iScroll = 1;
    }    
});

function initScrollLayer1() {
   
    var wndo = new dw_scrollObj('wn', 'lyr1', 't1');
    dw_scrollObj.GeckoTableBugFix('wn');
} 			
			
// Changes end by Harsh			
