    var strSpeakerVideosTemplate;
    var online = true;
    var myajaxstr = "";
    if (document.images) {
         blank = new Image
         pdf = new Image
         printer = new Image
         email = new Image
         linkIcon = new Image
         info = new Image

         blank.src = '../images/Speakerspage/blank_text.gif'
         pdf.src='../images/Speakerspage/icon_createpdf_text.gif'
         printer.src='../images/Speakerspage/icon_printer_text.gif'
         email.src='../images/Speakerspage/icon_email_text.gif'
         linkIcon.src='../images/Speakerspage/icon_link_text.gif'
         info.src='../images/Speakerspage/icon_info_text.gif'
     }

    $(function() {
        var moreinfolink;
        $("#icon_print").attr("href", "javascript:void(0);");
		$("#icon_print").click(function(){
				window.print();
				/*
				var currurl = "" + window.location;
				if(currurl.indexOf("?") > 0){
					currurl += "&print=yes"
				}else{
					currurl += "?print=yes"
				}
				window.open(currurl, "printwindow", "width=900, height= 600, status=1, scrollbars=1, toolbar=1, location=0");
				*/
		});
	if($("#btn_moreinfo")){
		moreinfolink= "/request-information";					//var moreinfolink = $("#btn_moreinfo").attr("href");
		$("#btn_moreinfo").attr("href", "javascript:void(0);");		//disable href
		$("#btn_moreinfo").click(function(){						//make new link
			//make form
			var myform = $("<form name='myform' id='myform' method='post' action='" + moreinfolink + "' style='display:none;'></form>");
			//make field
			var mysubmitbtn = $("<input type='submit' name='submit' id='prepopulate_submit' value='submit' />");
			//add form to page
			$(myform).append($(myfield));
			$(myform).append($(mysubmitbtn));
			$("body").append($(myform));
			//submit form
			$("#prepopulate_submit").click();
			return false;
		});
	}
	if($("#icon_reqinfo")){
		moreinfolink= "/request-information";
		$("#icon_reqinfo").attr("href", "javascript:void(0);");		//disable href
		$("#icon_reqinfo").click(function(){						//make new link
			//make form
			var myform = $("<form name='myform' id='myform' method='post' action='" + moreinfolink + "' style='display:none;'></form>");
			//make field
			var mysubmitbtn = $("<input type='submit' name='submit' id='prepopulate_submit' value='submit' />");
			//add form to page
			$(myform).append($(myfield));
			$(myform).append($(mysubmitbtn));
			$("body").append($(myform));
			//submit form
			$("#prepopulate_submit").click();
			return false;
		});
	}
	if($("#icon_email")){
		var emaillink = "/email-speaker";
		$("#icon_email").attr("href", "javascript:void(0);");		//disable href
		$("#icon_email").click(function(){
			window.open(emaillink, "emailwindow", "width=900, height= 600, status=1, scrollbars=1, toolbar=1, location=0");
		});
	}
        
        $("#div_spkProfileTabs").tabs();

        //Client Speaker Kit
        if (phtCurrent.length>0 || ntrCurrent.length>0){
			//load photo links
            var strSpeakerPhotosTemplate = $('#ul_Photos').html();
            $('#ul_Photos').html('');
            for (i=0;i<phtCurrent.length;i++){
                $('#ul_Photos').append(sprintf(strSpeakerPhotosTemplate,
                    phtCurrent[i].phtId,
                    phtCurrent[i].phtURL,i+1,"\n"));
            }
            if(!$('#ul_Photos').html())
                $('#div_Photos').hide();
            //load speaker intro
            var strSpeakerIntrosTemplate = $('#ul_Intros').html();
            var strSpeakerAVTemplate = $('#ul_VideoAudio').html();
            $('#ul_Intros').html('');
            $('#ul_VideoAudio').html('');
            for (i=0;i<ntrCurrent.length;i++){
                //skip to the next loop if any of both values is null
                var myintro = ntrCurrent[i].ntrIntro;
                if(myintro){
                    myintro = myintro.replace(/\r/g, "<br/>");
                    $('#ul_Intros').append(sprintf(strSpeakerIntrosTemplate,
                    ntrCurrent[i].ntrId,
                    myintro,"\n"));
		}
                var myaudio = ntrCurrent[i].ntrAudio;
                if(myaudio){
                    myaudio = myaudio.replace(/\r/g, "<br/>");
                    $('#ul_VideoAudio').append(sprintf(strSpeakerAVTemplate,
                        ntrCurrent[i].ntrId,
                        myaudio,"\n"));
                }
            }
            if(!$('#ul_Intros').html())
                $('#div_Intros').hide();
            if(!$('#ul_VideoAudio').html())
                $('#div_VideoAudio').hide();
        }
        else
            $("#div_spkProfileTabs").tabs( 'remove' , 4 );

        if (bkCurrent.length>0){
            var strSpeakerBooksTemplate = $('#div_SpeakerBooksItems').html();
            $('#div_SpeakerBooksItems').html('');
            for (i=0;i<bkCurrent.length;i++){
                $('#div_SpeakerBooksItems').append(sprintf(strSpeakerBooksTemplate,
                    bkCurrent[i].bkId,
                    bkCurrent[i].bkImgURL,
                    bkCurrent[i].bkImgAlt,"\n"));
            }
            $("#div_SpeakerBooks").scrollable({
                size: 4
            });
            strSpeakerBooksTemplate = $('#ul_SpeakerBooksItems').html();
            $('#ul_SpeakerBooksItems').html('');
            var strPublished;
            for (i=0;i<bkCurrent.length;i++){
                if (bkCurrent[i].bkPublished)
                    strPublished = new Date(bkCurrent[i].bkPublished.substring(0,4), bkCurrent[i].bkPublished.substring(5,7) - 1, bkCurrent[i].bkPublished.substring(8,10)).format("longDate");
                else
                    strPublished = "";
                strPublished = strPublished.replace(/(\d+, )/,"")
                if (strPublished=='November 1899')
                    strPublished = "";
                $('#ul_SpeakerBooksItems').append(sprintf(strSpeakerBooksTemplate,
                    bkCurrent[i].bkId,
                    bkCurrent[i].bkImgURL,
                    Clean(bkCurrent[i].bkImgAlt),
                    Clean(bkCurrent[i].bkTitle),
                    Clean(bkCurrent[i].bkDesc),
                    strPublished,"\n"));
            }
        }
        else{
            $("#div_spkProfileTabs").tabs( 'remove' , 3 );
            $("#div_SpeakerBooksContainer").hide();
        }

        if (cmmCurrent.length>0){
        	/*
            var strSpeakerCommentsTemplate = $('#ul_Testimonials').html();
            $('#ul_Testimonials').html('');
            for (i=0;i<cmmCurrent.length;i++){
                $('#ul_Testimonials').append(sprintf(strSpeakerCommentsTemplate,
                    Clean(cmmCurrent[i].cmmComment.replace(/<p>/,"").replace(/<\/p>/,"")),
                    Clean(cmmCurrent[i].cmmCommentBy), "\n"));
             }
             */
        }
        else
            $("#div_spkProfileTabs").tabs( 'remove' , 2 );

        if (stdCurrent.length>0){
        	/*
            var strSpeakerTopicsTemplate = $('#ul_SpeakerTopics').html();
            $('#ul_SpeakerTopics').html('');
            for (i=0;i<stdCurrent.length;i++){
                 $('#ul_SpeakerTopics').append(sprintf(strSpeakerTopicsTemplate,
                    Clean(stdCurrent[i].stdHead),
                    Clean(stdCurrent[i].stdDesc),"\n"));
            }
            */
        }
        else
            $("#div_spkProfileTabs").tabs( 'remove' , 1 );

        if (spkSimilars.length>0){
            var strSpeakerSimilarsTemplate = $('#div_SimilarsItems').html();
            $('#div_SimilarsItems').html('');
            for (i=0;i<spkSimilars.length;i++){
                $('#div_SimilarsItems').append(sprintf(strSpeakerSimilarsTemplate,
                    spkSimilars[i].spkPhotoURL,
                    spkSimilars[i].spkPhotoAlt,
                    spkSimilars[i].spkFirstName,
                    spkSimilars[i].spkLastName,
                    spkSimilars[i].spkPageURL,"\n"));
            }
            $("#accordion").accordion({
                        collapsible: true,
			icons: {
    			header: "ui-icon-circle-plus",
   				headerSelected: "ui-icon-circle-minus"
			}
            });
            $("#accordion").accordion( 'activate' , 'false' )
            $("#div_Similars").scrollable({
            size: 3
            });
        }
        else
            $("#div_SimilarsContainer").hide();
                    
        //generate ajax data for flash player
        if(vidCurrent.length>0){
            strSpeakerVideosTemplate = $('#div_SpeakerVideosItems').html();
            $('#div_SpeakerVideosItems').html('');
			myajaxstr = '&quot;myvideos&quot;:[';
			for (i=0;i<vidCurrent.length;i++){
				myajaxstr += '{';
				myajaxstr += '&quot;vidId&quot;:' + vidCurrent[i].vidId + ',';
				myajaxstr += '&quot;vidFKspkId&quot;:' + vidCurrent[i].vidFKspkId + ',';
				myajaxstr += '&quot;vidLocalURL&quot;:&quot;' + cleanyoutubelinks(vidCurrent[i].vidLocalURL) + '&quot;,';
				myajaxstr += '&quot;vidYouTubeURL&quot;:&quot;' + cleanyoutubelinks(vidCurrent[i].vidYouTubeURL) + '&quot;';
				if(i == vidCurrent.length -1){
					myajaxstr += '}';
				}else{
					myajaxstr += '},';
				}
			}
			myajaxstr += ']';
                        //detect internet connection then generate video links
                        testConnection();
		}
                else
                    $("#div_SpeakerVideosContainer").hide();
		
               
        if (spkTwtrUsr){
            strTwitterFeedsTemplate=$('#div_TwitterFeeds').html();
            $('#div_TwitterFeeds').html('');
            $('#div_TwitterFeeds').append('<img id="img_Spinner" src="/images/loading.gif" alt="Loading..." />');
            $.jTwitter(spkTwtrUsr, 1, function(aTweets){
                if(aTweets.length>0){
                    $('#div_TwitterFeeds').html('')
                        var dateTweet = new Date(Date.parse(aTweets[0].created_at.replace(/(\+\S+) (.*)/, '$2 $1')));
                        var strTweetdate = dateTweet.format("default");//dateTweet.format("default");
                        /*var now = new Date();
                        alert(now + " " + dateTweet);
                        var dateDiff = dateTweet-now;
                        var fullDays = Math.floor(dateDiff/(60*60*24));
                        if (fullDays)
                            strTweetdate = strTweetdate + Math.ceil((now.getTime()-dateTweet.getTime())/(1000*60*60*24)) + " days ";
                        var fullHours = Math.floor((dateDiff-(fullDays*60*60*24))/(60*60));
                        if (fullHours)
                            strTweetdate = strTweetdate + fullHours + " hours ";
                        var fullMinutes = Math.floor((dateDiff-(fullDays*60*60*24)-(fullHours*60*60))/60);
                        if (fullMinutes)
                            strTweetdate = strTweetdate + fullMinutes + " minutes ";*/
                        var strFormattedTweet=aTweets[0].text.replace(/((\w+:\/\/)[-a-zA-Z0-9:@;?&=\/%\+\.\*!'\(\),\$_\{\}\^~\[\]`#|]+)/g,'<a href="$&" target="_blank">$&</a>');
                        strFormattedTweet=strFormattedTweet.replace(/#[a-zA-Z_]+/g,'<a href="http://twitter.com/search?q=$&" target="_blank">$&</a>')
                        strFormattedTweet=strFormattedTweet.replace(/q=#/g,"q=");
                        strFormattedTweet=strFormattedTweet.replace(/@[a-zA-Z_]+/g,'<a href="http://twitter.com/$&" target="_blank">$&</a>');
                        strFormattedTweet=strFormattedTweet.replace(/twitter.com\/@/g,"twitter.com/");
                    $('#div_TwitterFeeds').append(sprintf(strTwitterFeedsTemplate,
                        strFormattedTweet,
                        strTweetdate,
                        aTweets[0].user.screen_name, "\n"));
                        $("#div_SpeakerTwitterContainer").show();
                    }
                    else
                        $("#div_SpeakerTwitterContainer").hide();
            });
        }
        else
            $("#div_SpeakerTwitterContainer").hide();        
    });
    function generateVideoLinks(){
        PrintVideoList(vidCurrent,strSpeakerVideosTemplate,$('#div_SpeakerVideosItems'));
       //If There are no youtube videos, force Viddler
        if (!$('#div_SpeakerVideosItems').html()){
            bYouTube=false;
            bViddler=true;
            PrintVideoList(vidCurrent,strSpeakerVideosTemplate,$('#div_SpeakerVideosItems'));
        }
       //If There are no viddler videos, force local
        if (!$('#div_SpeakerVideosItems').html()){
            bViddler=false;
            PrintVideoList(vidCurrent,strSpeakerVideosTemplate,$('#div_SpeakerVideosItems'));
        }
        /*
			if(online == false){
				//vidLocalURL
				for (i=0;i<vidCurrent.length;i++){
					if(vidCurrent[i].vidLocalURL != null){
						writevideo_local(vidCurrent[i]);
					}
				}
			}else{
				for (i=0;i<vidCurrent.length;i++){
					if(vidCurrent[i].vidYouTubeId != null){
						//load youtube videos
						writevideo_Youtube(vidCurrent[i]);
					}else if(vidCurrent[i].vidLocalURL != null){
						writevideo_local(vidCurrent[i]);
					}
				}


			}
        */

        if($("#div_SpeakerVideosItems").html()){
            $("#div_SpeakerVideos").scrollable({
                size: 2,
                clickable: false
            });
            $(".img_LoadVideo").click(function(){
                ShowVideoPlayer($(this).attr("id"));
            });
        }
        else
            $("#div_SpeakerVideosContainer").hide();
        //set prettyphoto
        for (var i = 0; i< $("a[href^='http://www\.youtube\.com']").length; i++){
            $("a[href^='http://www\.youtube\.com']").eq(i).attr('href', $("a[href^='http://www\.youtube\.com']").eq(i).attr('href').replace('/v/', '/watch?v='));
        }
	$("a[rel^='prettyPhoto']").prettyPhoto();
    }
	function writevideo_Youtube(videsource){
		/*
		//advance video player
		var thisajaxstr = 'myvals={&quot;online&quot;:' + online  + ',&quot;selected&quot;:' + videsource.vidId + ',' + myajaxstr + '}';
		var strSpeakerVideosTemplate = '<div><a id="a_vidId_%1$s">Video %1$s</a></div>%2$s';
		$('#div_SpeakerVideosItems').append(sprintf(strSpeakerVideosTemplate, videsource.vidId,"\n"));
		//$('#a_vidId_'+videsource.vidId).attr("href",videsource.vidYouTubeURL);
		$('#a_vidId_'+videsource.vidId).attr("href","assets/flash/param_test.swf?width=800&height=400&flashvars=" + thisajaxstr);
		$('#a_vidId_'+videsource.vidId).attr("rel", "prettyPhoto[1]");
		$('#a_vidId_'+videsource.vidId).attr("title", "");
		*/
		//simple video player
		var strSpeakerVideosTemplate = '<div><a id="a_vidId_%1$s"><img src="%2$s" alt="%1$s" /></a></div>%3$s';
		$('#div_SpeakerVideosItems').append(sprintf(strSpeakerVideosTemplate, videsource.vidId, "http://i3.ytimg.com/vi/" + videsource.vidYouTubeId + "/default.jpg" ,"\n"));
		$('#a_vidId_'+videsource.vidId).attr("href",videsource.vidYouTubeURL);
		$('#a_vidId_'+videsource.vidId).attr("rel", "prettyPhoto[1]");
		$('#a_vidId_'+videsource.vidId).attr("title", "");
                $("#div_SpeakerVideosContainer").show();
	}
	function writevideo_flv(videsource){
	}
	function writevideo_wmv(videsource){
	}
	function writevideo_local(videosource){
		//<a href="http://www.apple.com?iframe=true&width=500&height=250" rel="prettyPhoto[iframes]">Apple.com</a>
		//var strSpeakerVideosTemplate = '<div><a id="a_vidId_%1$s">Video %1$s (local)</a></div>%2$s';
		var strSpeakerVideosTemplate = '<div><a id="a_vidId_%1$s"><img src="/images/icon_video.png" width="120" /></a></div>%2$s';
		var playerurl = "videoplayer_local.php?videourl=" + videosource.vidLocalURL + "&iframe=true&width=540&height=320";
		$('#div_SpeakerVideosItems').append(sprintf(strSpeakerVideosTemplate, videosource.vidId,"\n"));
		$('#a_vidId_'+videosource.vidId).attr("href",playerurl);
		$('#a_vidId_'+videosource.vidId).attr("rel", "prettyPhoto[1]");
		$('#a_vidId_'+videosource.vidId).attr("title", "");
	}
	function cleanyoutubelinks(youtubelink){
		var myresult = "";
		if(youtubelink){
			myresult = (youtubelink.split("&"))[0];
		}else{
			myresult = youtubelink;
		}
		return myresult;
	}
	//------------------------------
	function testConnection(){
                /*
		//make image - image source will need to be update if youtube updates their logo image name
		//http://www.example.com/singlepixel.gif
		//http://s.ytimg.com/yt/img/master-vfl141814.png
		myimg = $("<img src='http://s.ytimg.com/yt/img/master-vfl141814.png' onerror='setOffline();' style='display:none;' />");
		$("#footer").before(myimg);
		//delay 2 second to check if error occured, if not load video from youtube, else load flv player
		var timeout = 2000; //timeout at 2 seconds
                */
                $("#footer").before(imgYouTube);
                $("#footer").before(imgViddler);
		setTimeout(generateVideoLinks, iTimeoutMS);
	}
	function setOffline(){
		online = false;	//set global var
	}
	//------------------------------