var rm214_get_post_url = '/summit/pull.php',
    rm214_send_post_url = '/summit/post.php',
    rm214_get_user_info = '/summit/get_user_info.php',
    rm214_report_abuse = '/summit/report_abuse.php',
    rm214_iframe_url = '/summit/index.php',
    rm214_twitter_follow = '/summit/twitter_auto_follow.php',
    rm214_twitter_login = '/summit/twitter_login.php',
    rm214_tt = '',                  //twitter token
    rm214_layover_displayed = 0,    //set the default state of the layover to false
    rm214_ui;                       //object to hold user information
    rm214_message_list = new Array();
    rm214_official_list = new Array();
    rm214_user_posted_messages = new Array();
    
    var rm214_run = [];

    var flickr_api_key = '4e07e55e6201612195335ba83ac9bfcc';
    var flickr_photo_set_id = '72157622399189405';
    var flickr_photos_per_page = 12;
/**
 * Get a post object
 **/
function rm214GetPostObject() {
    this.pid = 0;                     //post id
    this.post_type = '';              //post type
    this.post_display_style = '';     //post display style
    this.post_uid = '';               //post user id
    this.post_avatar_url = '';        //post avatar url
    this.post_date_created = '';      //post date created
    this.post_handle = '';            //post handle
    this.post_source = '';            //where the post came from
    this.post_handle_link = '';       //post user link back
    this.post_text = '';              //the post text
    this.post_unix_time_stamp = '';   //unix time stamp
    this.setPostByXml = function(xml) {
        this.pid = $(xml).attr('id');
        this.post_type = $(xml).attr('type');
        this.post_display_style = $(xml).attr('display_style');
        this.post_uid = $(xml).find('user_id').text();
        this.post_avatar_url = $(xml).find('avatar_url').text();
        this.post_date_created = $(xml).find('date_created').text();
        this.post_handle = $(xml).find('handle').text();
        this.post_source = $(xml).find('source').text();
        this.post_handle_link = $(xml).find('handle_link').text();
        this.post_text = $(xml).find('text').text();
        this.post_unix_time_stamp = $(xml).find('date_created_ts').text();
    }
    //check if the user is special
    this.isSpecialUser = function() {
        if (this.post_display_style == 'special') {
            return true;
        } else {
            return false;
        }
    }
    //check which post is the newest
    this.isPostNewer = function(post) {
        if (rm214_ui.csup == null) {
            return false;
        }
        if (post.post_unix_time_stamp > rm214_ui.csup.post_unix_time_stamp) {
            return true;
        } else {
            return false;
        }
    }
}
/**
* Set it up so the rm214LoadPost gets all at the defined interval
*/
function rm214GetPost() {
    $.ajax({type: 'GET',
            url: rm214_get_post_url + '?bid=' + (rm214_ui.bid == 0 ? 0 : (parseInt(rm214_ui.bid) + 1)) + '&tk=' + rm214GetRandString(),
            dataType: 'xml',
            success: function(xml) {
                        rm214LoadPost(xml);
                        if (rm214_ui.first_display == true) {
                            
                            rm214SetDefaultSticky();
                            var startEffect = function run() {
                                rm214GetPost();
                                rm214GetSpecialPost();
                                slideInPost();
                                slideInPostSpecial();
                            }

                            startEffect();
                            setInterval(function() {startEffect(); }, 25000);
                            rm214_ui.first_display = false;
                        }
                     },
            error: function(req, txt, e) {}
        });
}
/**
 * Set it up so the rm214LoadSpeicalPost function gets called at the defined
 * interval
 */
