// MAIN SITE NAV MENU EFFECTS

function loadSiteNavMenus() {

	// TOP MENU

	var traitsActive=new Boolean();
	var envActive=new Boolean();
	var connectActive=new Boolean();
	
	// clears dropdowns
	$('#topNav_menu_work').hide();
	$("#topNav_btn_work").attr({ src : 'images/nav_work.png'});
	$('#topNav_menu_traits').hide();
	$("#topNav_btn_traits").attr({ src : 'images/nav_what.png'});
	$('#topNav_menu_env').hide();
	$("#topNav_btn_env").attr({ src : 'images/nav_about.png'});
	$('#topNav_menu_blogs').hide();
	$("#topNav_btn_blogs").attr({ src : 'images/nav_blogs.png'});
	$("#topNav_btn_connect").attr({ src : 'images/nav_connect.png'});
	
	// Work Dropdown
			$("#work_container").hover(
				function () {
					$('#topNav_menu_work').show();
					$("#topNav_btn_work").attr({ src : 'images/nav_workActive.png'});
				}, 
				function () {
					$('#topNav_menu_work').hide();
					$("#topNav_btn_work").attr({ src : 'images/nav_work.png'});
				}
			);
	
		// Traits Dropdown
			$("#traits_container").hover(
				function () {
					$('#topNav_menu_traits').show();
					$("#topNav_btn_traits").attr({ src : 'images/nav_whatActive.png'});
				}, 
				function () {
					$('#topNav_menu_traits').hide();
					$("#topNav_btn_traits").attr({ src : 'images/nav_what.png'});
				}
			);
	
		// Environment Button
			$("#env_container").hover(
				function () {
					$('#topNav_menu_env').show();
					$("#topNav_btn_env").attr({ src : 'images/nav_aboutActive.png'});
				}, 
				function () {
					$('#topNav_menu_env').hide();
					$("#topNav_btn_env").attr({ src : 'images/nav_about.png'});
				}
			);
			
			// Blogs button
				$("#blogs_container").hover(
					function () {
						$('#topNav_menu_blogs').show();
						$("#topNav_btn_blogs").attr({ src : 'images/nav_blogsActive.png'});
					}, 
					function () {
						$('#topNav_menu_blogs').hide();
						$("#topNav_btn_blogs").attr({ src : 'images/nav_blogs.png'});
					}
				);
	
		// Connect Button
			$("#connect_container").hover(
				function () {
					//$('#topNav_menu_connect').show();
					$("#topNav_btn_connect").attr({ src : 'images/nav_connectActive.png'});
				}, 
				function () {
					//$('#topNav_menu_connect').hide();
					$("#topNav_btn_connect").attr({ src : 'images/nav_connect.png'});
				}
			);
	
	
	
	// BOTTOM MENU
	
		// Large Footer Menu
			$("#bottomNav_app").hover(
				function () { $(this).attr({ src : 'images/nav_appOver.jpg'}); }, 
				function () { $(this).attr({ src : 'images/nav_app.jpg'});
			});	
			$("#bottomNav_website").hover(
				function () { $(this).attr({ src : 'images/nav_websiteOver.jpg'}); }, 
				function () { $(this).attr({ src : 'images/nav_website.jpg'});
			});	
			$("#bottomNav_hosting").hover(
				function () { $(this).attr({ src : 'images/nav_hostingOver.jpg'}); }, 
				function () { $(this).attr({ src : 'images/nav_hosting.jpg'});
			});	
			$("#bottomNav_help").hover(
				function () { $(this).attr({ src : 'images/nav_helpOver.jpg'}); }, 
				function () { $(this).attr({ src : 'images/nav_help.jpg'});
			});	
			
		// Small Footer Menu
			$("#bottomnavSmall_app").hover(
				function () { $(this).attr({ src : 'images/navSmall_appOver.jpg'}); }, 
				function () { $(this).attr({ src : 'images/navSmall_app.jpg'});
			});	
			$("#bottomnavSmall_website").hover(
				function () { $(this).attr({ src : 'images/navSmall_websiteOver.jpg'}); }, 
				function () { $(this).attr({ src : 'images/navSmall_website.jpg'});
			});	
			$("#bottomnavSmall_hosting").hover(
				function () { $(this).attr({ src : 'images/navSmall_hostingOver.jpg'}); }, 
				function () { $(this).attr({ src : 'images/navSmall_hosting.jpg'});
			});	
			$("#bottomnavSmall_help").hover(
				function () { $(this).attr({ src : 'images/navSmall_helpOver.jpg'}); }, 
				function () { $(this).attr({ src : 'images/navSmall_help.jpg'});
			});

}


