$(document).ready(function(){

			  var videoThumb = ('<img class="loaded_video" src="/idf/pix/video/tn_barrett2.jpg" />');
			  $('.speaker-a').empty();
			  $('.speaker-a').prepend(videoThumb);
			  $('.speaker-a').removeAttr('href');

		
		$('#vid-videos-collection .content-item a.speaker-a').click(function() {
			$('.speaker-a').removeAttr('href');
			$('.speaker-b').attr('href','#');
			$('.speaker-c').attr('href','#');
		$(this).children().hide();
		$(this).prepend('<img src="/idf/pix/video/tn_barrett2.jpg" />');
		$('.speaker-b,.speaker-c').empty();
		$('.speaker-b').prepend('<img src="/idf/pix/video/tn_gelsinger.jpg" />');
		$('.speaker-c').prepend('<img src="/idf/pix/video/tn_chandrashaker.jpg" />');
		  });
		  
		  $('#vid-videos-collection .content-item a.speaker-b').click(function() {
			$('.speaker-b').removeAttr('href');
			$('.speaker-a').attr('href','#');
			$('.speaker-c').attr('href','#');
		  	$(this).children().hide();
			$(this).prepend('<img src="/idf/pix/video/tn_gelsinger2.jpg" />');				
			$('.speaker-a,.speaker-c').empty();	
			$('.speaker-a').prepend('<img src="/idf/pix/video/tn_barrett.jpg" />');			
			$('.speaker-c').prepend('<img src="/idf/pix/video/tn_chandrashaker.jpg" />');			
		  });
		  
		  $('#vid-videos-collection .content-item a.speaker-c').click(function() {
			$('.speaker-c').removeAttr('href');
			$('.speaker-a').attr('href','#');
			$('.speaker-b').attr('href','#');
			$(this).children().hide();
			$(this).prepend('<img src="/idf/pix/video/tn_chandrashaker2.jpg" />');				

			$('.speaker-a,.speaker-b').empty();	
			$('.speaker-a').prepend('<img src="/idf/pix/video/tn_barrett.jpg" />');			
			$('.speaker-b').prepend('<img src="/idf/pix/video/tn_gelsinger.jpg" />');			

		  });



	  // open faq section and links
    var question = $('.show-hide>ul>li>a'); 
    var questionItem = $('.show-hide>ul>li')
    var answer = $('.show-hide li div');
    var questionLink = $('.show-hide>ul>li>div a');
    answer.hide();
	question.click(function(){
		$(this).toggleClass('openActive');
		$(this).next().toggle();
		return false;
	});
	questionLink.click(function(e) {
		if (e.ctrlKey){
		window.open($(this).attr('href'))
		return false;
		}
		window.location=$(this).attr('href');

		});	


		
	
	// fire play video cta
	
	var playVideo =$('#vid-videos-collection > div.content-item:eq(0) > a:eq(0)');
	$('.play-video').click(function() {
		$(playVideo).click();
		return false;
	});
	
	//open these links in new window
	$('.keynotes #horizontal-scrollbar a,.travel .hotels a').click(function(){
		$(this).attr({target: "_blank"});
	});
	
	function hideFocusBorders(){
		var theahrefs = document.getElementsByTagName("a");
		if(!theahrefs){return;}
		for(var x=0;x!=theahrefs.length;x++){
			theahrefs[x].onfocus = function stopLinkFocus(){this.hideFocus=true;};
		}
	}
	
	// vert scrollers:
	$(".slider").each(function(){
		// how tall is my content?
		var panel = $(this).parent();
		var scroller = $("div.scroller",panel);
		var scrollerContent = $("div.scrollerContent",scroller);
		// initialize scroller only if it needs to be there:
		
		if(scrollerContent.height() > scroller.height()){
			// initialize
			$(this).slider({
				orientation: "vertical",
				animate: false,
				slide: handleSlide,
				min: -100,
				max: 0
			});
		}else{ // otherwise hide scrollbar bg
			$("div.scroll-bg",panel).hide();
		}
	});
	
});


function handleChange(e, ui){
	var scroller = $(ui.handle).parent().parent().children()[0];
	var maxScroll = $(scroller).attr("scrollHeight") - $(scroller).height();
	$(scroller).animate({ scrollTop: -ui.value * (maxScroll / 100)}, 1000);
}

function handleSlide(e, ui){
	var scroller = $(ui.handle).parent().parent().children()[0];
	var maxScroll = $(scroller).attr("scrollHeight") - $(scroller).height();
	$(scroller).attr({ scrollTop: -ui.value * (maxScroll / 100)   });
}