function rm214GetSpecialPost() {
    $.ajax({type: 'GET',
            url: rm214_get_post_url + '?bid=' + (rm214_ui.subid == 0 ? 0 : (parseInt(rm214_ui.subid) + 1)) +
                 '&tk=' + rm214GetRandString() + '&type=special',
            dataType: 'xml',
            success: function(xml) {
                        rm214LoadSpecialPost(xml);
                     },
            error: function(req, txt, e) {}
        });
}
function rm214SetDefaultSticky() {
	$.ajax({type: 'GET',
			url: '/summit/default_sticky.php',
			dataType: 'json',
			success: function(json) {
				var sticky = new rm214GetPostObject();
				sticky.pid = json.messages_sent_id;                     //post id
				sticky.post_type = 'twitter';              //post type
				sticky.post_display_style = 'special';     //post display style
				sticky.post_uid = json.user_id;               //post user id
				sticky.post_avatar_url = json.avatar_url;        //post avatar url
				sticky.post_date_created = json.date_created;      //post date created
				sticky.post_handle = json.handle;            //post handle
				sticky.post_source = json.source;            //where the post came from
				sticky.post_handle_link = 'http://www.twitter.com/' + json.handle;       //post user link back
				sticky.post_text = json.message;              //the post text
				sticky.post_unix_time_stamp = json.date_created_ts;   //unix time stamp
				rm214SetAsStickyPost(sticky);
				if ($.browser.msie && $.browser.version.substr(0,1) < 7) {
                    return 0;
                } else {
                    jQuery('abbr.timeago').timeago();   //make sure the dates state the updated time
                }
			},
			error: function(req, txt, e) {}
	});
}

/**
 *Create random string for ie6 cache problem
 */
function rm214GetRandString() {
    var temp_date = new Date();
    var token = temp_date.getUTCMilliseconds() + ':';
    token += temp_date.getHours() + ':';
    token += temp_date.getSeconds() + ':';
    token += temp_date.getUTCMilliseconds() + ':';
    token += temp_date.getYear() + ':';
    token += Math.floor(Math.random() * 50);
    return token;
}
/**
 *Called when a user post a message from the app.
 */
function rm214Post() {
    //user logged in send post
    if (rm214_ui.twitter_authorized == 1 || rm214_ui.fb_authorized == 1) {
        rm214SendPost();
    //user is not logged in try and get them logged in
    } else {
        $.ajax({type: 'GET',
                url: rm214_get_user_info,
                data: '',
                dataType: 'json',
                success: function(json) {
                            //the user seems to have logged in try and update the info
                            if (json.twitter_authorized == 1 || json.fb_authorized == 1) {
                                rm214_ui.avatar = json.avatar;
                                rm214_ui.fb = json.fb_authorized;
                                rm214_ui.twt = json.twitter_authorized;
                                rm214_ui.rm214_id = json.user_id;
                                rm214_ui.handle = json.handle;
                                $('#input_facebook_url').hide();
                                rm214SendPost();
                            } else {
                                rm214LoadLayover();
                            }
                    },
                error: function(req, txt, e) {}
        });
    }
}
/**
 * Removes old post in the "all" list
 */
function rm214RemovePostOverLimit() {
    $('#app_list .mlholder:gt(99)').remove();
}
/**
 *Remove old post in the "special" list
 */
function rm214RemoveSpecialPostOverLimit() {
    $('#app_list_special .mlholder:gt(99)').remove();
}
/**
 * Set a message as the "sticky" and add the old post into the stream
 */
function rm214SetAsStickyPost(obj_post) {
    var display_handle = rm214GetPostHandle(obj_post.post_handle, obj_post.post_handle_link);
    var image_type = ''; 
    
    if (obj_post.post_source == 'buzz_fb') {
		image_type = '/summit/img/summit_facebook_dark.png';
    } else {
    	image_type = '/summit/img/summit_twitter_dark.png';
    }
    
    var str_html = '<div class="app_post"><img src="' +
        obj_post.post_avatar_url + '" alt="" class="app_post_avatar" /><div class="msg_holder"><div class="msg_main_text">' +
        display_handle + '<span class="user_comment">' + obj_post.post_text +
        '</span></div><div class="post_type_holder"><img class="post_type_img post_type_png" src="' + image_type + '" style="_display: block" /></div><div class="message_date_holder"><div class="message_date"><abbr class="timeago" title="' +
        obj_post.post_date_created + 'Z">' + obj_post.post_date_created +
        '</abbr></div>' + '<a id="ab' + obj_post.pid +
            '" href="javascript://" onClick="rm214FlagPost(\'' +
            obj_post.pid +
            '\');" class="abuse">flag</a></div></div></div>';
    $('#sticky_message').html(str_html);

    if (rm214_ui.csup != null) {
        str_html = rm214GetPostMessage(rm214_ui.csup);
        $('#sticky_message').after(str_html);
        rm214_message_list.push(rm214_ui.csup.pid);
    }
    rm214_ui.csup = obj_post;
}
/**
 * Get a post and place it in the sticky area
 */
