/*
 * Parse through a text string and create hyperlinks where needed.
 */
String.prototype.parseURL = function() {
	return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&~\?\/.=]+/g, function(url) {
		return url.link(url);
	});
};

/*
 * Parsing usernames as Links to Twitter
 */
String.prototype.parseUsername = function() {
	return this.replace(/[@]+[A-Za-z0-9-_]+/g, function(u) {
		var username = u.replace("@","")
		return u.link("http://twitter.com/"+username);
	});
};

/*
 * Parsing Hashtags as Links to Twitter's Search
 */
String.prototype.parseHashtag = function() {
	return this.replace(/[#]+[A-Za-z0-9-_]+/g, function(t) {
		var tag = t.replace("#","%23")
		return t.link("http://search.twitter.com/search?q="+tag);
	});
};

/**
 * Date.elapsed
 * @param {Date | string} date The reference date.
 * @param {boolean} isGMT [arg1] If true, use Universal Time; false, otherwise.
 * @param {boolean} timeUnit [arg2] The expected to Time unit of the response.
 *     Default value is false.
 * @return {object}
 *     {object}.type {string} [MONTH|DAY|HOUR|MINUTE|SECOND]
 *     {object}.value {number}
 */
Date.prototype.elapsed = function(date) {
    var time = 0;
	if (!(this.valueOf())) {
		return null;
	} else {
        time = parseFloat(this.valueOf());
    }
	
	var MONTH_MS = 2592000000;
	var DAY_MS = 86400000;
	var HOUR_MS = 3600000;
	var MINUTE_MS = 60000;
	var SECOND_MS = 1000;
    
    
	var dateReference = (date instanceof Date) ? date : new Date(date);
    
	var isGMT = arguments[1] || false;
	if (isGMT) {
		dateReference = new Date(dateReference.toUTCString());
	}
    
    var dateElapsed = time - parseFloat(dateReference.valueOf()); // Elapsed time in ms.
    
	var timeUnit = arguments[2] || '';    
    switch (timeUnit.toUpperCase()) {
        case 'MONTH' :
            return { type: 'MONTH', value: Math.floor(dateElapsed / MONTH_MS)};
        case 'DAY' :
            return { type: 'DAY', value: Math.floor(dateElapsed / DAY_MS)};
        case 'HOUR' :
            return { type: 'HOUR', value: Math.floor(dateElapsed / HOUR_MS)};
        case 'MINUTE' :
            return { type: 'MINUTE', value: Math.floor(dateElapsed / MINUTE_MS)};
        case 'SECOND' :
            return { type: 'SECOND', value: Math.floor(dateElapsed / SECOND_MS)};
        default : break;
    }
	
	if (Math.floor(dateElapsed / MONTH_MS)) {
		// Months
		return { type: 'MONTH', value: Math.floor(dateElapsed / MONTH_MS)};
		
	} else if (Math.floor(dateElapsed / DAY_MS)) {
		// Days
		return { type: 'DAY', value: Math.floor(dateElapsed / DAY_MS)};
		
	} else if (Math.floor(dateElapsed / HOUR_MS)) {
		// Hours
		return { type: 'HOUR', value: Math.floor(dateElapsed / HOUR_MS)};
		
	} else if (Math.floor(dateElapsed / MINUTE_MS)) {
		// Minutes
		return { type: 'MINUTE', value: Math.floor(dateElapsed / MINUTE_MS)};
		
	} else { // Seconds
		return { type: 'SECOND', value: Math.floor(dateElapsed / SECOND_MS)};
	}
	
	return null;
}

/* Extends jQuery library */
/**
 * $.cookie
 * @param {string} name The cookie's name.
 *     return results for.
 * @param {string} action [arg1] The action to try and apply to a
 *     cookie; [assign|read|delete];
 * @param {string} value [arg2] The cookie's value.
 * @param {string} days [arg3] The cookie's lifetime in days;
 *     if not set, cookie expires at the end of session.
 */