function initializeHorizontalScrollers(){
	//
	// add html for scroll background
	$('.content-slider,#content-slider0,#content-slider,#content-slider2,#content-slider3,#content-slider4').prepend('<div class="content_scroller_bg"></div>');

    window.onload = jQuery.sliderScroller = function(){
        jQuery('.sliderScroller').each(function(){
        
            jQuery(this).css('overflow', 'hidden');
            
            // add up width of content items:
            var contentItemsTotalWidth = 0;

			$(".content-holder > .content-item", this).each(function(){
				contentItemsTotalWidth += $(this).outerWidth(true);
			})

			
            // set container to calculated width:

				$(".content-holder", this).css("width", contentItemsTotalWidth + "px");

            
            // don't initialize if it doesn't need to scroll:
            if ($(this).width() > contentItemsTotalWidth || $(".content-holder > .content-item", this).length <= 3) {
                // hide the scroller
                $(this).next().hide();
                return;
            }
            
            function handleSliderSlide(e, ui){
                var maxScroll = jQuery(this).prev().attr("scrollWidth") - jQuery(this).prev().width();
                jQuery(this).prev().attr({
                    scrollLeft: ui.value * (maxScroll / 100)
                });
            }
			
            jQuery('.sliderScroller').next().slider({
                animate: false,
                slide: handleSliderSlide
            });
        });
        
        
        
        
        // for each content item 
        $('.content-holder').each(function(){
        
            // define variables for the respective container, items, and scroller
            var sliderScrollContainer = $(this).parent();
            //alert (sliderScrollContainer)
            var contentItem = $(this).children('.content-item');
            //alert (contentItem)
            var scrollerHeight = sliderScrollContainer.height();
            //alert (scrollerHeight)
            
            // set content item heights
            contentItem.css('height', scrollerHeight);
            
        });
        
    };

    $.sliderScroller();  // initiate slider and positioning 
}


// add rounded corners for bind class
$('.boxImg>div').addClass('bind_bottom_round');
$('.boxImg').css('border-bottom','none');
$('.bind_bottom_round').css('-top', '-25px');

$('ul.showHide li div').hide();
$('ul.showHide>li a').click(function (){
	$(this).next().slideToggle();
	return false;
});







// BEGIN: past IDF keynotes video player and videos collection -------------------------

$(document).ready(function(){
	// is this the video page? Check for the IDs of the major funtional elements:
	if(!(document.getElementById("vid-videos-collection") && document.getElementById("vid-caption"))){
		// wrong page:
		return;
	}
	
	// this is the video page, so continue:
	// give video thumbnails event handlers that will update the video window meta-data, and play the correct video:

	$("#vid-videos-collection > .content-item").each(function(i){ // for each 'content item'...

		// get needed data, store as properties of 'a' element:
		var videoThumbnail = $("a:first",this)[0];
		videoThumbnail.eventName = $("p.vid-event-name",this).html();
		videoThumbnail.eventDate = $("p.vid-event-date",this).html();
		videoThumbnail.keynoteTitle = $("p.vid-keynote-title",this).html();
		videoThumbnail.speakerName = $("p.vid-speaker-name",this).html();
		videoThumbnail.speakerTitle = $("p.vid-speaker-title",this).html();
		videoThumbnail.speakerCompany = $("p.vid-speaker-company",this).html();
		videoThumbnail.videoUrl = $("p.vid-url",this).html();
		videoThumbnail.stillImageUrl = $("p.vid-still",this).html();

		
		$(videoThumbnail).bind("click", function(e){
			//
			$("#vid-event-name").html(this.eventName);
			$("#vid-event-date").html(this.eventDate);
			$("#vid-keynote-title").html(this.keynoteTitle);
			$("#vid-speaker-name").html(this.speakerName);
			$("#vid-speaker-title").html(this.speakerTitle);
			$("#vid-speaker-company").html(this.speakerCompany);
			
			// play the video:

				playFlashVideo(this.videoUrl, this.stillImageUrl);
				console.log('play video at ' + (this));
				return false;

		});
	});
	
});

function playFlashVideo(videoUrl,stillImgUrl){
	// is it rtmp or flv?
	if(videoUrl.indexOf("rtmp:") == 0){ // rtmp:
		// seperate url path and file-name:
		var fileNameBreak = videoUrl.lastIndexOf("/");
		var filePath = videoUrl.substring(0, fileNameBreak+1);
		var fileName = videoUrl.substring(fileNameBreak+1);
		// capture error, in case there's no flash:
		try{ document.getElementById('flash').playAkami(filePath,fileName,stillImgUrl) }
		catch(e){}
	}else{ // flv:
		// capture error, in case there's no flash:
		try{ document.getElementById('flash').playFLV(videoUrl,stillImgUrl) }
		catch(e){}
	}
}