function rm214GetStickyPost() {
    $.ajax({type: 'GET',
            url: rm214_get_post_url + '?bid=' +
                  (rm214_ui.bid == 0 ? 0 : (parseInt(rm214_ui.bid) + 1)) +
                  '&tk=' + rm214GetRandString() + 'type=special',
            dataType: 'xml',
            success: function(xml) {
                $(xml).find('post').each(function() {
                    obj_post = new rm214GetPostObject();
                    obj_post.setPostByXml(this);
                    rm214SetAsStickyPost(obj_post);
                });
            },
            error: function(req, txt, e){}
    });
}
/**
 * Get a message block of html
 */
function rm214GetPostMessage(obj_post, is_special) {
    var background_style = '';

    if (obj_post.post_type == 'ad') {
        background_style = ' message_ad';
    } else if (obj_post.post_display_style != 'standard' && obj_post.post_type != 'ad') {
        background_style = ' special_user';
    }

    //find the correct handle display
    var display_handle = rm214GetPostHandle(obj_post.post_handle, obj_post.post_handle_link);
    var post_id_prefix = 'p';
    
    if (is_special == true) {
        post_id_prefix = 's';
    }
    var time_display = '';
    
    if ($.browser.msie && $.browser.version.substr(0,1) < 7) {
    	time_display = '<span class="timeago">' + obj_post.post_date_created + '</span>';
    } else {
    	time_display = '<abbr class="timeago" style="font-family: Lucida Sans Unicode, Lucida Grande, sans-serif; font-size: 11px" title="' + obj_post.post_date_created + 'Z">' + obj_post.post_date_created +
        '</abbr>' ;	
    }
    var image_type = ''; 
    
    if (obj_post.post_source == 'buzz_fb') {
    	if ($.browser.msie && $.browser.version.substr(0,1) < 7) {
    		image_type = '/summit/img/summit_facebook_light_ie6.png';
    	} else {
    		image_type = '/summit/img/summit_facebook_light.png';
    	}
    	
    } else {
    	if ($.browser.msie && $.browser.version.substr(0,1) < 7) {
    		image_type = '/summit/img/summit_twitter_light_ie6.png';
    	} else {
    		image_type = '/summit/img/summit_twitter_light.png';
    	}
    	
    }
    
    return '<div id="' + post_id_prefix + obj_post.pid + '" class="no_display mlholder"><div class="app_post ' + background_style +'"><img src="' +
                obj_post.post_avatar_url + '" alt="" class="app_post_avatar" /><div class="msg_holder"><div class="msg_main_text">' +
                display_handle + '<span class="user_comment">' + obj_post.post_text +
                '</span></div><div class="post_type_holder"><img id="type_image_' + obj_post.pid + '" class="post_type_img" src="' + image_type + '" /></div><div class="message_date_holder"><div class="message_date">' + 
                //'<abbr class="timeago" style="font-family: Lucida Sans Unicode, Lucida Grande, sans-serif; font-size: 11px" title="' + obj_post.post_date_created + 'Z">' + obj_post.post_date_created +
                //'</abbr>' +
                time_display +'</div>' + '<a id="ab' + obj_post.pid +
                    '" href="javascript://" onClick="rm214FlagPost(\'' +
                    obj_post.pid +
                    '\');" class="abuse">flag</a></div></div></div></div>';
    
}
/**
 *Get the handle html for a message post
 */