jQuery.cookie = function(name) {
	var name = name;
	var value = arguments[2] || '';
	var days = 0;
	
	
	var action = arguments[1] || 'read';
	switch (action) {
		case 'assign' :
			if (arguments[3]) {
				days = (typeof arguments[3] == 'number') ?
					arguments[3] : parseFloat(arguments[3]);
			}
			break;
		case 'delete' :
			value = '';
			days = -1;
			break;
		default :
			var strTarget = name + '=';
			var arrKeyValue = document.cookie.split(';');
			for (i in arrKeyValue) {
				keyValue = arrKeyValue[i];
				keyValue = $.trim(keyValue);
				if (keyValue.indexOf(strTarget) === 0) {
					return keyValue.substring(strTarget.length,
						keyValue.length);
				}
			}
			return null;
	}
	
	var expires = '';
	if (days) {
		var dateExpires = new Date();
		dateExpires.setTime(dateExpires.getTime() +
			(days * 24 * 60 * 60 * 1000));
		expires = '; expires=' + dateExpires.toGMTString();
	}
	document.cookie = name + '=' + value + expires + "; path=/";
	return null;
}

/**
 * Twitter
 * @param {string} user The screen name of the user for whom to
 *     return results for.
 * @param {int} count [arg1] The number of tweets to try and retrieve.
 * @param {function} onComplete [arg2] Process the returned Twitter feed.
 */