// END: past IDF keynotes video player and videos collection -------------------------


// BEGIN: past IDF keynotes video player and videos collection 2 -------------------------

$(document).ready(function(){
	// is this the video page? Check for the IDs of the major funtional elements:
	if(!(document.getElementById("vid-videos-collection2") && document.getElementById("vid-caption2"))){
		// wrong page:
		return;
	}
	
	// this is the video page, so continue:
	// give video thumbnails event handlers that will update the video window meta-data, and play the correct video:

	$("#vid-videos-collection2 > .content-item2").each(function(i){ // for each 'content item'...

		// get needed data, store as properties of 'a' element:
		var videoThumbnail2 = $("a:first",this)[0];
		videoThumbnail2.eventName2 = $("p.vid-event-name2",this).html();
		videoThumbnail2.eventDate2 = $("p.vid-event-date2",this).html();
		videoThumbnail2.keynoteTitle2 = $("p.vid-keynote-title2",this).html();
		videoThumbnail2.speakerName2 = $("p.vid-speaker-name2",this).html();
		videoThumbnail2.speakerTitle2 = $("p.vid-speaker-title2",this).html();
		videoThumbnail2.speakerCompany2 = $("p.vid-speaker-company2",this).html();
		videoThumbnail2.videoUrl2 = $("p.vid-url2",this).html();
		videoThumbnail2.stillImageUrl2 = $("p.vid-still2",this).html();

		
		$(videoThumbnail2).bind("click", function(e){
			//
			$("#vid-event-name2").html(this.eventName2);
			$("#vid-event-date2").html(this.eventDate2);
			$("#vid-keynote-title2").html(this.keynoteTitle2);
			$("#vid-speaker-name2").html(this.speakerName2);
			$("#vid-speaker-title2").html(this.speakerTitle2);
			$("#vid-speaker-company2").html(this.speakerCompany2);
			
			// play the video:
			var firstVideo = $();

				//playFlashVideo2(this.videoUrl2, this.stillImageUrl2);

			return false;
		});
	});
	
});

function playFlashVideo2(videoUrl2,stillImgUrl2){
	// is it rtmp or flv?
	if(videoUrl2.indexOf("rtmp:") == 0){ // rtmp:
		// seperate url path and file-name:
		var fileNameBreak2 = videoUrl2.lastIndexOf("/");
		var filePath2 = videoUrl2.substring(0, fileNameBreak2+1);
		var fileName2 = videoUrl2.substring(fileNameBreak2+1);
		// capture error, in case there's no flash:
		try{ document.getElementById('flash2').playAkami(filePath2,fileName2,stillImgUrl2) }
		catch(e){}
	}else{ // flv:
		// capture error, in case there's no flash:
		try{ document.getElementById('flash2').playFLV(videoUrl2,stillImgUrl2) }
		catch(e){}
	}
}


// END: past IDF keynotes video player and videos collection -------------------------


      $(document).ready(function(){
	  	
		/* fix  the video thumbnails to indicate currently playing */
		var barrettVideo = '<img src="/idf/pix/video/tn_barrett2.jpg" alt="Craig R. Barret" />';
		var gelisingerVideo = '<img src="/idf/pix/video/tn_gelsinger2.jpg" alt="Patrick Gelsinger" />';
		var anandVideo = '<img src="/idf/pix/video/tn_chandrashaker2.jpg" alt="Anand Chandrashaker" />';
		$('.vidlink').click(function(){$('.speaker').empty();});
		$('.speaker-a').click(function(){
			$('.speaker-a>div').prepend(barrettVideo);
		});	  	
		$('.speaker-b').click(function(){
			$('.speaker-b>div').prepend(gelisingerVideo);
		});
		$('.speaker-c').click(function(){
			$('.speaker-c>div').prepend(anandVideo);
		});
		
		$('.speaker-a2').click(function(){
			$('.speaker-a2>div').prepend(barrettVideo);
		});	  	
		$('.speaker-b2').click(function(){
			$('.speaker-b2>div').prepend(gelisingerVideo);
		});
		$('.speaker-c2').click(function(){
			$('.speaker-c2>div').prepend(anandVideo);
		});
      });