function rm214GetPostHandle(str_handle, str_handle_link) {
    var display_handle = '';

    if ($.trim(str_handle_link) != '') {
        display_handle = '<a class="handle" href="' + str_handle_link + '" target="_blank">' + str_handle + '</a>';
    } else {
        display_handle = '<span class="handle">' + str_handle + '</span>';
    }
    return display_handle;
}
/**
* Send user input to server and display information to frontend
*/
function rm214SendPost() {
    var app_text = $.trim($('#app_text').val());
    var is_only_facebook = 0;
    
    if (app_text == '') {
        return 0;
    }
    if (rm214_ui.fb == 1 && rm214_ui.twt != 1) {
    	is_only_facebook = 1;
    }
    
    $.ajax({type: 'GET',
            url: rm214_send_post_url,
            data: 'message=' + escape(app_text) + '&is_fb_only=' + is_only_facebook,
            dataType: 'json',
            success: function(json) {
                        d = new Date();
                        d.setUTCMilliseconds(d.getUTCMilliseconds());

                        month = d.getUTCMonth() + 1;
                        month = month < 10 ? '0' + month : month;

                        day = d.getUTCDate();
                        day = day < 10 ? '0' + day : day;

                        min = d.getUTCMinutes()
                        min = min < 10 ? '0' + min : min;

                        var handle_link = '';

                        if (rm214_ui.twt == 1) {
                            handle_link = 'http://twitter.com/' + rm214_ui.handle;
                        }

                        var utc_time_stamp = d.getUTCFullYear() + '-' + month +
                                             '-' + day + ' ' + d.getUTCHours() +
                                             ':' + min + ':' + d.getUTCSeconds();

                        obj_post = new rm214GetPostObject();

                        obj_post.pid = 'rm' + d.getUTCHours() +
                                        d.getUTCSeconds() +
                                        d.getUTCMilliseconds();
                        obj_post.post_type = '';
                        obj_post.post_display_style = rm214_ui.ds;
                        obj_post.post_uid = rm214_ui.rm214_id;
                        obj_post.post_avatar_url = rm214_ui.avatar;
                        obj_post.post_date_created = utc_time_stamp;
                        obj_post.post_handle = rm214_ui.handle;
                        obj_post.post_source = '';
                        obj_post.post_handle_link = handle_link;
                        obj_post.post_text = app_text;
                        str_list = rm214GetPostMessage(obj_post);
                        rm214_user_posted_messages.push(obj_post.pid);  //add posted message id to list to check if the user has already got this message
                        utc_timestamp = new Date(d.getUTCFullYear(),
                                                 d.getUTCMonth(),
                                                 day,
                                                 d.getUTCHours(),
                                                 min,
                                                 d.getUTCSeconds());

                        obj_post.post_unix_time_stamp = (utc_timestamp.getTime() / 1000);
                        //set as sticky
                        
                        if(rm214_ui.csup.isPostNewer(obj_post) && rm214_ui.ds == 'special') {
                            rm214SetAsStickyPost(obj_post);
                        } else {
                            $('#sticky_message').after(str_list);
                        }

                        $('#app_text').val('');
                        rm214RemovePostOverLimit();
                        $("#p" + obj_post.pid).show(600);
                        if ($.browser.msie && $.browser.version.substr(0,1) < 7) {
                            return 0;
                        } else {
                            jQuery('abbr.timeago').timeago();   //make sure the dates state the updated time
                        }
                     },
            error: function(req, txt, e) {}
    });
    return 1;
}
/**
 *Load layover window
 */
function rm214LoadLayover() {
    if (rm214_layover_displayed == 0) {
        $("#app_layover_bg").css({"opacity": "0.8"});
        rm214CenterLayover();
        $('#app_layover').fadeIn('slow');
        $('#app_layover_bg').fadeIn('slow');
        rm214_layover_displayed = 1;
    }
}
/**
 *Hide layover window
 */
function rm214HideLayover() {
    if (rm214_layover_displayed == 1) {
        $('#app_layover').fadeOut('slow');
        $('#app_layover_bg').fadeOut('slow');
        rm214_layover_displayed = 0;
    }
}
function rm214HideWhatIsThis() {
	$('#what_is_this_layover').fadeOut('slow');
    $('#app_layover_bg').fadeOut('slow');
}
/**
 *Center layover
 */
function rm214CenterLayover() {
    $('#app_layover').css({
        'position': 'absolute',
        'top': 150,
        'left': $(window).width() / 2 - $('#app_layover').width() / 2
    });

    //hack for good old IE6...
    $('#app_layover_bg').css({
        'height': $(window).height()
    });
}
/**
 *Get the user information
 */
function rm214LoadUserInfo() {
    $.ajax({type: 'GET',
            url: rm214_get_user_info,
            dataType: 'json',
            success: function(json) {
                       rm214_ui.avatar = json.avatar;
                       rm214_ui.handle = json.handle;
                       rm214_ui.fb = json.fb_authorized;
                       rm214_ui.twt = json.twitter_authorized;
                       rm214_ui.rm214_id = json.user_id;
                       rm214_ui.ds = json.display_style;
                       rm214SetTextareaStatus();
                     },
            error: function(req, txt, e) {}
        });
}
/**
 *Disconnect the user from twitter connect
 */