var Twitter  = function(screenName) {
	/* Public Members */
	var screenName = screenName;
	var count = arguments[1] || 10;
    
    /* Public Methods */
	var onComplete = arguments[2] || function(feed) {
        /**
         * @param {array} feed Contains an array of tweet object;
         *      tweet object format
         *      {   'id_str': 1234,
         *          'screen_name': 'John_Doe',
         *          'created_at': 'Tue Sep 13 +0000 2011',
         *          'text': 'Some "Twitter Tweet" text.'
         *      }
         */
        var strBuffer = [];
        var tweet = feed;
        for (i in feed) {
            dateBuff = [];
            dateBuff.push(tweet[i].created_at.split(' ')[1]);
            dateBuff.push(tweet[i].created_at.split(' ')[2]);
            dateBuff.push(tweet[i].created_at.split(' ')[5]);
            dateBuff.push(tweet[i].created_at.split(' ')[3]);
            dateBuff.push(tweet[i].created_at.split(' ')[4]);
            elapsedTime = new Date().elapsed(dateBuff.join(' '), true);
            created_at = 'about ' + elapsedTime.value + ' ' +
                elapsedTime.type.toLowerCase() + ((elapsedTime.value > 1) ?
                    's ago' : ' ago');
            strBuffer.push('<li><span class="tweet_text">');
            strBuffer.push(tweet[i].text.parseURL().parseUsername().parseHashtag());
            strBuffer.push('</span><span class="tweet_time">');
            strBuffer.push('<a href="http://twitter.com/');
            strBuffer.push(tweet[i].screen_name);
            strBuffer.push('">');
            strBuffer.push(created_at);
            strBuffer.push('</a></span></li>');
        }
        $('.tweet ul.tweet_list').html(strBuffer.join(''));
        // DO NOT DELETE: from riser
        $('.tweet').vTicker({
            speed: 1000,
            pause: 5000,
            showItems: 1,
            animation: 'fade',
            mousePause: false,
            height: 92,
            direction: 'up'
        });
        /*
        alert('TwitterFeed: no default onComplete handler');
        return false;
        */
    };
    
	/* Error & Exception */
	if (!screenName) {
		throw new Error('TwitterFeed: sreenName expected.');
	} else if (typeof screenName != 'string') {
		throw new TypeError('TwitterFeed: sreenName must be of String value.');
	} else if (count && typeof count != 'number') {
		throw new TypeError('TwitterFeed: count must be a Number.');
	} else if (count < 0) {
		throw new Error('TwitterFeed: count must be greater than 0.');
	} else if (typeof onComplete != 'function') {
		throw new TypeError('TwitterFeed: onComplete must be a function.');
	}
    
    /* Private Methods */
	function onSuccess(data) {
        /**
         * @param {object} feed Twitter feed in JSON format.
         */
        var strBuffer = [];
        for (i in data) {
            var tweetBuffer = '%7B';
            tweetBuffer += '%22id_str%22:%22' + data[i].id_str + '%22,';
            tweetBuffer += '%22screen_name%22:%22' + encodeURI(data[i].user.screen_name) + '%22,';
            tweetBuffer += '%22created_at%22:%22' + data[i].created_at + '%22,';
            tweetBuffer += '%22text%22:%22' + encodeURI(data[i].text.replace(/\"/g, '\\\"')) + '%22';
            tweetBuffer += '%7D';
            strBuffer.push(tweetBuffer);
        }
         
        var cookieValue = '%5B' + strBuffer.join(',') + '%5D';
        $.cookie('_twitter_feed_' + screenName, 'assign', cookieValue, 30 * 1/1440); // Cache Twitter Feed for 30 minutes.
        onComplete($.parseJSON(decodeURI(cookieValue)));
	};
    
    cookieValue = $.cookie('_twitter_feed_' + screenName);
    if (cookieValue) {
        onComplete($.parseJSON(decodeURI(cookieValue)));
    } else {
        // Retrieve feed from twitter.com.
        $.get('http://twitter.com/statuses/user_timeline/' +
            screenName + '.json?count=' + count +
            '&callback=?', onSuccess, 'json');
    }
};

/**
 * GuestGuide
 * @param {string} path The relative path to Guest Guide XML file.
 * @param {function} onSuccess [arg1] Process the returned XML.
 */
var GuestGuide = function(path) {
    // Constants
    var CONST_DAY_NAMES = {
        'Mon' : 'Monday',
        'Tue' : 'Tuesday',
        'Wed' : 'Wednesday',
        'Thu' : 'Thursday',
        'Fri' : 'Friday'
    };
    
    var path = path;
    var onSuccess = arguments[1] || function(data) { // Default handler
        //prepare HTML snippet from XML document
        var counter = 0 // days limit
        var htmlBuffer = [];
        var XML = data;
        $(XML).find('accordion').each(function(){
        
            var $accordion = $(this);
            
            var today = new Date(new Date().toDateString()) // GMT
            var target = new Date($accordion.attr('date'));
            if (today <= target) {
                var pathIMG = '/live/riserAssets-kelly/';
                htmlBuffer.push('<li><div class="inner_slide_container">');
                $accordion.find('slide').each(function(){
                
                    $section = $(this);
                    htmlBuffer.push('<div class="inner_slide"><div class="border"></div><a href="guest-guide.html">');
                    htmlBuffer.push('<img src=\'' + pathIMG + $section.find('photo').text() + '\' ');
                    htmlBuffer.push('alt=\'' + $section.find('title').text() + '\' />');
                    htmlBuffer.push('</a><div class="slider_bg"></div>');
                    
                    tokenizedDate = target.toDateString().split(' ');
                    htmlBuffer.push('<div class="thumb_info"><span class="day">' +
                        tokenizedDate[0] + '</span><span>' +
                        tokenizedDate[1] + ' ' +
                        tokenizedDate[2] + '</span></div>');
                        
                    htmlBuffer.push('<div class="slider_info"><a href="guest-guide.html"><p class="slider_text"><span class="title">');
                    if (today.toDateString().indexOf(tokenizedDate[0]) > -1) {
                        htmlBuffer.push('Today');
                    } else {
                        htmlBuffer.push(CONST_DAY_NAMES[tokenizedDate[0]]);
                    }
                    htmlBuffer.push(' <strong>' +
                        tokenizedDate[1] + ' ' +
                        tokenizedDate[2] + '</strong></span>' +
                        $section.find('title').text() + '</p></a>');
                    htmlBuffer.push('</div></div>');
                    
                });
                htmlBuffer.push('</div></li>');
                
                if (!(counter < 5)) {
                    return false;
                } else {
                    counter++;
                }
            }
        });
        //initialize the accordion slider (update content)
        $('#slider ul.accordion').html(htmlBuffer.join(''));
        
        //initialize the accordion slider (cycle through 5 days/shows)
        var slideSpeed = 600;
        mySlider = $("#slider .accordion").zAccordion({
            auto: false,
            tabWidth: 71,
            width: 600,
            speed: slideSpeed,
            click: function() {
                
                //remove the pager, set the cycle slide to first one and destroy the cycle on the previous slide
                $('.pager_container').remove();
                $('#slider .accordion > li.slide-previous .inner_slide_container').cycle(0);
                $('#slider .accordion > li.slide-previous .inner_slide_container .inner_slide').css('z-index', '0');
                $('#slider .accordion > li.slide-previous .inner_slide_container .inner_slide').eq(0).css('z-index', '1').css('opacity', '1');
                $('#slider .accordion > li.slide-previous .inner_slide_container').cycle('destroy');
                
                $("#slider").find("li.slide-open div.slider-info").css("display", "none");
                $("#slider").find("li.slide-previous div.slider-info").css("display", "none");
                
                $('#slider .accordion > li.slide-previous img').animate({marginLeft: -123}, slideSpeed);
                
                setTimeout(function(){
                    $("#slider").find("li.slide-open div.slider-info").css("display", "none").fadeIn(1200);
                    $("#slider").find("li.slide-previous div.slider-info").css("display", "none").fadeIn(1200);
                }, 500);
                
                $("#slider").find("li.slide-open img").animate({marginLeft: 0}, slideSpeed);
                
                //start the inner slider on the newly opened slide
                startInnerSlider();
            },
            slideWidth: 315,
            height: 297
        });
        
        //initialize the inner slideshow (cycle through all the guests for the selected day)
        var startInnerSlider = function() {
            $('#slider .accordion > li.slide-open .inner_slide_container')
            .after('<div class="pager_container"><div class="pager_left"><a class="prev_slide">Previous Slide</a></div><div class="pager"></div><div class="pager_right"><a class="next_slide">Next Slide</a></div></div>')
            .cycle({ 
                fx:     'fade', 
                speed:  'slow', 
                timeout: 5000, 
                pager:  '.pager',
                next:   '.next_slide', 
                prev:   '.prev_slide'
            });
        }
        
        //run the inner slider for the default accordion slide
        startInnerSlider();
	};
    
    /* Error & Exception */
	if (!path) {
		throw new Error('GuestGuide: path argument expected.');
	} else if (typeof path != 'string') {
		throw new TypeError('GuestGuide: path must be of String value.');
	} else if (typeof onSuccess != 'function') {
		throw new TypeError('GuestGuide: onSuccess must be a function.');
	}
    
    $.get(path, onSuccess, 'xml');
}

/**
 * CoHost
 * @param {string} path The relative path to co-host XML file.
 * @param {function} onSuccess [arg1] Process the returned XML.
 */
var CoHost = function(path) {
    var path = path;
    var onSuccess = arguments[1] || function(data) { // Default handler
        //prepare HTML snippet from XML document
		var pathIMG = '/live/riserAssets-kelly/images/guestcohost/';
		var img = '';
		var imgTitle = '';
		var text = '';
        var XML = data;
        $(XML).find('guestHost').each(function(){
            var $guestHost = $(this);
            var today = new Date(new Date().toDateString()); // GMT
            //var today = new Date('12/01/2011');
			var target = new Date($guestHost.attr('date'));
			var difference = target - today;
            if (difference == 0) {
				img = $guestHost.find('photo').text();
				imgTitle = $guestHost.find('photoTitle').text();
				text = $guestHost.find('title').text();
			}
		});
		
		$('#guest_host').html(
			'<div class="container">' + 
				'<a href="/live/guest-cohost.html"><img src="' + pathIMG + img + '" alt="co-host" class="co_host" /></a>' + 
				'<div class="content" onclick="location.href=\'http://dadt.com/live/guest-cohost.html\';" style="cursor:pointer;">' + 
					'<h3>Today\'s Guest Co-Host:</h3>' + 
					'<a href="/live/guest-cohost.html">' + 
						'<img src="' + pathIMG + imgTitle + '" alt="Guest Co-Host" class="name" />' + 
					'</a>' + 
					'<p>' + text + '</p>' + 
				'</div>' + 
			'</div>'
		);
	};
	$.get(path, onSuccess, 'xml');
}

NavObj = {
	Home: {
		'home':'<a href="index.html">Home</a>'
	},
	Hosts: {
		'kelly':'<a href="/live/kelly.html">Kelly</a>',
		'cohost':'<a href="http://www.kellyscohosts.com">Guest Co-Host</a>'
	},
	ShowInfo: {
		'getTickets':'<a href="get-tickets.html">Get Tickets</a>',
		'guestGuide':'<a href="guest-guide.html">Guest Guide</a>',
		'localListings':'<a href="local-listings.html">Local Listings</a>',
		'gelman':'<a href="gelman.html">Gelman\'s Page</a>'
	},
	Video: {
		'hostChat':'<a href="host-chat.html">Host Chat</a>',
		'videoArchive':'<a href="video-archive.html">Video Archive</a>',
		'webExclusives':'<a href="special/webexclusives">Web Exclusives</a>',
		'performances':'<a href="special/livestage">Performances</a>',
		'bonusInbox':'<a href="special/askregiskelly/index.html#bonusinbox">Bonus Inbox</a>'
	},
	FunStuff: {
		'trivia':'<a href="contest/traveltrivia">Trivia</a>',
		'recipes':'<a href="recipes.html">Recipes</a>',
		'fashionFinder':'<a href="fashion-finder.html">Fashion Finder</a>'
	},
	Interact: {
		'sendMessage':'<a href="special/ask">Send Kelly a message</a>',
		'sendSubmissions':'<a href="submissions.html">Send your submissions</a>',
		'twitter':'<a href="http://www.twitter.com/LiveKelly">Follow us on Twitter</a>',
		'facebook':'<a href="http://www.facebook.com/LIVEwithKelly">Visit us on Facebook</a>',
		'blog':'<a href="http://blogs.liveregisandkelly.com/behind_the_scenes/">Read the LIVE Blog</a>'
	},
	Help: {
		'faq':'<a href="faq.html">FAQ</a>'
	}
};

FooterContentObj = {
	Column1: {
		'header':'Top Videos',
		'item1':'<a href="http://bcove.me/m2poex85">Science Bob</a>',
		'item2':'<a href="http://bcove.me/0b5dg9xl">Miss Piggy</a>',
		'item3':'<a href="http://bcove.me/itc7lxe7">Wild and Wacky Gift Ideas</a>',
		'item4':'<a href="http://bcove.me/nk3lr4x9">Jerry Seinfeld\'s Dog Jose</a>',
		'item5':"<a href='/live/special/farewellcelebration/'>Farewell Celebration Moments</a>"
	},
	Column2: {
		'header':'Top Performances',
		'item1':'<a href="http://bcove.me/dvpsbwfw">Nick Jonas</a>',
		'item2':'<a href="http://bcove.me/ozwilxis">Ingrid Michaelson</a>',
		'item3':'<a href="http://bcove.me/kdk17fpi">Mary J. Blige</a>',
		'item4':'<a href="http://bcove.me/82b8l3tc">Common</a>',
		'item5':'<a href="http://bcove.me/4fxl1wz6">Voca People</a>'
	},
	Column3: {
		'header':'Recent Features',
		'item1':'<a href="/live/special/guinnessweek/11/">Guinness World Record Breaker Week</a>',
		'item2':'<a href="/live/special/dogweek/11/">Dog Days of Summer</a>',
		'item3':'<a href="/live/contest/fixmyman">Fix My Man</a>',
		'item4':'<a href="/live/special/ambushmakeovers/11">Rescue Me Ambush Makeovers</a>',
		'item5':'<a href="/live/special/summerhealth">Summer Health Journey</a>'
	},
	Column4: {
		'header':'Latest Recipes',
		'item1':'<a href="http://dadt.com/live/recipe-finder.html?recipeID=13045">Richard Blais\' Whipped Egg Nog</a>',
		'item2':'<a href="http://dadt.com/live/recipe-finder.html?recipeID=13050">Richard Blais\' Hot Cider with Potpourri</a>',
		'item3':'<a href="http://dadt.com/live/recipe-finder.html?recipeID=13024">Paula Deen\'s Sweet Potato Praline Crunch Pie</a>',
		'item4':'<a href="http://dadt.com/live/recipe-finder.html?recipeID=12942">Josh Capon\'s Turkey Chowder</a>',
		'item5':'<a href="http://dadt.com/live/recipe-finder.html?recipeID=12970">Jamie Oliver\'s Sausage Rolls</a>'
	}
};

function loadHeader() {
	$('#logo').html(
		'<a href="http://dadt.com/live/index.html">LIVE! with Kelly</a>'
	);
	
	$('#top_right').html(
      
        '<div id="search">' +
          '<form action="http://www.dadt.com/live/search.html" method="get" id="search-form">' +
            '<div>' +
              '<input type="text" name="sq" id="sq" class="text_field" value="Enter Keyword:" onblur="if (this.value == \'\') {this.value = \'Enter Keyword:\';}"  onfocus="if (this.value == \'Enter Keyword:\') {this.value = \'\';}" />' +
              '<input class="search_button" type="image" src="riserAssets-kelly/images/search-go.png" alt="Go" id="searchsubmit" />' +
            '</div>' +
          '</form>' +
        '</div><!-- end #header .full_wrapper #top_right #search -->' +
        
        '<div id="social">' +
          '<a href="http://www.twitter.com/LiveKelly" class="twitter">Twitter</a>' +
          '<a href="http://www.facebook.com/LIVEwithKelly/" class="facebook">Facebook</a>' +
        '</div><!-- end #header .full_wrapper #top_right #social -->'
		
	);
	  
	$('#navigation').html(
      
        '<ul class="main_nav">' +
          '<li>' + NavObj.Home.home + '</li>' +
          '<li>' +
            '<a href="#">Hosts</a>' +
            '<ul>' +
              '<li>' + NavObj.Hosts.kelly + '</li>' +
              '<li>' + NavObj.Hosts.cohost + '</li>' +
            '</ul>' +
          '</li>' +
          '<li>' +
            '<a href="#">Show Info</a>' +
            '<ul>' +
              '<li>' + NavObj.ShowInfo.getTickets + '</li>' +
              '<li>' + NavObj.ShowInfo.guestGuide + '</li>' +
              '<li>' + NavObj.ShowInfo.localListings + '</li>' +
              '<li>' + NavObj.ShowInfo.gelman + '</li>' +
            '</ul>' +
          '</li>' +
          '<li>' +
            '<a href="#">Video</a>' +
            '<ul>' +
              '<li>' + NavObj.Video.hostChat + '</li>' +
              '<li>' + NavObj.Video.videoArchive + '</li>' +
              '<li>' + NavObj.Video.webExclusives + '</li>' +
              '<li>' + NavObj.Video.performances + '</li>' +
              '<li>' + NavObj.Video.bonusInbox + '</li>' +
            '</ul>' +
          '</li>' +
          '<li>' +
            '<a href="#">Fun Stuff</a>' +
            '<ul>' +
              '<li>' + NavObj.FunStuff.trivia + '</li>' +
              '<li>' + NavObj.FunStuff.recipes + '</li>' +
              '<li>' + NavObj.FunStuff.fashionFinder + '</li>' +
            '</ul>' +
          '</li>' +
          '<li>' +
            '<a href="#">Interact</a>' +
            '<ul>' +
              '<li>' + NavObj.Interact.sendMessage + '</li>' +
              '<li>' + NavObj.Interact.sendSubmissions + '</li>' +
              '<li>' + NavObj.Interact.twitter + '</li>' +
              '<li>' + NavObj.Interact.facebook + '</li>' +
              '<li>' + NavObj.Interact.blog + '</li>' +
            '</ul>' +
          '</li>' +
          '<li>' +
            '<a href="#">Help</a>' +
            '<ul>' +
              '<li>' + NavObj.Help.faq + '</li>' +
            '</ul>' +
          '</li>' +
        '</ul>'
		
	);
}

function loadFooterContent() {
	$('#footer_content').html(
		'<div class="container">' + 
		  '<div class="column column1">' + 
			'<h3>' + FooterContentObj.Column1.header + '</h3>' + 
			'<ul>' + 
			  '<li>' + FooterContentObj.Column1.item1 + '</li>' + 
			  '<li>' + FooterContentObj.Column1.item2 + '</li>' + 
			  '<li>' + FooterContentObj.Column1.item3 + '</li>' + 
			  '<li>' + FooterContentObj.Column1.item4 + '</li>' + 
			  '<li>' + FooterContentObj.Column1.item5 + '</li>' +
			'</ul>' + 
		  '</div>' + 
		  '<div class="column column2">' + 
			'<h3>' + FooterContentObj.Column2.header + '</h3>' + 
			'<ul>' + 
			  '<li>' + FooterContentObj.Column2.item1 + '</li>' + 
			  '<li>' + FooterContentObj.Column2.item2 + '</li>' + 
			  '<li>' + FooterContentObj.Column2.item3 + '</li>' + 
			  '<li>' + FooterContentObj.Column2.item4 + '</li>' + 
			  '<li>' + FooterContentObj.Column2.item5 + '</li>' + 
			'</ul>' + 
		  '</div>' + 
		  '<div class="column column3">' + 
			'<h3>' + FooterContentObj.Column3.header + '</h3>' + 
			'<ul>' + 
			  '<li>' + FooterContentObj.Column3.item1 + '</li>' + 
			  '<li>' + FooterContentObj.Column3.item2 + '</li>' + 
			  '<li>' + FooterContentObj.Column3.item3 + '</li>' + 
			  '<li>' + FooterContentObj.Column3.item4 + '</li>' + 
			  '<li>' + FooterContentObj.Column3.item5 + '</li>' +
			'</ul>' + 
		  '</div>' + 
		  '<div class="column column4">' + 
			'<h3>' + FooterContentObj.Column4.header + '</h3>' + 
			'<ul>' + 
			  '<li>' + FooterContentObj.Column4.item1 + '</li>' + 
			  '<li>' + FooterContentObj.Column4.item2 + '</li>' + 
			  '<li>' + FooterContentObj.Column4.item3 + '</li>' + 
			  '<li>' + FooterContentObj.Column4.item4 + '</li>' + 
			  '<li>' + FooterContentObj.Column4.item5 + '</li>' +
			'</ul>' + 
		  '</div>' + 
		'</div>'
	);
}

var loadDocumentFooter = function() {
    var links = arguments[0] || [
        { text: 'Privacy Policy/Your California Privacy Rights', url: 'http://transfer.go.com/cgi/transfer.dll?srvc=dis&goto=http://disney.go.com/corporate/legal/wdig_privacy.html&name=g_legalFooter_privacypolicy'},
        { text: 'Internet Safety', url: 'http://transfer.go.com/cgi/transfer.dll?srvc=dis&goto=http://disney.go.com/corporate/legal/safety_tips.html&name=g_legalFooter_internetsafety'},
        { text: 'Terms of Use', url: 'http://transfer.go.com/cgi/transfer.dll?srvc=dis&goto=http://disney.go.com/corporate/legal/terms.html&name=g_legalFooter_termsofuse'},
        { text: 'Register', url: 'https://register.go.com/regisandkelly/index'},
        { text: 'Guest Services', url: 'https://register.go.com/regisandkelly/lists'},
        { text: 'Help', url: 'https://register.go.com/go/goFAQ'}
    ];
    
    strBuffer = [];
    for (i in links) {
        strBuffer.push('<a href="' + links[i].url + '">' + links[i].text + '</a>');
    }
    
    $('#footer').html(
        '<div class="full_wrapper">' +
        '<p>&copy; Disney*ABC Domestic Television. All rights reserved.<br />' +
        strBuffer.join(' | ') +
        '</p></div>');
}

/* SiteCatalyst code version: H.16. Copyright 1997-2007 Omniture,
Inc. More info available at	http://www.omniture.com */
var gobj_docHead = document.getElementsByTagName("head")[0];

var gobj_omnitureAccount = document.createElement('script');
gobj_omnitureAccount.type = 'text/javascript';
gobj_omnitureAccount.src = '/omniture/omniture_dadt_account.js';
gobj_docHead.appendChild(gobj_omnitureAccount);

var gobj_omnitureCode = document.createElement('script');
gobj_omnitureCode.type = 'text/javascript';
gobj_omnitureCode.src = '/omniture/s_code.js';
gobj_docHead.appendChild(gobj_omnitureCode);

$(document).ready(function(){
	try {
		if (s_omni.t() &&
            location.href.indexOf(".go.com/regisandkelly/") == -1) {
            document.write(s_omni.t());
		}
	}
	catch (e) {
	//throw(e)
	}
    
	//Load the header div html code
	loadHeader();
	//Load site footer content
	loadFooterContent();
	//Load site footer
	loadDocumentFooter();
    
	//initialize the superfish plugin for the dropdown navigation
    $('#navigation ul.main_nav').superfish({
        speed: 0,
        delay: 0
    });
    
    // Homepage
    try {
        var GuestGuideSlider = new GuestGuide('/live/riserAssets-kelly/xml/slider.xml');
		var CoHostObj = new CoHost('/live/riserAssets-kelly/xml/co-host.xml');
        //initialize the vertical scroller for the twitter feed
        var TwitterWidget = new Twitter('LiveKelly', 2);
    } catch(e) { alert('error initializing xml'); }
    	
});