// NEWS TICKER

function newsTickerGo() {
	$.ajax({
		type: "GET",
		url: "xml/newsTicker.xml",
		dataType: "xml",
		success: function(xml) {
		
			$(xml).find('newsPost').each(function() {
				var newsPost = $(this);

				var date = newsPost.find('date').text();
				var title = newsPost.find('title').text();
				var link = newsPost.find('link').text();
				
				if (link) {
					var newsPosts = '<li><div class="newsPost"><p><strong>&bull;</strong> <span>' + date + '</span> <a href="'+link+'" target="_blank">' + title + '</a></p></div></li>';
				} else {
					var newsPosts = '<li><div class="newsPost"><p><strong>&bull;</strong> <span>' + date + '</span> ' + title + '</p></div></li>';
				}

				//var newsPosts = '<li><div class="newsPost"><p><strong>&bull;</strong> <span>' + date + '</span> ' + title + '</p></div></li>';

				$('#newsTicker ul').append(newsPosts).newsTicker();

			});

		}
	});
}

// WORK PORTFOLIO MINI-APP

function createWorkPortfolio(featuredProjectType,featuredClientBtnId) {
	
	var featuredProjectType;
	var featuredClientBtnId;
	
	//Load Accordion jQuery plugin (
	$("#accordion").accordion({
		event: 'click',
		header: "h3",
		fillSpace: true,
                active: 2
                
	});
	
	$.ajax({
		type: "GET",
		url: "xml/workPortfolio.xml",
		dataType: "xml",
		success: function(xml) {
			
			$('li.projectTypeContainer').each(function() {
				
				//Array of project types from divs in HTML (on work.php)
				var projectType = $(this).find('h3').attr('id');
				
                                
				$(xml).find(projectType).each(function() {
                                    
					var firstProject = $(this).find(":first");
					var firstProjectIdName = firstProject.attr('idName');
                                        
					
					// Bind onclick events to PROJECT TYPE ACCORDION BARS:
					$('#'+projectType).click( function () {
						
						//Load content for first project in Project Type onclick
						$('#'+firstProjectIdName).trigger('click');
						
					});
					
				
					$(this).find('project').each(function() {
						var project = $(this);
						
						//Project Buttons
						var projIdName = project.attr('idName');
						var projIdBtn  = project.attr('button');
						
						
						//Main SlideView content items
						var projectContentItems = project.find('slideviewerContent').children();
						
						
						//Bottom Nav
						var name = project.find('name').text();
						var story = project.find('story').text();
						var otherWorkItems = project.find('otherWork').children();
						var seeItLiveSites = project.find('seeItLive').children();
						
						
						//////////////////////////////////////////////////////////////////////////////////////
						// Create new LI tags and Image buttons for each <project> in each Project Type tag //
						// (e.g. <sites>, <commerce>, etc.) in workPortfolio.xml                            //
						//////////////////////////////////////////////////////////////////////////////////////
						$('#'+projectType+'+div ul').append(
							'<li><img src="images/content/work/buttons/projects/' + projIdBtn + '.png" id="' + projIdName + '" class="" /></li>'
						);
						
						// Bind hover events to new buttons
						$('#'+projIdName).mouseover( function () {
							if (!$(this).hasClass("active")) {
								$(this).attr({ src : 'images/content/work/buttons/projects/' + projIdBtn +'_over.png'});
							}
						});
						$('#'+projIdName).mouseout( function () {
							if (!$(this).hasClass("active")) {
								$(this).attr({ src : 'images/content/work/buttons/projects/' + projIdBtn +'.png'});
							}
						});
						
						
						/////////////////////////////////////////////
						// Bind onclick events to PROJECT BUTTONS: //
						//	   ->on click...                       //
						/////////////////////////////////////////////
						$('#'+projIdName).click( function () {
						
						
							// 1. Set active image, class; remove active image, class from all other buttons
								$(this)
									.attr({ src : 'images/content/work/buttons/projects/' + projIdBtn +'_active.png'})
									.addClass("active");
								
								$("#accordion").find("img").not($(this))
									.attr("src", function() { return this.src.replace(/_active\.png/i,".png") })
									.removeClass("active");
							
							// 2. Clear contents of Other Work and See It Live lists
								$('#bottomNav_menu_otherwork ul').empty();
								$('#bottomNav_menu_seeitlive ul').empty();
						
							// 3. Load copy for project into bottom tab popup divs
							
								// ********* Story Tab **********
								$('#bottomNav_menu_story h4').html(name);
								$('#bottomNav_menu_story p').html(story);
								
								// ********* Other Work Tab *********
								if ($(otherWorkItems).length > 0) {
								
									// -> Load Other Work Panel Hover
									$("#bottomNav_btn_otherwork").attr({ src : 'images/otherworkBtn.png'});
									$("#otherwork_container").hover(
										function () {
											$("#bottomNav_btn_otherwork").attr({ src : 'images/otherworkActive.png'});			
											$('#bottomNav_menu_otherwork').fadeIn("fast");
										}, 
										function () {
											$("#bottomNav_btn_otherwork").attr({ src : 'images/otherworkBtn.png'});
											$('#bottomNav_menu_otherwork').fadeOut("fast");
									});
									
									// -> Load Content
									$('#bottomNav_menu_otherwork h5 span').html(name);
									$(otherWorkItems).each(function() {
									
										var relatedProjectType = $(this).attr('type');
										var relatedProject = $(this).text();
										
										$('#bottomNav_menu_otherwork ul').append(
											'<li><img src="images/content/work/buttons/' + relatedProjectType + 'Btn.png" id="' + relatedProject + 'OtherWork" /></li>'
										);
										
										// **Bind onclick events to new buttons**
										$('#'+relatedProject+'OtherWork').click( function () {
											
											//Activate accordion project type and "click" project button
											$('#accordion').accordion('activate', '#'+relatedProjectType);
											$('#'+relatedProject).trigger('click');
											
											//Hide Other Work container, change Active button back
											$('#bottomNav_menu_otherwork').hide();
											$("#bottomNav_btn_otherwork").attr({ src : 'images/otherworkBtn.png'});
										});
										
										// **Bind hover events to new buttons**
										$('#'+relatedProject+'OtherWork').hover(
											function () { $(this).attr({ src : 'images/content/work/buttons/' + relatedProjectType +'Btn_over.png'}) },
											function () { $(this).attr({ src : 'images/content/work/buttons/' + relatedProjectType +'Btn.png'}) }
										);
										
									});
								
								} else {
									$('#bottomNav_btn_otherwork').attr({ src : 'images/otherworkBtnInactive.png'});
									$("#otherwork_container").unbind();
								}
								
								// ********* See It Live Tab *********
								if ($(seeItLiveSites).length > 0) {
								
									// -> Load See It Live Panel Hover
									$("#bottomNav_btn_seeitlive").attr({ src : 'images/seeitliveBtn.png'});
									$("#seeitlive_container").hover(
										function () {
											$("#bottomNav_btn_seeitlive").attr({ src : 'images/seeitliveActive.png'});			
											$('#bottomNav_menu_seeitlive').fadeIn("fast");
										}, 
										function () {
											$("#bottomNav_btn_seeitlive").attr({ src : 'images/seeitliveBtn.png'});
											$('#bottomNav_menu_seeitlive').fadeOut("fast");
									});
									
									// -> Load content
									$(seeItLiveSites).each(function() {
										var siteURL = $(this).text();
										
										$('#bottomNav_menu_seeitlive ul').append(
											'<li><a href="http://' + siteURL + '" target="_blank">' + siteURL + '</a></li>'
										);
									});
									
								} else {
									$('#bottomNav_btn_seeitlive').attr({ src : 'images/seeitliveBtnInactive.png'});
									$("#seeitlive_container").unbind();
								}
							
							// 4. Clear current items in content (<ul>) list for slideshow content, set slideshow position to "0" (showing first image)
								$('ul#mainContentContainerList').empty().css("left","0");
							
							// 5. Load new list of images from XML
								$(projectContentItems).each(function() {
									$('ul#mainContentContainerList').append(
										'<li><img src="images/content/work/' + projectType + '/' + projIdName + '/' + $(this).text() + '" /></li>'
									);
								});
							
							// 6. Remove slideshow nav buttons and call slideView method to regenerate the slideshow for the project clicked
								$("div#stripTransmitter").remove();
								$("div#portfolioContentWindow").slideView();

						});
						
					}); // close $(this).find('project').each(
				});  //close $(xml).find(projectType).each(
			
			}); //close $('li.projectTypeContainer').each(
			
			if ( !featuredProjectType && !featuredClientBtnId ) {
                                
				featuredProjectType = '#'+$(xml).find('featured projectType').text();
				featuredClientBtnId = '#'+$(xml).find('featured projectIdName').text();
			}
                        
			$('#accordion').accordion('activate', featuredProjectType);
			$(featuredClientBtnId).trigger('click');
                        
                     
    
			
		}
	}); //close $.ajax(
	
    
        
        
	// Load Bottom Story Tab/Panel Hover

		$("#story_container").hover(
			function () {
				$("#bottomNav_btn_story").attr({ src : 'images/storyActive.png'});			
				$('#bottomNav_menu_story').fadeIn("fast");
			}, 
			function () {
				$("#bottomNav_btn_story").attr({ src : 'images/storyBtn.png'});
				$('#bottomNav_menu_story').fadeOut("fast");
		});
	
}