function rm214DisconnectTwitter() {
    $.ajax({type: 'GET',
            url: '/summit/disconnect.php?disconnect=twitter',
            dataType: 'json',
            success: function(json) {
                    //did the user logout
                    if (json.status == 1) {
                        //modify the front end display
                        rm214_tt = json.twitter_token;
                        
                        var html ='<a id="twitter_connect_link" href="javascript://" onClick="rm214TwitterPopUp()"><img src="/summit/img/summit_twitter_connect.png" class="png" alt="twitter" /></a>'
                        $('#twitter_connect').html(html);
                        //update the user info
                        $('#twitter_layover').remove();
                        layover_html = '<a href="javascript://" id="twitter_layover" onClick="rm214TwitterPopUp();"><img src="/summit/img/summit_twitter_large.png" /></a>';

                        $('#layover_facebook').before(layover_html);
                        rm214LoadUserInfo();

                        if (rm214_ui.fb == 0) {
                            $('#app_text').click(function() {
                                rm214LoadLayover()
                            });
                        }
                    }
                },
            error: function(req, txt, e) {}
        });
}
/**
 * Disconnect from facebook
 * Note: This can take a long time
 */
function rm214DisconnectFacebook() {
    $.ajax({type: 'GET',
            url: '/summit/disconnect.php?disconnect=facebook',
            dataType: 'json',
            success: function(json) {
                if (json.status == 1) {
                    window.location.replace(rm214_iframe_url);
                }
            },
            error: function(req, txt, e) {}
        });
}
/**
 *Enable or disable the textarea input element.
 */
function rm214SetTextareaStatus() {
    if (rm214_ui.twt == 1 || rm214_ui.fb == 1) {
        $('#app_text').attr('readonly', false);
    } else if (rm214_ui.twt == 0 && rm214_ui.fb == 0) {
        if ($('#app_text').attr('readonly') == false) {
            $('#app_text').attr('readonly', true);
            $('#app_text').attr('onclick', 'rm214LoadLayover()');
        }
    }
}
/**
 * Flag post
 */
function rm214FlagPost(pid) {
    $.ajax({type: 'GET',
            url: rm214_report_abuse,
            data: 'messages_sent_id=' + pid,
            dataType: 'json',
            success: function(json) {
                if (json.result == 'success') {
                    var abid = '#ab' + pid;
                    $(abid).parent().append('<span class="abuse">flagged</span>');
                    
                    var dom_id = $(abid).parent().parent().parent().parent().attr('id');
                	$('#' + dom_id).fadeOut("slow");
                }
            },
            error: function(req, txt, e) {}
    });
}

/**
* Load display information to front end user
*/
function rm214LoadPost(xml) {
    
    if (rm214_ui.bid == $(xml).find('block').attr('id')) {
        return 0;
    }
    
    rm214_ui.bid = $(xml).find('block').attr('id');
    var list = '';
    $(xml).find('post').each(function() {

        obj_post = new rm214GetPostObject();
        obj_post.setPostByXml(this);

        //check if the post is a special user post
        if (obj_post.isSpecialUser() == true) {
            //if we don't have a speical user post set add it to the sticky post
            if (rm214_ui.csup == null && rm214_ui.first_display == false) {
                rm214SetAsStickyPost(obj_post);
            //check if the post is newer
            } else if(rm214_ui.first_display == false && typeof rm214_ui.csup.isPostNewer == 'function') {
                if (rm214_ui.csup.isPostNewer(obj_post)) {
                    rm214SetAsStickyPost(obj_post);
                } else if (rm214_ui.csup.pid != obj_post.pid &&
                           $.trim(rm214_ui.csup.post_text) != $.trim(obj_post.post_text)){
                    rm214_message_list.push(obj_post.pid);
                    list += rm214GetPostMessage(obj_post);
                }
            }
        //not a special user post add it to the list
        } else {
            //rm214_user_posted_messages post_uid
            var is_not_posted = true;
            //user id is matching up
            if (obj_post.post_uid == rm214_ui.rm214_id) {
                for(var x in rm214_user_posted_messages) {
                    if ($('#p' + rm214_user_posted_messages[x]).children('div.app_post').children('div.msg_holder').children('div.msg_main_text').children('span.user_comment').html() == obj_post.post_text) {
                        is_not_posted = false;
                    }
                }
            }

            if (is_not_posted == true) {
                if (rm214LoadPost.count == undefined || rm214LoadPost.count == NaN) {
                    rm214LoadPost.count = 0;
                }
                rm214LoadPost.count = rm214LoadPost.count + 1;
                rm214_message_list.push(obj_post.pid);
                list += rm214GetPostMessage(obj_post);
            }
        }
    });

    $('#sticky_message').after(list);
    rm214RemovePostOverLimit();

    $('.user_comment a').attr('target', '_blank');

    rm214LoadPost.count = undefined;
    if ($.browser.msie && $.browser.version.substr(0,1) < 7) {
        return 0;
    } else {
        jQuery('abbr.timeago').timeago();   //make sure the dates state the updated time
    }
}
/**
 * Slide in effect for display all message
 */
