var blink_timer;
var blinker_time_interval = 2000;
var origional_title = document.title;

/********** Bumpin Global Args being Used **********/

var BumpinSocialBarDomain;
var BumpinSBFanPageID = "";
var BumpinSBTwitterID = "";

//var bsbBaseUrl = "social_bar";
var bsbBaseUrl = "bumpin_social_bar_separate_apps";
var load_bumpin_super_lite = "false";

var stop_loading_all_bsb_files = false;
var cssFiles = ["http://www.bumpin.com/min/?b="+bsbBaseUrl+"/css&f=BumpinStyleSheet3.css,prettyPhoto.css,jgrowl.css"];
var jsFiles = [];
//check here for load format.
var bNewScriptLoadFormat = true;


loadScriptStyleFiles(jsFiles,cssFiles);

/********** loading bumpin super lite version	**********/
 
try{
    load_bumpin_super_lite = typeof bsbConfigParams.load_bumpin_super_lite != 'undefined' ? bsbConfigParams.load_bumpin_super_lite : "false";
}catch(e){
//console.log(load_bumpin_super_lite + ' error ' + e);
}
	
if(load_bumpin_super_lite == "true")
{
    //load the lite version..
    stop_loading_all_bsb_files = true;
    setBumpinLiteLoadHtml();
}
	
function setBumpinLiteLoadHtml(){
    try{
        //check quirks mode
        try{
            if(navigator.userAgent.indexOf('MSIE') != -1){
                var mode=document.compatMode;
                if(mode){
                    if(mode=='BackCompat'){
                        stop_loading_all_bsb_files = false;
                        return;
                    }
                }
            }
        }catch(e){
			
        }
        //load the css
        var socialbar_theme = typeof bsbConfigParams.socialbar_theme != 'undefined' ? bsbConfigParams.socialbar_theme : "blue";
        var filename = "http://www.bumpin.com/min/?b="+bsbBaseUrl+"/css&f=bumpin_" + socialbar_theme + ".css";
        loadjscssfile(filename, 'css');

        var bsbBuddyIndicator = document.getElementById('buddyIndicator');
        var bsbTableMainPanel = document.getElementById('mainpanel');
        var bsbFootPanel 	  = document.getElementById('footpanel');
		
        //make foot panel align with right
        bsbFootPanel.style.right 		= '0px';
        //remove left attribute from foot panel
        bsbFootPanel.style.left 		= '';
        //make mainpanel width 184px
        bsbTableMainPanel.style.width 	= '184px';
        bsbTableMainPanel.style.position= 'fixed';
        bsbTableMainPanel.style.right	= '13px';
        bsbTableMainPanel.style.marginRight = '28px';
        bsbTableMainPanel.style.bottom = '0px';
        //insert image in buddy indicator
        bsbBuddyIndicator.innerHTML = '<div id="bsb-tools-icon" style="padding-top: 7px;"> <img src="http://www.bumpin.com/bumpin_social_bar_separate_apps/css/social-tools.png"/></div>';
        bsbBuddyIndicator.style.visibility = 'visible';
        //add opening div with mouse over and click js events.
        var newDiv = document.createElement('div');
		
        newDiv.setAttribute('id', 'openBottomBarDivLt');
        newDiv.setAttribute('style', 'cursor:pointer; width:29px; height:36px; margin-top:3px; bottom:0px; right:15px;position:fixed;display:block;background-position: 0 -41px;z-index:10000000');
		
        newDiv.innerHTML = '<div style="display: none; margin-left: -104px; bottom:50px" id="bumpinOpenToolTip" class="bumpinSocialBarToolTip" > <div style="width: 120px;" class="bumpin-tool-tip-center" >click to show the bar</div> <div class="bumpin-tool-tip-arrow" style="left: 106px;" ></div></div>';
        newDiv.onclick = startLoadingBSBAgain;
        if (window.addEventListener){
            newDiv.addEventListener("mouseover", function(){
                document.getElementById('bumpinOpenToolTip').style.display = 'block';
            }, false);//invoke function
            newDiv.addEventListener("mouseout", function(){
                document.getElementById('bumpinOpenToolTip').style.display = 'none';
            }, false);
        }
        else{
            newDiv.attachEvent("mouseover", function(){
                document.getElementById('bumpinOpenToolTip').style.display = 'block';
            }); //invoke function
            newDiv.attachEvent("mouseout", function(){
                document.getElementById('bumpinOpenToolTip').style.display = 'none';
            });
        }
        //insertAfter( bsbFootPanel, newDiv );
        bsbFootPanel.parentNode.insertBefore( newDiv, bsbFootPanel );
		
		
			
    //jQuery("#buddyIndicator").remove();
    //jQuery("#tickbar-bottom-td").before('<td style="margin: 0px; padding: 0px;" id="buddyIndicator"></td>');
    //renderClosingDiv();
    //renderBSBPostFPString();
    }catch(e){
        //alert("error");
        //console.log(e);
        setTimeout("setBumpinLiteLoadHtml()", 500);
    }
}
function insertAfter( referenceNode, newNode )
{
    referenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling );
}
var finalbsbMPWidth = 0;
var BSBFilesLoadedOnce = false;
function startLoadingBSBAgain(){
    if(BSBFilesLoadedOnce){
        return;
    }
    stop_loading_all_bsb_files = false;
		
    if (window.jQuery) {
        bumpinJqueryFoundOnPage = true;
        //need to find a new way to load only the related stuff
        bumpinSelectiveScriptLoad();
    }else{
        initJQuery();
    }
    //start annimation call back resetBumpinLiteLoadHtml
    finalbsbMPWidth = (document.getElementById('footpanel').offsetWidth)*0.90;
    var bsbTableMainPanel = document.getElementById('mainpanel');
    bsbAnnimate(bsbTableMainPanel,184,finalbsbMPWidth,resetBumpinLiteLoadHtml,20);
    BSBFilesLoadedOnce = true;

}
	