// ENVIRONMENT MINI-APP

function createEnvPortfolio(featuredProjectType,featuredSectionBtnId) {
	
	var featuredProjectType;
	var featuredSectionBtnId;
	
	//Load Accordion jQuery plugin (
	$("#accordion").accordion({
		event: 'click',
		header: "h3",
		fillSpace: true
	});
	
	$.ajax({
		type: "GET",
		url: "xml/envPortfolio.xml",
		dataType: "xml",
		success: function(xml) {
		
			$('li.projectTypeContainer').each(function() {
				
				//Array of project types from divs in HTML (on environment.php)
				var projectType = $(this).find('h3').attr('id');
				
				$(xml).find(projectType).each(function() {
				
					var firstProject = $(this).find(":first");
					var firstProjectIdName = firstProject.attr('idName');
					
					// Bind onclick events to PROJECT TYPE ACCORDION BARS:
					if (firstProject.attr('button')) {
						$('#'+projectType).click( function () {
							
							//Load content for first project in Project Type onclick
                                                     
							$('#'+firstProjectIdName).trigger('click');
							
						});
					}
				
					$(this).find('project').each(function() {
						var project = $(this);
						
						//Project Buttons
						var projIdName = project.attr('idName');
						var projIdBtn  = project.attr('button');
						
						
						
						//Main SlideView content items
						var projectContentItems = project.find('slideviewerContent').children();
						
						
						//Bottom Nav (for "Leaders" only)
						var name = project.find('name').text();
						var leaderBio = project.find('bio').text();
												
						
						if (projIdBtn) {
						
							// Create new LI tags and Image buttons for each <project> in each Project Type tag (e.g. <sites>, <commerce>, etc.) in envPortfolio.xml
							$('#'+projectType+'+div ul').append(
								'<li><img src="images/content/env/buttons/' + projIdBtn + '.png" id="' + projIdName + '" class="" /></li>'
							);
							
							// Bind hover events to new buttons
							$('#'+projIdName).mouseover( function () {
								if (!$(this).hasClass("active")) {
									$(this).attr({ src : 'images/content/env/buttons/' + projIdBtn + '_over.png'});
								}
							});
							$('#'+projIdName).mouseout( function () {
								if (!$(this).hasClass("active")) {
									$(this).attr({ src : 'images/content/env/buttons/' +  projIdBtn + '.png'});
								}
							});
							
							
							//Bind onclick events to new buttons:
							//	on click...
							$('#'+projIdName).click( function () {
							
								// 1. Set active image, class; remove active image, class from ALL other buttons in the accordian
									$(this)
										.attr({ src : 'images/content/env/buttons/' + projIdBtn + '_active.png'})
										.addClass("active");
									
									$("#accordion").find("img").not($(this))
										.attr("src", function() { return this.src.replace(/_active\.png/i,".png") })
										.removeClass("active");
								
								// 2. Show "Story" Tab
									$('#story_container').show();
							
								// 3. Load copy for project into bottom nav button popup divs
									$('#bottomNav_menu_story h4').html(name);
									$('#bottomNav_menu_story p').html(leaderBio);
								
								// 4. Clear current items in content (<ul>) list for slideshow content, set slideshow position to "0" (showing first image)
									$('ul#mainContentContainerList').empty().css("left","0");
								
								// 5. Load new list of images from XML
									$(projectContentItems).each(function() {
										$('ul#mainContentContainerList').append(
											'<li><img src="images/content/env/' + projIdName + '/' + $(this).text() + '" /></li>'
										);
									});
								
								// 6. Remove slideshow nav buttons and call slideView method to regenerate the slideshow for the project clicked
									$("div#stripTransmitter").remove();
									$("div#portfolioContentWindow").slideView();
	
							});
						}
						else {
							
							$('#'+projectType).click( function () {
								
								// 1. Hide "Story" Tab
									$('#story_container').hide();
								
								// 2. Remove active image, class from all buttons in the accordian
									$("#accordion").find("img")
										.attr("src", function() { return this.src.replace(/_active\.png/i,".png") })
										.removeClass("active");
								
								// 3. Clear current items in content (<ul>) list for slideshow content, set slideshow position to "0" (showing first image)
									$('ul#mainContentContainerList').empty().css("left","0");
								
								// 4. Load new list of images from XML
									$(projectContentItems).each(function() {
										$('ul#mainContentContainerList').append(
											'<li><img src="images/content/env/' + projectType + '/' + $(this).text() + '" /></li>'
										);
									});
								
								// 5. Remove slideshow nav buttons and call slideView method to regenerate the slideshow for the project clicked
									$("div#stripTransmitter").remove();
									$("div#portfolioContentWindow").slideView();
								
							});
						}
						
					}); // close $(this).find('project').each(
				});  //close $(xml).find(projectType).each(

			}); //close $('li.projectTypeContainer').each(
			
			if ( !featuredProjectType ) {
				featuredProjectType = '#'+$(xml).find('featured projectType').text();
			}

			$('#accordion').accordion('activate', featuredProjectType);
			$(featuredProjectType).trigger('click');
			
		}
	}); //close $.ajax(
	
	// Load Bottom Story Tab/Panel Hover
	
		$("#story_container").hover(
			function () {
				$("#bottomNav_btn_story").attr({ src : 'images/storyActive.png'});			
				$('#bottomNav_menu_story').fadeIn("fast");
			}, 
			function () {
				$("#bottomNav_btn_story").attr({ src : 'images/storyBtn.png'});
				$('#bottomNav_menu_story').fadeOut("fast");
		});	
}