function slideInPost() {
    //first display show all 
    if (rm214_ui.first_display == true) {
        //$("#app_list .no_display").show(600);
        //rm214_ui.first_display = false;
        //return true;
    }
    
    var post_2_show = rm214_message_list.pop();
    if (typeof slideInPost.running == 'undefined')
        slideInPost.running = true;
    
    if(post_2_show == undefined) {
        return false;
    }

    if ($("#p" + post_2_show).css('display') == 'none') {
        $("#p" + post_2_show).show(600, function() {
        	//if ($.browser.msie && $.browser.version.substr(0,1) < 7) {
        	//	$("#type_image_" + post_2_show).css('display', 'block');
        	//}
        	slideInPost();}
        );
    } else {
        slideInPost();        
    }
    
    return true;
}
/**
 * Slide in effect for display special user only post
 */
function slideInPostSpecial() {
    //first display show all
    if (rm214_ui.first_display_special == true) {
        //$("#app_list_special .no_display").show(600);
        //rm214_ui.first_display_special = false;
        //return true;
    }
    var post_2_show = rm214_official_list.pop();

    if (post_2_show == undefined) {
        return false;
    }
    
    if ($("#s" + post_2_show).css('display') == 'none') {
        $("#s" + post_2_show).show(600, function() {
    			//if ($.browser.msie && $.browser.version.substr(0,1) < 7) {
    			//	$("#type_image_" + post_2_show).css('display', 'block');
    			//}
    			slideInPostSpecial();
    		}
        );
    } else {
        slideInPostSpecial();
    }
    return true;
}

/**
 * Load the special user post into the list
 */
function rm214LoadSpecialPost(xml) {
    if (rm214_ui.subid == $(xml).find('block').attr('id')) {
        return 0;
    }

    rm214_ui.subid = $(xml).find('block').attr('id');
    var list = '';
    $(xml).find('post').each(function() {

        obj_post = new rm214GetPostObject();
        obj_post.setPostByXml(this);

        /*
        if (obj_post.isSpecialUser() == true) {
            if (rm214_ui.csup == null) {
                rm214SetAsStickyPost(obj_post);
            }
        }*/

        obj_post.post_display_style = 'standard';
        rm214_official_list.push(obj_post.pid);
        list += rm214GetPostMessage(obj_post, true);
    });

    $('#app_list_special').prepend(list);
    $('.user_comment a').attr('target', '_blank');
    rm214RemoveSpecialPostOverLimit();
    if ($.browser.msie && $.browser.version.substr(0,1) < 7) {
        return 0;
    } else {
        jQuery('abbr.timeago').timeago();   //make sure the dates state the updated time
    }
}
/**
 * Load the "all post" tab and hide the other tab
 */
function rm214ShowAllMessages() {
    $('#app_list_special').css({'display': 'none'});
    $('#app_list').css({'display': 'block'});
    $('#tab_official').removeClass('selected_tab');
    $('#tab_official').addClass('inactive_tab');
    $('#tab_all').removeClass('inactive_tab');
    $('#tab_all').addClass('selected_tab');


}
/**
 * Load the "official post" tab and hide theother tab
 */