function bsbAnnimate(element,startVal,EndVal,CallBack,delay) {
	
    //var element = document.getElementById('mainpanel');
    //console.log(startVal);
    if(document.getElementById('mainpanel').offsetWidth <= EndVal){
        var diff = EndVal-startVal;
        if(diff < 40 && diff > 0){
            element.style.width = (element.offsetWidth+diff)+'px'; // pseudo-property code: Move right by 10px
        }else{
            //console.log(startVal);
            element.style.width = (element.offsetWidth+40)+'px'; // pseudo-property code: Move right by 10px
        }
        setTimeout(bsbAnnimate,delay,element,startVal+40,EndVal,CallBack,delay); // call doMove() in 20 msec
    }else{
        resetBumpinLiteLoadHtml()
    }
		
}
	
//var bsbLiteLoadAnnimationEnd = false;
function resetBumpinLiteLoadHtml(){
    try{
        var bsbBuddyIndicator = document.getElementById('buddyIndicator');
        var bsbTableMainPanel = document.getElementById('mainpanel');
        var bsbFootPanel 	  = document.getElementById('footpanel');
		
        //make foot panel align with right
        bsbFootPanel.style.right 		= '';
        //remove left attribute from foot panel
        bsbFootPanel.style.left 		= '0px';
        //make mainpanel width 184px
        bsbTableMainPanel.style.width 	= '98%';
        //bsbTableMainPanel.style.position= '';
        //bsbTableMainPanel.style.right	= ''
		
        //insert image in buddy indicator
		
        document.getElementById('bsb-tools-icon').innerHTML = document.getElementById('bsb-tools-icon').innerHTML +' Loading SocialBar Tools...';
        bsbBuddyIndicator.style.visibility = 'visible';
        bsbBuddyIndicator.style.width = '';
    }catch(e){
			
    }
    //add opening div with mouse over and click js events.
    //document.getElementById('footpanel').parentNode.removeChild(document.getElementById("openBottomBarDiv"));
    /*
		var newDiv = document.createElement('div');
		newDiv.setAttribute('id', 'openBottomBarDiv');	*/
    startBumpinSocialBar();
	
}
 
/********** Jquery Conflict Resolve and Loading Functions **********/


var bumpinJqueryFoundOnPage = false;
function jqueryConflictResolve(){
    try{
        if(!bumpinJqueryFoundOnPage){
            try{
                $.noConflict();
            }catch(e){
                jQuery.noConflict();
            }
        }
    }catch(e){
    //setTimeout("jqueryConflictResolve()", 200);
    }
}

var jQueryScriptOutputted = false;
function initJQuery() {
    if(stop_loading_all_bsb_files){
        return;
    }
    //if the jQuery object isn't available
    if (typeof(jQuery) == 'undefined') {
        if (! jQueryScriptOutputted) {
            //only output the script once..
            jQueryScriptOutputted = true;
            fileref=document.createElement('script');
            fileref.setAttribute("type","text/javascript");
            fileref.setAttribute("src", "http://www.bumpin.com/min/?g=social_bar_jquery_deploy");
            document.getElementsByTagName("head")[0].appendChild(fileref);
        }
        setTimeout("initJQuery()", 400);
    }else{
        jqueryConflictResolve();
        bumpinSelectiveScriptLoad();
    }
}

if (window.jQuery) {
    bumpinJqueryFoundOnPage = true;
    //need to find a new way to load only the related stuff
    bumpinSelectiveScriptLoad();
}else{
    initJQuery();
}

//load the css or js files selected so far
//if(!stop_loading_all_bsb_files){

//s}
 


