// JavaScript Document

$(document).ready(function(){	

	$(".field_name").focus(function(){
		if(this.value==this.defaultValue){
			this.value="";
		}
	}).blur(function(){
		if(this.value==""){
			this.value=this.defaultValue
		}
	});
	$(".field_email").focus(function(){
		if(this.value==this.defaultValue){
			this.value="";
		}
	}).blur(function(){
		if(this.value==""){
			this.value=this.defaultValue
		}
	});
	$(".field_question").focus(function(){
		if(this.value==this.defaultValue){
			this.value="";
		}
	}).blur(function(){
		if(this.value==""){
			this.value=this.defaultValue
		}
	});
	
	if(document.getElementById('askHaroldForm')){
		jQuery.validator.addMethod("defaultvalue", function(value, element) { 
			if (value == element.defaultValue)
				return false;
			return true;
		}, "This field is required");
		
		$("#askHaroldForm").validate({
			focusInvalid: false,
			rules: {
				name: {
					required: true,
					defaultvalue: true
				},
				email: {
					required: true,
					email: true
				},
				question: {
					required: true,
					defaultvalue: true
				}
			}
		});
	}
});
// 'ask harold' dropdown, using carousel with empty node on initial state
var carousel;
function initCaro(){
	var hblink = document.getElementById('askHB');
	$('#mycarousel').jcarousel({
		initCallback: function(obj,b){ carousel = obj; },
		vertical: true,
		scroll: 1,
		visible: 1,
		start: 2,
		buttonNextHTML: null,
		buttonPrevHTML: null,
		itemVisibleInCallback: {
			onBeforeAnimation: function(a,b,num,state){ 
				if(num == 1){
					 $('.jcarousel-skin-tango').css('visibility','visible');
					hblink.href = 'javascript:carousel.next()';	
					hblink.parentNode.className = 'active';	 
				 }
			},
			onAfterAnimation:  function(a,b,num,state) { 
				if(num == 2){ 
					$('.jcarousel-skin-tango').css('visibility','hidden'); 
					hblink.href = 'javascript:carousel.prev()';
					hblink.parentNode.className = '';		
				}	
			}
		}
	});
}
//blog feed using google rss api
function getBlog(){
      google.load("feeds", "1");
      google.setOnLoadCallback(blogParse);
}
var monthArray = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
function blogParse(){
	var blogString = "";
	var feed = new google.feeds.Feed("http://www.burson-marsteller.com/Innovation_and_insights/blogs_and_podcasts/harold_burson_blog/_layouts/listfeed.aspx?List={6D4DBC50-37E1-4C20-8040-703259FDDD1F}&View=2fdc2737-b681-410e-b05a-070ab1f5cfc0");
	feed.setNumEntries(15);
	feed.load(function(result) {
		if (!result.error) {
			var container = document.getElementById("blogarea");
			for (var i = 0; i < result.feed.entries.length; i++) {
				var entry = result.feed.entries[i];
				var theDate = new Date(entry.publishedDate);
				var content =
				"<h2><a target=\"_blank\" href=\""+ entry.link +"\" title=\""+ entry.title +"\">"+ entry.title +"</a></h2>\n" + 
				"<h3>" + monthArray[theDate.getMonth()] + " " + theDate.getDate() + " " + theDate.getFullYear() + "</h3>" +
				"<div class=\"itemCont\">" + entry.content + "</div>";
				blogString += content;
			}
			container.innerHTML = blogString;
			$('#blogarea p').removeAttr('style');
			$('#blogarea p').css('margin', '0');
			$('#blogarea font').removeAttr('size');
			$('#blogarea span').removeAttr('style');
			$('#blogarea font').removeAttr('face');  
			$('.itemCont').find('b:first').css('display','none');
		}
	});
}
function getYouTubeContent(){
      google.load("feeds", "1");
      google.setOnLoadCallback(youtubeContent);
}
function youtubeContent(){
	var blogString = "";
	var feed = new google.feeds.Feed("http://gdata.youtube.com/feeds/api/users/bursonmarsteller/uploads");
	feed.setResultFormat(google.feeds.Feed.XML_FORMAT);
	feed.setNumEntries(100);
	feed.load(function(result) {
		var container = document.getElementById("feed");
		if (!result.error) {
			var entries = google.feeds.getElementsByTagNameNS(result.xmlDocument, "http://www.w3.org/2005/Atom", "entry");
			for (var i = 0; i < entries.length; i++) {
				var titleElement = google.feeds.getElementsByTagNameNS(entries[i], "http://www.w3.org/2005/Atom", "title")[0];
				var title = titleElement.firstChild.nodeValue;
				
				//var descriptionElement = google.feeds.getElementsByTagNameNS(entries[i], "http://www.w3.org/2005/Atom", "content")[0];
				//var description = descriptionElement.firstChild.nodeValue;
				
				var linkElement = google.feeds.getElementsByTagNameNS(entries[i], "http://www.w3.org/2005/Atom", "id")[0];
				var link = linkElement.firstChild.nodeValue;
				
				var linkArray = link.split("/");
				link = linkArray[linkArray.length - 1];
				blogString += "<li title=\"" +title+"\" onclick=\"loadVideo('" + link + "')\"><img src=\"http://i.ytimg.com/vi/" + link + "/default.jpg\"/></li>";
				
			} 
			document.getElementById('loadVideosHere').innerHTML = blogString;
			initVideoPlayer();
		}
	}); 
}
function loadVideo(eleven){
	var flashvars = {};
	var params = {
		wmode: "transparent"
	};
	var attributes = {};
	attributes.id = 'youtubeplayer-video';
	$('#youtubeplayer').fadeOut(0);
	swfobject.embedSWF("http://www.youtube.com/v/" + eleven + "&autoplay=1&rel=0", 'youtubeplayer-video', "640", "388", "9.0.115", "<?php bloginfo('template_directory'); ?>swf/expressInstall.swf", flashvars, params, attributes);
	$('#youtubeplayer').fadeIn('slow');
	location.hash = eleven;
}
function initVideoPlayer(){
	var o = {enableMouse: false};
	$(".myJac").jac(o);
	if(location.hash.length < 1){
		$("#loadVideosHere li:nth-child(2)").click();
	}else{
		loadVideo(location.hash.substr(1));
	}
	
	$("#loadVideosHere li img").hover(
	function(){
		$(this).addClass('hoverS');
	},
	function(){
		$(this).removeClass('hoverS');
	});
	$("#loadVideosHere li img").click(function(){
		$("#loadVideosHere li img").removeClass('active');
		$(this).addClass('active');
	});
}