function rm214ShowInvitedGuest() {
    $('#app_list_special').css({'display': 'block'});
    $('#app_list').css({'display': 'none'});
    $('#tab_all').removeClass('selected_tab');
    $('#tab_all').addClass('inactive_tab');
    $('#tab_official').removeClass('inactive_tab');
    $('#tab_official').addClass('selected_tab');
}
/**
 * Show the follow twitter layover for following twitter users
 */
function rm214ShowTwitterFollow() {
    $(document).ready(function(){
        $('#twitter_follow').css({'position':
                           'absolute','top': 150,
                           'left': $(window).width() / 2 - $('#app_layover').width() / 2
        });

        //hack for good old IE6...
        $('#app_layover_bg').css({'height': $(window).height()});
        $("#app_layover_bg").css({"opacity": "0.8"});

        $('#twitter_follow').fadeIn('slow');
        $('#app_layover_bg').fadeIn('slow');
    });
}
function rm214ShowWhatIsThis() {
	$(document).ready(function(){
        $('#what_is_this_layover').css({'position':
                           'absolute','top': 150,
                           'left': $(window).width() / 2 - $('#app_layover').width() / 2
        });

        //hack for good old IE6...
        $('#app_layover_bg').css({'height': $(window).height()});
        $("#app_layover_bg").css({"opacity": "0.8"});

        $('#what_is_this_layover').fadeIn('slow');
        $('#app_layover_bg').fadeIn('slow');
    });
}
function rm214OnPageLoad() {
    var runFunction = function() {
    		if ($.browser.msie && $.browser.version.substr(0,1) < 7) {
    			$('#RES_ID_fb_login_image').attr('src', '/summit/img/summit_facebook_small_ie6.png');
    		} else {
    			$('#RES_ID_fb_login_image').attr('src', '/summit/img/summit_facebook_small.png');
    		}
        setTimeout(function(){$('#RES_ID_fb_login').css({'display': "inline"})}, 700);
    }
    
    setTimeout(function(){runFunction()}, 3000);
}
/**
 * Add the user to follow twitter or not and then close the follow twitter layover
 */
function rm214FollowTwitter(int_follow) {
    $.ajax({type: 'GET',
            url: rm214_twitter_follow + '?follow=' + int_follow,
            dataType: 'json',
            success: function(json) {
                $('#twitter_follow').fadeOut('slow');
                $('#app_layover_bg').fadeOut('slow');
            },
            error: function(req, txt, e) {}
        });
}
function rm214TwitterPopUp() {
    window.open('/summit/twitter_login.php','tw_login',
                                'status=yes,toolbar=no,width=900,height=400,location=no');
}
//on page load
$(document).ready(function() {
    rm214_ui = {avatar: '',         //user avatar
                rm214_id: null,     //room 214 user id
                handle: '',         //handle
                twt: 0,             //is twitter authorized
                fb: 0,              //is facebook authorized
                bid: 0,             //block id
                ds: 0,              //user display style
                subid: 0,           //special user block id holder
                csup: null,          //current special user post
                first_display: true, //fast display
                first_display_special: true
               };
    //load the send post function to the submit button for an onClick
    $('#app_post_btn').click(function(){rm214Post()});
    //load the hideLayover function to the close link for an onClick
    $('#layover_close').find('span').click(function(){rm214HideLayover()});
    rm214GetSpecialPost();
    rm214GetPost();
    rm214LoadUserInfo();
    
    //load flickr
    $.getJSON("http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=" + flickr_api_key + "&photoset_id=" + flickr_photo_set_id + "&per_page=" + flickr_photos_per_page + "&format=json&jsoncallback=?",
		function (json) {
    		var row_count = 1;
    		var photo_count = 0;
	    	$.each(json.photoset.photo, function(key, value) {
	    		var img_url = 'http://farm' + value.farm + '.static.flickr.com/' +  
	    					  value.server + '/' + value.id + '_' + 
	    					  value.secret + '_s.jpg';
	    		var link_url = 'http://www.flickr.com/photos/wommaflickr/' + value.id + 
	    					   '/in/set-' + flickr_photo_set_id + '/';
	    		var elm = '<a href="' + link_url + '" title="' + value.title + '" target="_blank"><img src="' + img_url + '" /></a>';
	    		$('#buzz_flickr_row_' + row_count).append(elm);
	    		photo_count++;
	    		if (photo_count > 3) {
	    			photo_count = 0;
	    			row_count++;
	    		}
    		});
		}
    );
});