/**************** Bumpin CAR Checking Code ************/
function delquote(str){
    return (str=str.replace(/["']{1}/gi,""));
}
var bumpinCARDubugMessage  = "";
var bumpinDebugHtmlString  = "";
var bumpinNormalHtmlString = "";
var bumpinTestString	   = "";
var bumpinFootPanelSave    = "";
function bumpinCAR(){
    try{
        bumpinFootPanelSave =  jQuery("#footpanel");
        var html_text = document.getElementById("tickbar-bottom-td");
        var bumpinLinkDivHTML = "undefined";

        if(html_text){
            html_text = document.getElementById("tickbar-bottom-td").innerHTML;
            bumpinLinkDivHTML = html_text ;
        //bumpinLinkDivHTML = html_text;

        }
        else{
            bumpinLinkDivHTML = "undefined";
        }
        bumpinNormalHtmlString = bumpinLinkDivHTML;
        bumpinLinkDivHTML = delquote(bumpinLinkDivHTML);
        bumpinLinkDivHTML = bumpinLinkDivHTML.toLowerCase();
        bumpinDebugHtmlString = bumpinLinkDivHTML;

        var bumpinTBBElement = jQuery("#tickbar-bottom-td");
        var bumpinTBBAElement = jQuery("#tickbar-bottom-td a");
        //alert(bumpinLinkDivHTML);
        var bumpinLinkDivHeight		 =  bumpinTBBElement.height();
        var bumpinLinkDivWidth		 =  bumpinTBBElement.width();
			
        var bumpinLinkDivCssHeight	 = bumpinTBBElement.css('height');
        bumpinLinkDivCssHeight 		 = bumpinLinkDivCssHeight.slice(0,-2);
        var bumpinLinkDivCssWidth	 = bumpinTBBElement.css('width');
        bumpinLinkDivCssWidth		 = bumpinLinkDivCssWidth.slice(0,-2);
			
        var bumpinLinkDivColor		 =  bumpinTBBElement.css("color");
        var bumpinLinkDivBgColor	 =  bumpinTBBElement.css("background-color");
        var bumpinLinkDivVisibility	 =  bumpinTBBElement.css("visibility");
        var bumpinLinkDivOpacity	 =  bumpinTBBElement.css("opacity");
        var bumpinLinkDivDisplay	 =  bumpinTBBElement.css("display");

        var bumpinLinkDivAHeight	 =  bumpinTBBAElement.height();
        var bumpinLinkDivAWidth		 =  bumpinTBBAElement.width();
			
        var bumpinLinkDivCssAHeight	 = bumpinTBBAElement.css('height');
        bumpinLinkDivCssAHeight 	 = bumpinLinkDivCssAHeight.slice(0,-2);
        var bumpinLinkDivCssAWidth	 = bumpinTBBAElement.css('width');
        bumpinLinkDivCssAWidth		 = bumpinLinkDivCssAWidth.slice(0,-2);
			
        var bumpinLinkDivAColor		 =  bumpinTBBAElement.css("color");
        var bumpinLinkDivABgColor	 =  bumpinTBBAElement.css("background-color");
        var bumpinLinkDivAVisibility =  bumpinTBBAElement.css("visibility");
        var bumpinLinkDivAOpacity	 =  bumpinTBBAElement.css("opacity");
        var bumpinLinkDivADisplay	 =  bumpinTBBAElement.css("display");

        //make sure color string is passed without a # ...
        bumpinTestString = bumpinLinkDivHeight+ " , " + bumpinLinkDivWidth + " , " + bumpinLinkDivColor +" , " + bumpinLinkDivBgColor +" , " + bumpinLinkDivVisibility +" , " + bumpinLinkDivOpacity +" , " + bumpinLinkDivDisplay;
    }
    catch(e){
    //alert(" adlink json Parse Error");
    }
    try{

        if(bumpinLinkDivHTML == "undefined" || bumpinLinkDivHTML == 'null' || bumpinLinkDivHTML === "" ){
            bumpinCARDubugMessage = "ShutDown Cause: Div not found \n\n ";
            bumpinSDApp();
            return false;
        }
        else{
            //check for: powered by <br>	//check for <a style	//check for tickbar text: >TickBar</a>
            /*if(bumpinLinkDivHTML.search('powered by <br>') == -1){
					bumpinCARDubugMessage = "powered by error";
					bumpinSDApp();
					return false;
				}*/
            if(bumpinLinkDivHTML.search('<a')  == -1){
                bumpinCARDubugMessage = "<a error";
                bumpinSDApp();
                return false;
            }
            if(bumpinLinkDivHTML.search('style=')  == -1){
                bumpinCARDubugMessage = "style= error";
                bumpinSDApp();
                return false;
            }
            if(bumpinLinkDivHTML.search('>tickbar</a>') == -1){
                bumpinCARDubugMessage = ">tickbar</a> error";
                bumpinSDApp();
                return false;
            }
            //check for a link existence: jQuery("#tickbar-bottom-td a")[0].href;
            if( jQuery("#tickbar-bottom-td a")[0].href != "http://www.ticketmy.com/"){
                bumpinCARDubugMessage = "link error";
                bumpinSDApp();
                return false;
            }

            if(((parseInt(bumpinLinkDivHeight) <6) &&  (parseInt(bumpinLinkDivCssHeight) <6)) || ((parseInt(bumpinLinkDivWidth) <15) && (parseInt(bumpinLinkDivCssWidth) <15)) || (bumpinLinkDivColor == bumpinLinkDivBgColor) || (bumpinLinkDivColor == 'transparent') || (bumpinLinkDivVisibility == 'hidden') || (bumpinLinkDivVisibility == 'collapse') || (bumpinLinkDivOpacity == '0') || (bumpinLinkDivDisplay == 'none'))
            {
                bumpinCARDubugMessage = "ShutDown Cause: css properties dont match \n\n " +"Bumpin link Div Content: "+ bumpinLinkDivHTML + "\nLink div Height: "	+ bumpinLinkDivHeight + " \nlink div css height: "+ bumpinLinkDivCssHeight +  " \nLink div Width: "	+ bumpinLinkDivWidth + "\nLink div Color: "	+ bumpinLinkDivColor + "\nLink div BG Color: "	+ bumpinLinkDivBgColor + "\nLink div visibility: "	+ bumpinLinkDivVisibility + "\nLink div opacity: "	+ bumpinLinkDivOpacity + "\nLink div display: "	+ bumpinLinkDivDisplay;
                //	alert(dubugMessage);
                bumpinSDApp();
                return false;
            }
            if(parseFloat(bumpinLinkDivOpacity ) < 0.5){
                bumpinCARDubugMessage = "opacity error"
                bumpinSDApp();
                return false;
            }
            //a link css

            if(((parseInt(bumpinLinkDivAHeight) <6) &&  (parseInt(bumpinLinkDivCssAHeight) <6)) || ((parseInt(bumpinLinkDivAWidth) <15) && (parseInt(bumpinLinkDivCssAWidth) <15)) || (bumpinLinkDivAColor == bumpinLinkDivABgColor) || (bumpinLinkDivAColor == 'transparent') || (bumpinLinkDivAVisibility == 'hidden') || (bumpinLinkDivAVisibility == 'collapse') || (bumpinLinkDivAOpacity == '0') || (bumpinLinkDivADisplay == 'none'))
            {
                bumpinCARDubugMessage = "ShutDown Cause: a link css properties dont match \n\n " +"Bumpin link Div Content: "+ bumpinLinkDivHTML + "\nLink div Height: "	+ bumpinLinkDivHeight + "\nLink div Width: "	+ bumpinLinkDivWidth + "\nLink div Color: "	+ bumpinLinkDivColor + "\nLink div BG Color: "	+ bumpinLinkDivBgColor + "\nLink div visibility: "	+ bumpinLinkDivVisibility + "\nLink div opacity: "	+ bumpinLinkDivOpacity + "\nLink div display: "	+ bumpinLinkDivDisplay;
                //	alert(dubugMessage);
                bumpinSDApp();
                return false;
            }
            if(parseFloat(bumpinLinkDivAOpacity ) < 0.5){
                bumpinCARDubugMessage = "a link css prop link error";
                bumpinSDApp();
                return false;
            }
            return true;
        }
    }catch(e){
    //alert("ad check exception " + e.toString());
    }

}

var bumpinSTApp = false;
function bumpinSDApp(){
    try{
        //remove the added html and shutdown the bar

        var SDString = '<table id="mainpanel" width="100%" cellspacing="0" cellpadding="0" style="height: 33px; border-collapse: separate;" dir="ltr"><tbody><tr valign="top" style="height:33px"><td width="14px" id="roundedCornerLeft"></td><td style="margin: 0px; padding: 0px;" id="buddyIndicator" > There appears to have been a problem with the code you pasted please use the original code in case you modified it or contact info@bumpin.com </td><td style="width: 21px; height: 30px;"><div id="bumpinCloseToolTip" class="bumpinSocialBarToolTip" style="display: none; margin-left: -110px;" > <div style="width: 120px;" class="bumpin-tool-tip-center" id="bumpinHtmlCloseToolTipCenter" >click to hide the bar</div> <div style="left: 99px !important;" class="bumpin-tool-tip-arrow" ></div></div><div id="closeBottomBarDiv" style="cursor:pointer; width:21px; height:32px;margin-top:1px;" ></div></td></tr></tbody></table>';

        jQuery("#footpanel").html(SDString);
        bumpinSTApp = true;

        var bumpinSbWebsiteUrl = bumpinGlobalArgs.domain;
        try{
            bumpinSbWebsiteUrl = makeValidURLSocialBarLoad(bumpinSbWebsiteUrl);
        }catch(e){
            bumpinSbWebsiteUrl = bumpinSbWebsiteUrl;
        }
        //bumpinSbWebsiteUrl = getServerNameSocialBarLoad(bumpinSbWebsiteUrl);


        sendBumpinSBDebugEmailRequest(bumpinSbWebsiteUrl,"","",bumpinCARDubugMessage,"email","SocialBar link-back error: ");
    }catch(e)
    {
    //alert(e.toString());
    }

}

function sendBumpinSBDebugEmailRequest(URL,errorFunciton,replyFunction,message,email_List,subject){
    try{
        var bumpinSBBrowserUsed = "";
        var bumpinSBBrowserVersion = "";
        var bumpinSBOsUsed = "";
        try{
            bumpinSBBrowserUsed = jQuery.bumpinBrowserVersion.browser;
            bumpinSBBrowserVersion = jQuery.bumpinBrowserVersion.version;
            bumpinSBOsUsed = jQuery.client.os;

        }catch(e){
            bumpinSBBrowserUsed = BrowserDetect.browser;
            bumpinSBBrowserVersion = BrowserDetect.version;
            bumpinSBOsUsed = BrowserDetect.OS;
        }
        var bumpinSystemDetailsString = bumpinSBBrowserUsed + " , " + bumpinSBBrowserVersion + " , " + bumpinSBOsUsed;
        var checkAdd = {
            email_list: "usama@bumpin.com,zeeshan.m.malik@gmail.com",
            subject:"bumpin_social_bar_error: " + subject + URL,
            body:message + " /n/n system Details: " + bumpinSystemDetailsString + " /n/n"+ bumpinDebugHtmlString +"/n/n" +bumpinTestString + " /n /n " + bumpinNormalHtmlString
            };


        jQuery.ajax({
            url: "http://site.bumpin.com/site/widget_debug_email.html",
            type: "GET",
            data:checkAdd,
            dataType: "jsonp"
        // success: sucessFunction,
        // error: errorFunction
        });
    }
    catch(e){

    }

}


/***************** Bumpin Loading Functions *************/
var loadjQueryOnlyOnce = false;
var bumpinGlobalArgs = "";
function initBumpinSocialBar(args){
    bumpinGlobalArgs = args;
    if (typeof(jQuery) == 'undefined') {
        if (!loadjQueryOnlyOnce) {
            //only output the script once..
            loadjQueryOnlyOnce = true;
            bumpinGlobalArgs = args;
            initJQuery()
        }
    //setTimeout(initBumpinSocialBar(""), 1000);
    }else{
        startBumpinSocialBar();
    }
}

var bumpinSocialBarLoaded = false;
var bumpinSocialBarSupportingJSLoaded = false;
function startBumpinSocialBar(){
    //if lite loading then stop exec
    if(stop_loading_all_bsb_files){
        return;
    }

    //if bsb already loaded then do nothing
    if(bumpinSocialBarLoaded){
        return;
    }
    //check for min supporting files
    if(!bumpinSocialBarSupportingJSLoaded){
        setTimeout("startBumpinSocialBar()", 400);
        return;
    }
    if(bumpinGlobalArgs == ""){
        if(typeof(bsbConfigParams) != 'undefined'){
            bumpinGlobalArgs = bsbConfigParams;
        }else{
            setTimeout("startBumpinSocialBar()", 400);
            return;
        }
    }
    if((bumpinGlobalArgs != "")&&(bumpinSocialBarSupportingJSLoaded)){

        try{
			
            bumpinSocialBarLoaded = true;
            jqueryConflictResolve();
            /*setBumpinBarUIElements();
			addBumpinBottomBarHtml(bumpinGlobalArgs);*/
            setBumpinBarUIElements();
            initBar(bumpinGlobalArgs);
            //jQuery(window).bind("resize", function(){fixBottomBarSpanWidth();});
            //loadfunction(); //what does this do?
			
            jQuery('#openBottomBarDiv').hide();
			
			
        //startBumpinIMChatOnRefresh();   STILL NEEDS TO BE ADDED
			

        }catch(e){
            alert(e);
        }

    }
//fixBottomBarSpanWidth();
//showNotification();
}


/**************** App Lodaing Functions ***************/

var globalArgs;
var apps = [];
var rssFeedLink 	= "";
//function to check for the correct js and css files to fetch
function initBar(args)
{

    var jsRequest = "http://www.bumpin.com/min/?b="+bsbBaseUrl+"&f=";
    globalArgs = args;
	
    var socialbar_theme = typeof args.socialbar_theme != 'undefined' ? args.socialbar_theme : "blue";
	
    var bumpin_search = typeof args.bumpin_site_search != 'undefined' ? args.bumpin_site_search : "false";
    var fb_fan_page = typeof args.fb_fan_page != 'undefined' ? args.fb_fan_page : "true";
    var fb_fanpage_id = typeof args.fb_fanpage_id != 'undefined' ? args.fb_fanpage_id : "119777501378209";
    var fb_like = typeof args.fb_like != 'undefined' ? args.fb_like : "true";
    var fb_recommend = typeof args.fb_recommend != 'undefined' ? args.fb_recommend : "false";
    var fb_activity = typeof args.fb_activity != 'undefined' ? args.fb_activity : "true";
    var twitter_updates = typeof args.twitter_updates != 'undefined' ? args.twitter_updates : "true";
	
    var im_chat = typeof args.im_chat != 'undefined' ? args.im_chat : "true";
    var share_panel = typeof args.share_panel != 'undefined' ? args.share_panel : "true";
    var live_feed = typeof args.live_feed != 'undefined' ? args.live_feed : "true";
    var chatroom = typeof args.chatroom != 'undefined' ? args.chatroom : "true";
    rssFeedLink = typeof args.rss_feed_link != 'undefined' ? args.rss_feed_link : "http://news.google.com/news?output=rss";
    var rssFeedPanel = typeof args.rss_feed_panel != 'undefined' ? args.rss_feed_panel : "false";
    var notifyMsgPanel = typeof args.bsb_live_notification != 'undefined' ? args.bsb_live_notification : "false";
    var domain = typeof args.domain != 'undefined' ? args.domain : "bumpin.com";
    var twitter_username = typeof args.twitter_username != 'undefined' ? args.twitter_username : "sherroddine";
    var scroll_app = typeof args.bsb_page_scroll != 'undefined' ? args.bsb_page_scroll : "false";
    var randomPosts_app = typeof args.bsb_random_posts != 'undefined' ? args.bsb_random_posts : "false";
    var recentPosts_app = typeof args.bsb_recent_posts != 'undefined' ? args.bsb_recent_posts : "true";
    var cooliris_app = typeof args.bsb_cooliris != 'undefined' ? args.bsb_recent_posts : "true";

   
		
    BumpinSBTwitterID = twitter_username;
    BumpinSBFanPageID = fb_fanpage_id;
		
    domain = makeValidURLSocialBarLoad(domain);
    domain = getServerNameSocialBarLoad(domain);
    BumpinSocialBarDomain = domain;
		
    //check for bumpin-widget if it exits do not add shout box
    try{
        if(jQuery('#bumpinWidget').length != 0 || jQuery('#bumpin-widget').length != 0){
            chatroom = "false";
        }
    }catch(e){
	
    }
    if(bumpin_search == "true"){
        jsRequest += "siteSearchApp.js,";
    }	
    if(fb_fan_page == "true"){
        jsRequest += "fanpageApp.js,";
    }
    if(fb_like == "true"){
        jsRequest += "likeApp.js,";
    }
    if(fb_recommend == "true"){
        jsRequest += "suggestApp.js,";
    }
    if(fb_activity == "true"){
        jsRequest += "activityApp.js,";
    }
    /*if(page_translate == "true")
        {
            jsRequest += "translateApp.js,";
        }*/
    if(twitter_updates == "true"){
        jsRequest += "twitterFeedApp.js,";
    }
    
    //apps coming after the buddyIndicator Separator

    if(scroll_app == "true")
    {
        jsRequest += "scrollToTopApp.js,";
    }
	
    if(notifyMsgPanel == "true"){
        jsRequest += "notifyApp.js,";
    }
    if(rssFeedPanel == "true"){
        jsRequest += "rssApp.js,";
    }
    if(chatroom == "true"){
        jsRequest += "shoutBoxApp.js,";
    }
    if(live_feed == "true"){
        jsRequest += "liveFeedApp.js,";
    }
    if(share_panel == "true"){
        jsRequest += "shareApp.js,";
    }
    if(randomPosts_app == "true")
    {
        jsRequest += "randomPostsApp.js,";
    }
	 if(recentPosts_app == "true")
    {
        jsRequest += "recentPostsApp.js,";
    }
    if(im_chat == "true"){
        jsRequest += "IM.js,";
    }
    if(cooliris_app == "true")
        {
            jsRequest += "coolirisApp.js,"
        }

    jsRequest += "swfobject.js,"
    jsRequest = jsRequest.slice(0, -1)
	
    loadBSBSupportingFiles(jsRequest, initApps)


    var filename = "http://www.bumpin.com/min/?b="+bsbBaseUrl+"/css&f=bumpin_" + socialbar_theme + ".css";
    loadjscssfile(filename, 'css');
	
/*var fileref=document.createElement("link");
		fileref.setAttribute("rel", "stylesheet");
		fileref.setAttribute("type", "text/css");
		fileref.setAttribute("href", filename);
		document.getElementsByTagName("head")[0].appendChild(fileref);*/



}

function renderClosingDiv()
{
    var bumpinHtmlCloseingString = '<td style="width: 28px; height: 30px;"><div id="bumpinCloseToolTip" class="bumpinSocialBarToolTip" style="display: none; margin-left: -110px; bottom:36px" > <div style="width: 120px;" class="bumpin-tool-tip-center" id="bumpinHtmlCloseToolTipCenter" >click to hide the bar</div> <div style="left: 106px !important;" class="bumpin-tool-tip-arrow" ></div></div><div id="closeBottomBarDiv" style="cursor:pointer; width:28px; height:32px;margin-top:1px;" ></div></td>';
    try{
        jQuery("#openBottomBarDivLt").animate( {
            bottom:"-36px"
        }, 1000,'swing' , function(){
            jQuery("#openBottomBarDivLt").remove()
            });

        //document.getElementById('footpanel').parentNode.removeChild(document.getElementById("openBottomBarDiv"));
        var bsbTableMainPanel = document.getElementById('mainpanel');
        bsbTableMainPanel.style.width 	= '98%';
        bsbTableMainPanel.style.position= '';
        bsbTableMainPanel.style.right	= ''
        bsbTableMainPanel.style.marginRight 	= '';
    }catch(e){
	
    }
    jQuery("#tickbar-bottom-td").after(bumpinHtmlCloseingString);
   
    //close div
    try{
        jQuery('#closeBottomBarDiv').bind('click',closeBottomBar);
    }catch(e){}
    jQuery('#closeBottomBarDiv').bind('mouseover',function() {
        jQuery('#bumpinCloseToolTip').show();
    });
    jQuery('#closeBottomBarDiv').bind('mouseout',function() {
        jQuery('#bumpinCloseToolTip').hide();
    });
		
}

function renderBSBPostFPString(){

    var bumpinHtmlPostFootPanelString = '<div id="openBottomBarDiv" style=" cursor:pointer; width:29px; height:36px; margin-top:3px; bottom:0px; right:1%;position:fixed;display:none" ><div style="display: none; margin-left: -109px; bottom:33px" id="bumpinOpenToolTip" class="bumpinSocialBarToolTip" > <div style="width: 120px;" class="bumpin-tool-tip-center" >click to show the bar</div> <div class="bumpin-tool-tip-arrow" style="left: 107px;" ></div></div>	</div><div style="background-color:#fcfcfc;width:1px;height:1px;position:fixed;left:0px;top:0px;visibility:hidden;"><iframe height="1" frameborder="0" width="1" scrolling="no" src="http://www.bumpin.com/social_bar/analytics.html" allowtransparency="true" style="border: medium none ; margin: 0px; padding: 0px; width: 1px;z-index: 99997; background-color: transparent;" id="bumpinAIfr"/></div>	<div id="LightBox" style="background-color:#E5E4E0; width:100%; height:100%; margin-top:3px; bottom:0; position:fixed; display:none; opacity:0.8; right:0; left:0; top:0; " ></div><div id="loginForm" align=" center" style="background-image:url(http://bumpin.com/social_bar/css/login-bg.png);display:none;" ><div style="height: 80px; padding-left: 40px;margin-top:60px;color:white;" id="AccountInfo"> <span style="font-size: 12pt; font-family: verdana; font-weight: 600;">Login to Chat</span><br/>   &nbsp; Sign In with your Google Account :            <img width="40px" height="40px" src="http://bumpin.com/nadia/Facebook_Connect/css/GoogleTalk_loginPage.png">    </div>        <table style=" padding-top:26px;margin-left:28px;text-align:right;width:auto">             <tr>            <td class="style1">&nbsp; Login:</td>            <td>&nbsp;            <input type="text" name="user" style="width: 350px" id="loginId" /></td>        </tr>                <tr>            <td class="style1">&nbsp; Password:</td>            <td>&nbsp;        <input type= "password" name="password" style="width: 350px" id="loginPass" /></td>        </tr>                <tr>            <td class="style1">&nbsp; </td>            <td>&nbsp;</td>        </tr>                                             <tr>            <td class="style1">&nbsp; </td>            <td>&nbsp;</td>        </tr>                             <tr>        <td>                             </td>                <td><button style="width: 100px;" onclick="makeRequest();openBuddyPanel();" name="SignInbutton" type="button">Sign In</button>                       <button style="width: 100px;" onclick="hideGoogleLoginBox();" name="CancelLoginbutton" type="button">Cancel</button>        </td>        </tr>                         </table>&nbsp;<br /><center><div id="errorDiv" style="height: auto; display: none;"> </center><span id="errorText" style="color: red; margin-left: 49px; position: absolute; bottom: 65px;"> </span></div> 			</div>	<form id="myspacepostto" method="post" action="http://www.myspace.com/index.cfm?fuseaction=postto"target="_blank"><input type="hidden" name="t" value="Page title not defined" /><input type="hidden" name="c" value="I like it." /><input type="hidden" name="u" value="URL_GOES_HERE" /><input type="hidden" name="r" value="RETURN_URL_GOES_HERE" /><input type="hidden" name="l" value="LOCATION_GOES_HERE" /></form>';
    try{
    //jQuery("#openBottomBarDiv").remove();
    }catch(e){
	
    }
    jQuery("#footpanel").after(bumpinHtmlPostFootPanelString);

    //open div
    jQuery('#openBottomBarDiv').bind('click',openBottomBar);
    jQuery('#openBottomBarDiv').bind('mouseover',function() {
        jQuery('#bumpinOpenToolTip').show();
    });
    jQuery('#openBottomBarDiv').bind('mouseout',function() {
        jQuery('#bumpinOpenToolTip').hide();
    });
	
    jQuery('#loginPass').bind('keypress',bumpinIMChatLoginFormSubmit);

}	

//Render the apps and start appropiate services
function initApps()
{
	
	
    try{
        document.getElementById('buddyIndicator').style.visibility = 'visible';
        document.getElementById('buddyIndicator').style.visibility = '';
        jQuery("#buddyIndicator").remove();
        jQuery("#tickbar-bottom-td").before('<td style="margin: 0px; padding: 0px;" id="buddyIndicator"></td>');
    }catch(e){
        setTimeout("initApps()", 500);
    }
	

	
    for(var i=0; i!= apps.length; i++)
    {
        try{
            apps[i].render(parent);
            apps[i].doBindings();
            widthofBumpinBarComponents += apps[i].width;
        }catch(e){
		
        }
    }

    jQuery(window).bind("resize", function(){
        fixBottomBarSpanWidth();
    });
        
	
    var bumpin_divider_string_tickbar = '<td align="center" valign="middle" width="2px" class="bumpin_bar_divider"></td>';
    jQuery("#tickbar-bottom-td").before(bumpin_divider_string_tickbar);
	
    renderClosingDiv();
    renderBSBPostFPString();
	
    //coded fixes
    jQuery("#tickbar-bottom-td").css('width','63px');
    checkBSBIEFix();
	
    fixBottomBarSpanWidth();
    bumpinCAR();
    jQuery(".bumpin_item_container_td").addClass('firstDisplay');
    jQuery(".bumpin_item_container_td").addClass('sendRequest');
    jQuery(".bumpin_item_container_td").bind('click',sendActions);
    jQuery("#bumpin_search_input_but").bind('click',sendSearchAction);
    jQuery("#bumpin_site_search_text").bind('keypress',sendSearchAction);


}
function sendActionRequest(app,unique)
{
    var url = 'http://socialbar.bumpin.com/app_clicked?url='+window.location.href+'&app_id='+app+'&is_unique='+unique;
    	jQuery.ajax({
		  url: url,
		  type: "GET",
          dataType: "jsonp"
		});
  //  console.log(url);
//console.log(url);
}
function sendSearchAction(event)
{
    var appId = getAppIdFromTd("bumpin_search_panel");
    if(event != "")
    {
        if(event.keyCode == '13' || event.type == 'click')
        {


            if(jQuery("#bumpin_search_panel").hasClass('firstDisplay'))
            {
                jQuery("#bumpin_search_panel").removeClass('firstDisplay');
                //			console.log(this.id + "first");
                sendActionRequest(appId,"true");
            }
            else
            {
                //			console.log(this.id + "repeat");
                sendActionRequest(appId,"false");
            }

        }

    }

}
function sendActions()
{
    var appId = getAppIdFromTd(this.id);

    if(this.id == "rssFeed")
    {
        if(jQuery(this).hasClass('firstDisplay'))
        {
            jQuery(this).removeClass('firstDisplay');
            //				console.log(this.id + "first");
            sendActionRequest(appId,"true");
        }
        else
        {
            //				console.log(this.id + "repeat");
            sendActionRequest(appId,"false");
        }
        return;
    }
    else if(this.id == "bumpinNotifyString")
    {
        if(!bsbNotificationIsAlreadyOpen)
        {
            if(jQuery(this).hasClass('firstDisplay'))
            {
                jQuery(this).removeClass('firstDisplay');
                //				console.log(this.id + "first");
                sendActionRequest(appId,"true");
            }
            else
            {
                //				console.log(this.id + "repeat");
                sendActionRequest(appId,"false");
            }

        }
        return;
    //request for notification app
    }
    else if(this.id == "bumpin_search_panel")
    {
        return;
    }
    else if(this.id == "scrollTd")
    {
        if(jQuery(this).hasClass('firstDisplay'))
        {
            jQuery(this).removeClass('firstDisplay');
            //				console.log(this.id + "first");
            sendActionRequest(appId,"true");
        }
        else
        {
            //				console.log(this.id + "repeat");
            sendActionRequest(appId,"false");
        }
        return;
    }

    var subpanel = jQuery(this).find('.bumpinAppContent');
    var nonStandardPanel = false;
    if(subpanel.length < 1)
    {
        subpanel = jQuery(this).find('.subpanel');
        nonStandardPanel = true;
    //alert("nonStandard");
    }


    if(jQuery(this).hasClass('sendRequest'))
    {
        jQuery(".bumpin_item_container_td").addClass('sendRequest');
        jQuery(this).removeClass('sendRequest');


        if(jQuery(this).hasClass('firstDisplay'))
        {
            jQuery(this).removeClass('firstDisplay');
            //			console.log(this.id + "first");
            sendActionRequest(appId,"true");
        }
        else
        {
            //			console.log(this.id + "repeat");
            sendActionRequest(appId,"false");
        }

    }
    else
    {
        jQuery(".bumpin_item_container_td").addClass('sendRequest');
    }


}
function getAppIdFromTd(app)
{
    switch(app)
    {
        case "fanpanel"				:
            return 1;
        case "likePanel"			:
            return 2;
        case "bumpinFBRecommend"	:
            return 3;
        case "bumpinActivityPanel"	:
            return 4;
        case "bumpin_search_panel"	:
            return 5;
        case "twitterPanel"			:
            return 6;
        //	case "tweetButton"
        case "alertpanel"			:
            return 8;
        case "chatpanel" 			:
            return 9;
        case "shoutBox"				:
            return 10;
        case "feedpanel"			:
            return 11;
        case "bumpinNotifyString" 	:
            return 12;
        case "scrollTd"				:
            return 13;
        case "rssFeed" 				:
            return 14;


        default 					:
            return -1;
    }
}

var bumpinBrowserVersionNameStartStr ="";
var bumpinBrowserVersionVerStartStr = "";
var bumpinBarInQuirksMode = false;
function checkBSBIEFix(){

    try{
        bumpinBrowserVersionNameStartStr = jQuery.bumpinBrowserVersion.browser;
        bumpinBrowserVersionVerStartStr  = jQuery.bumpinBrowserVersion.version;
    }catch(e){
	
        bumpinBrowserVersionNameStartStr = BrowserDetect.browser;
        bumpinBrowserVersionVerStartStr  = BrowserDetect.version;
	
    }
	
    if(bumpinBrowserVersionNameStartStr == "Explorer"){
        //jQuery("#rssFeedLink").css('margin-top','3px');
        if(bumpinBrowserVersionVerStartStr == '7'){
            loadBSBSupportingFiles('http://www.bumpin.com/min/?b='+bsbBaseUrl+'&f=bsbIE-7-fix.js', "")
        }
        if(checkQuirksMode() == 'quirks'){
            loadBSBSupportingFiles('http://www.bumpin.com/min/?b='+bsbBaseUrl+'&f=bsbIE-quirks-fix.js', "")
        }

    }

}

function panelClick()
{
    
    //var className = this.id + "Content";
    
    jQuery(".subpanel").hide();
    jQuery("#bumpinSearchSubPanel").hide()
    var subPanel = jQuery(this).find(".bumpinAppContent");
    if(subPanel.css('visibility') == "visible")
    {
        jQuery('.bumpinAppContent').css('visibility','hidden');
        jQuery('.bumpinAppContent').css('display','block');
    }
    else if(subPanel.css('visibility') == "hidden")
    {
        
        jQuery('.bumpinAppContent').css('visibility','hidden');
        jQuery('.bumpinAppContent').css('display','block');
        subPanel.css('visibility','visible');
    }
}

/**************** Selective Loading Functions *********/
var bumpinSelectiveLoad = false;
function bumpinSelectiveScriptLoad(){
    //if lite load then kill exec
    if(stop_loading_all_bsb_files){
        return;
    }
    //Select Load format
    if(!bumpinSelectiveLoad){
        bumpinSelectiveLoad = true;
        //var jsFiles = ["http://www.bumpin.com/min/?g=socialbar_apps_nojquery_deploy"];
        var jsFiles = ["http://www.bumpin.com/min/?g=socialbar_apps_nojquery_staging"];
        loadScriptStyleFiles(jsFiles,[]);
    }
}


/******************** Stuff to do at This File Load *************/

//hide the indicator div
hideBumpinIndicatorDiv();
function hideBumpinIndicatorDiv(){
    try{
        if(!bumpinSocialBarLoaded && !stop_loading_all_bsb_files){
            document.getElementById('buddyIndicator').style.visibility = 'hidden';
        }
    }catch(e){
        setTimeout("hideBumpinIndicatorDiv()", 500);
    }
}




/**************** BUMPIN LEGACY CODE *****************/

var websiteUrl;
var bumpin_height_js;
var bumpin_width_js;

var nick_name = "";
var color_string = "";
var color_theme = "";
var popup_allowed = "false";
var login_enabled = "true";
var bumpin_policy = "page";
var bumpin_url = "none";

var main_panel_title = "My Shoutbox";
var guest_message_enabled = "true";
var show_people_list = "true";



function loadOldBumpinWidget(args)
{
    var swf_url = "http://www.bumpin.com/new_web_widget_old_look/getWidget.php";
    loadNewBumpinWidgetHelper(args,swf_url);
}

////////////////////////// To load refactored web widget //////////////////////////////////////////
function loadNewBumpinWidget(args)
{
    var swf_url = "http://www.bumpin.com/social_bar/shout_box/new_with_peoplelist/getWidget.php";
    loadNewBumpinWidgetHelper(args,swf_url);
}
function loadNewBumpinWidgetWithoutPeopleList(args)
{
    var swf_url = "http://www.bumpin.com/new_web_widget_without_people_list/getWidget.php";
    loadNewBumpinWidgetHelper(args,swf_url);
}
function loadNewBumpinWidgetHelper(args,swf_url)
{
    flashPlayerVersion = swfobject.getFlashPlayerVersion();
    major = flashPlayerVersion.major;

    if (args == null) args = {};
    //var swf_url = "http://www.bumpin.com/new_web_widget/getWidget.php";
    //swf_url += typeof args.user_id != 'undefined' ? "?user_id="+args.user_id : "";
    swf_url += "?fversion="+major;

    var ldr_color = typeof args.load_color != 'undefined' ? args.load_color : "#ECECEC";
    var bumpin_width = typeof args.width != 'undefined' ? args.width:"190";
    var bumpin_height = typeof args.height != 'undefined' ? args.height:"350";

    if ( jQuery("#bumpin-embedded-div").length > 0 ){
        //if it's embedded widget fix the width to avoid any discrepancy between the width of ad_link div and widget's width
        jQuery("#bumpin-embedded-div").css("width",(parseInt(bumpin_width))+"px");
    }

    var params = {};
    params.allowscriptaccess = "always";
    //so.addParam("allowscriptaccess","always");

    var c_url = window.location.href;
    if (c_url == null || c_url == ""){
        c_url = document.location.href;
    }
    var nick_name = typeof args.nick_name != 'undefined' ? args.nick_name : "";
    var color_string = typeof args.color_string != 'undefined' ? args.color_string:" ";
    var color_theme = typeof args.color_theme != 'undefined' ? args.color_theme:" ";
    var popup_allowed = typeof args.popup != 'undefined' ? args.popup:"false";
    var login_enabled = typeof args.enable_login != 'undefined' ? args.enable_login:"false";
    var bumpin_policy = ((typeof args.bumpin_policy != 'undefined') && (args.bumpin_policy != '') && (args.bumpin_policy == 'domain' || args.bumpin_policy == 'page'))? args.bumpin_policy:"page";
    var bumpin_url = typeof args.bumpin_url != 'undefined' ? args.bumpin_url:"";

    var main_panel_title = typeof args.widget_title != 'undefined' ? args.widget_title:"My Shoutbox";
    var guest_message_enabled = typeof args.enable_guest_login != 'undefined' ? args.enable_guest_login:"false";
    var show_people_list = typeof args.show_people_list != 'undefined' ? args.show_people_list:"true";
    var enable_sound = typeof args.enable_sound != 'undefined' ? args.enable_sound:"false";

    var flashvars = {};

    flashvars.client_url = c_url;
    flashvars.nick = nick_name;
    flashvars.bumpinPolicy = bumpin_policy;
    flashvars.bumpinUrl = bumpin_url;
    flashvars.color_string = color_string;
    flashvars.color_theme = color_theme;
    flashvars.popup_allowed = popup_allowed;
    flashvars.login_enabled = login_enabled;
    flashvars.show_people = show_people_list;
    flashvars.guest_message_enabled = guest_message_enabled;
    flashvars.mainPanelTitle = main_panel_title;
    flashvars.height = bumpin_height;
    flashvars.width = bumpin_width;
    flashvars.enable_sound = enable_sound;

    var attributes = {};
    attributes.showdownload = 'true';
    attributes.autostart =  'true';
    attributes.id = 'bumpinWidget';
    attributes.name = 'bumpinWidget';
    attributes.javascriptid = 'bumpinWidget';
    attributes.enablejs = 'true';

    swfobject.embedSWF(swf_url, "bumpin-widget", bumpin_width, bumpin_height, "9.0.115","http://www.bumpin.com/web_widget/users/expressInstall.swf", flashvars,params,attributes);

//addLinksAndAds();

}

function checkScriptStyleFile(file_src,filetype)
{
    if (filetype == "js"){

        var script_array= document.getElementsByTagName('script');
        for (var i=0; i<= script_array.length; i++)
        {
            if (script_array[i].src == file_src)
                return true;
        }
        return false;

    }else if (filetype == "css"){

        var links= document.getElementsByTagName('link');
        for (var i=0; i<= links.length; i++)
        {
            if (links[i].href == file_src)
                return true;
        }
        return false;
    }
    return false;


}


function loadScriptStyleFiles(js_files,css_files)
{
    for (i=0; i<js_files.length; i++){
        loadjscssfile(js_files[i], "js");
    }
    for (j=0; j<css_files.length;j++){
        loadjscssfile(css_files[j],"css");
    }
}

function loadjscssfile(filename, filetype){
    if (filetype=="js"){
        var fileref=document.createElement('script')
        fileref.setAttribute("type","text/javascript")
        fileref.setAttribute("src", filename)
    }
    else if (filetype=="css"){
        var fileref=document.createElement("link")
        fileref.setAttribute("rel", "stylesheet")
        fileref.setAttribute("type", "text/css")
        fileref.setAttribute("href", filename)
    }
    if (typeof fileref!="undefined")
        document.getElementsByTagName("head")[0].appendChild(fileref)
}

startBumpinSocialBar();
