// BroadVision.com javascript

// 2009.06.30: JONP Added to animate logos.
var animate_t;
function animateLogos() {
   var logoDiv = $('#scrolling_logos');
   var customerLinks = $('a', logoDiv);
   $('a:last', logoDiv).after(customerLinks[0]);
   animate_t = setTimeout("animateLogos()", 5000);
}

$(document).ready(function(){
						   
	// Cufon font replacement
	Cufon.replace('#nav-top > ul > li > a')('#home #content_main h2')('#row_1 .feature h2, {hover: true}');
						   
$('#keyword').each(function() {
    var default_value = this.value;
    $(this).css('color', '#666'); // this could be in the style sheet instead
    $(this).focus(function() {
        if(this.value == default_value) {
            this.value = '';
            $(this).css('color', '#333');
        }
    });
    $(this).blur(function() {
        if(this.value == '') {
            $(this).css('color', '#666');
            this.value = default_value;
        }
    });
});

$('#nav-language').bind('click',function(event) {
	$(this).toggleClass('open');								 
});

$('#select_language').bind('click',function(event) {
	$('#nav-language').toggleClass('open');								 
});

    $('#nav-top li li ul').parent().addClass('parent');
	
	var relatedContentHeight = $('#related_content ul').height();
	if (relatedContentHeight > 388) {
		$('#related_content ul').not('#related_content ul ul').addClass('tall');
	} else if (relatedContentHeight > 264) {
		$('#related_content ul').not('#related_content ul ul').addClass('medium');
	} else if (relatedContentHeight > 75) {
		$('#related_content ul').not('#related_content ul ul').addClass('small');
	} else {
		$('#related_content ul').not('#related_content ul ul').addClass('xsmall');
	} 
	


// Get url of current page. Find subnav item which points to current url and give the LI a class of "current
	// and the parent LI a class of "open". This will make it show you can show the currently selected page and 
	// can open the section it lives under.
	var path = location.pathname.substring(location.pathname.lastIndexOf("/") + 1, location.pathname.length);
	var locPath = location.pathname;
	if ((path.length > 1) && (path.indexOf("cnt_")==0)) {
	   locPath = locPath.substring(0, locPath.lastIndexOf("/"));
	}
	
	if ( path.length > 1 ) {
	   $('#content_secondary #nav-sub a[href="' + locPath + '"]').each(function() {
		  $(this).parents('#nav-sub > ul > li > ul > li').addClass('open');
		  $(this).parent().addClass('current');
		});
	}	 
	 
	$('#nav-sub li.open').append('<div class="inner bottom"></div>').prepend('<div class="inner top"></div>');
	$('#connect_with_us').prepend('<div class="inner"></div>');
	$('#learn_more').append('<div class="inner"></div>');
	$('#url_block a').append('<span class="inner"></span>');
	$('#featured_blog_post').append('<div class="inner bottom"></div>').prepend('<div class="inner top"></div>');
	$('#row_1').append('<div class="inner bottom"></div>');
	
	var contentImgPath = $('#MainGraphic').children('img').attr('src');
	if (contentImgPath) {
		var contentImgHeight = $('#MainGraphic').children('img').height();
		$('#MainGraphic').empty().css({'height':contentImgHeight,'background-image':'url(' + contentImgPath + ')'});
	}
/*	var homeImgPath = $('#billboard img').attr('src');
	var homeImgHeight = $('#billboard img').height();
	$('#billboard').empty().css({'height':homeImgHeight,'background-image':'url(' + homeImgPath + ')'});
*/	
	
    /* 2009.06.30: JONP added to animate logos */
    animate_t = setTimeout("animateLogos()", 5000);

    /*
			$('#featured_customers ul li').each(function() {
				$(this).cycle({random: 1, delay: -4000});
			});
	*/		
			// Wrap the images in divs
			$('#billboard').wrapInner('<div class="inner"></div>');
				if ($(window).width() >= 960) {
			// Set the width of #billboard to the width of the window
					$('#billboard').width($(window).width());
					// Give the divs inside #billboard a negative left margin
					// equal to half the difference between the billboard and window widths
					$('#billboard div.inner').css('margin-left', getWidth());
				} else {
					$('#billboard').width(960);
					// Give the divs inside #billboard a negative left margin
					// equal to half the difference between the billboard and window widths
					$('#billboard div.inner').css('margin-left', -520);
				}
			// Apply cycle to the billboard
			$('#billboard div').each(function() {
				$(this).before('<div id="pager">').cycle({ 
					delay: -4000, speed: 800, pager:'#pager', timeout:9000, width:getWidth()
				});
			});
			
			$('#pager').appendTo('#header');
/*			var pager_wrapDiff = ($(window).width() - 960)/2;
			if (pager_wrapDiff > 0) {
				$('#pager_wrap').css({'margin-left':pager_wrapDiff,'margin-right':pager_wrapDiff,'background':'red'});
				alert($('#pager_wrap').width());
			}
*/			
			
			// Resize with width of #billboard and reapply the negative left margin to .inner on window resize
			$(window).bind('resize', function() {
				if ($(window).width() >= 960) {
					$('#billboard').width($(window).width());
					$('#billboard div.inner').css('margin-left', getWidth());
				} else {
					$('#billboard').width(960);
					$('#billboard div.inner').css('margin-left', -520);
				}
			});
			
			function getWidth() {
				var windowWidth = $(window).width();
				var difference = -(2000 - windowWidth)/2;
				return difference;
			}
});