function servicesTickerGo() {

	var ticker = $("#servicesTicker dl");
	  
	//wrap dt:dd pairs in divs
	ticker.children().filter("dt").each(function() {
	  
	  var dt = $(this),
		container = $("<div>");
	  
	  dt.next().appendTo(container);
	  dt.prependTo(container);
	  
	  container.appendTo(ticker);
	});
			
	//hide the scrollbar
	ticker.css("overflow", "hidden");
	
	//animator function
	function animator(currentItem) {
		
	  //work out new anim duration
	  var distance = currentItem.height();
		duration = (distance + parseInt(currentItem.css("marginTop"))) / 0.025;

	  //animate the first child of the ticker
	  currentItem.animate({ marginTop: -distance }, duration, "linear", function() {
		
		//move current item to the bottom
		currentItem.appendTo(currentItem.parent()).css("marginTop", 0);

		//recurse
		animator(currentItem.parent().children(":first"));
	  }); 
	};
	
	//start the ticker
	animator(ticker.children(":first"));
			
	//set mouseenter
	ticker.mouseenter(function() {
	  
	  //stop current animation
	  ticker.children().stop();
	  
	});
	
	//set mouseleave
	ticker.mouseleave(function() {
			  
	  //resume animation
	  animator(ticker.children(":first"));
	  
	});

}



