var _CONFIG = {"locale": {"lang": "all", "msgBundle": {"untranslate_action": "Original", "realtime_btn_pause_title": "Pause real-time updates", "noSavedSearches": "You don't have any saved searches yet", "signin_twitterpassword_label": "password:", "gallery_title": "Live Pictures", "signin_twitterlogin_label": "user name:", "savedQuery_name_label": "Name", "realtime_btn_resume_title": "Resume real-time updates", "send_a_message": "Send a message", "googlenews_title": "News", "savedQuery_description_label": "Description", "search_adv_language": "Language", "search_languagePrefs_show": "Preferences", "realtime_speed_title_H": "Tweets Per Hour", "translate_action": "Translate", "favorite_action": "Favorite", "tagline": "Cutting through the noise", "highlights_title": "Highlights", "about_title": "about&nbsp;twazzup", "trendmakers_title": "Top Trendmakers", "about_link": "About", "speakers_title": "Speakers", "realtime_title": "Real-time tweets for", "savedQuery_delete_button_label": "Delete", "signin_error": "Wrong user name or password", "save_search_button": "Save this Search", "search_removed_notification": "Search was removed", "tweet_this_page": "Share this page", "more_results": "More results", "hottopics_label": "Hot&nbsp;Topics", "signin_cancel_button_label": "Cancel", "signin_button_label": "Sign in", "search_button": "Search", "realtime_pendingTweetsMessage_1": "<b>1<\/b> new result. <a href='#' class='btnRtRefresh'>Show it<\/a> or <a href='#' class='btnRtResume'>resume real-time updates<\/a>.", "savedSearches_label": "My Searches", "links_title": "Top Links", "any_language": "Any language", "sponsors_title": "Sponsors", "featuredtopics_label": "Featured", "savedQuery_save_button_label": "Save", "realtime_pendingTweetsMessage_0": "<b>Paused<\/b>, press <a href='#' class='btnRtResume'>play<\/a> to resume real-time updates.", "vids_title": "Related Videos", "savedQuery_cancel_button_label": "Cancel", "signout_button_label": "Sign out", "search_languagePrefs_hide": "Hide Preferences", "realtime_pendingTweetsMessage_2": "<\/b> new results. <a href='#' class='btnRtRefresh'>Show them<\/a> or <a href='#' class='btnRtResume'>resume real-time updates<\/a>", "want_to_tweet_signin_now": "Want to tweet? <b>Sign in now!<\/b>", "usersWidget_title": "Community", "signed_in_as": "Signed in as", "search_saved_notification": "Your search was saved", "reply_action": "Reply", "preview_action": "preview"}, "uilang": "en"}, "widgets": {"featured": {"default": [{"q": "\u266b", "style": "background-color:#39A9A8;color:white", "name": "&#9835;"}, {"q": "WOW OR awesome OR \"very cool\"", "style": "background-color:#58AA00;color:white", "name": "wow!"}, {"q": "twazzup -via", "style": "background-color:#45b4da;color:white", "name": "twazzup"}], "directory": []}, "trends": []}, "previewMode": false};
var _LOCALE = _CONFIG.locale;
//var _USERPROFILE = _CONFIG.user;
var _WIDGETS = _CONFIG.widgets;

var _CONTEXT = {};

var TWAZZUP=null;

function toggleAdvSearch(){
	$('#advSearch').slideToggle();
	$('.advSearchToggleButton').toggle();
}

$(function(){
	var lang = _LOCALE.lang;
	var uilang = _LOCALE.uilang;
	$("#preferedLang").val(lang);
	var plr = $("#preferedLanguageReminder");
	var uilangText = $("#preferedLang option[value="+uilang+"]").text();
	var html=[];
	html.push("<input type='radio' name='plrRadio' value='all' id='clearPreferedLang' "+(lang!="all"?"":"checked='checked'")+">"+_LOCALE.msgBundle.any_language+" ");
	var showLangReminder = uilang!="en" || lang!='all';
	if (lang!='all'){
		// show the reminder lang pref
		var langText = $("#preferedLang option[value="+lang+"]").text();
		html.push("<input type='radio' name='plrRadio' value='"+lang+"' checked='checked'> "+langText);
	}
	if (lang!=uilang){
		html.push("<input type='radio' name='plrRadio' id='setPreferedLangToUI' value='"+uilang+"'> "+uilangText);
	}
	plr.html(html.join(""));
	
	// TODO : understand how to handle the UI for profile and custom pages
	//if (showLangReminder) plr.show();
	$("#clearPreferedLang").click(function(){
		$("#preferedLang").val('all');
		$("#searchForm").submit();
	});
	$("#setPreferedLangToUI").click(function(){
		$("#preferedLang").val(uilang);
		$("#searchForm").submit();
	});
	$("#preferedLang").change(function(){
		$("#searchForm").submit();
	});
	$("#searchForm").submit(function(){
		var q = $("#searchBox").val();
		//if (!q) return false;
		// set the cookie for the selected lang ...
		var lang = $("#preferedLang").val();
		if (lang){
			createCookie("lang",lang,365);
		}
		$("#preferedLanguageReminder").text("");
		return true;
	});
	
	_CONTEXT["currentQuery"]=$("#searchBox").val();

	new SavedQueriesWidget();

	TWAZZUP = new Twazzup({config:_CONFIG/*,trends:*/});
	$.extend(_WIDGETS,{
		widgetsParameters:{
		}
		,pipes:{}
	});

	_WIDGETS["page"] = {
			"type":"UserPage",
			"owner":{'twitter_id':14109159,'screen_name':"Capgemini",'lookup':"capgemini",'name':"Capgemini",'profile_image_url':"http://a3.twimg.com/profile_images/1167585893/capgemini_twitter-avatar-lightblue_normal.png"},
			"key":"agd0d2F6enVwciELEgRQYWdlIhdwYWdlOjE0MTA5MTU5OmNhcGdlbWluaQw",
			"lookup":"capgemini",
			"basequery":"capgemini -job -jobs -vacature -ontslagregels",
			"useroverlayQuery":"capgemini -job -jobs -vacature -ontslagregels",
			"title":"The buzz on Capgemini",
			"desc":"Consulting, Technology and Outsourcing Services",
			"skin":{"css":"/* CSS for page */\nbody {\nbackground: #0099b5\n}\n\n#twRCol .sectionTitle, #twRCol .sectionTitle a {\n   background-color:#0E278D ;\n   color:white;\n}\n#twLCol .sectionTitle, #twLCol .sectionTitle a {\n   background-color:#45B4DA;\n   color:white;\n}","html":"        <div id=\"twRCol\">\n            <div id=\"sponsorsFeature_PH\" ></div>\n            <div id=\"highlightsFeature_PH\" ></div>\n            <div id=\"realtimeFeature_PH\" ></div>\n        </div>\n        <div id=\"twLCol\">        \n            <div id=\"editorialFeature_myPics_PH\"></div>\n            <div id=\"editorialFeature_myLols_PH\"></div>\n            <div id=\"picGalleryFeature_PH\" ></div>\n            <div id=\"googlenewsFeature_PH\" ></div>\n            <div id=\"feedFeature_PH\" ></div>\n            <div id=\"youtubeFeature_PH\" ></div>\n<div style=\"font-style: italic; font-weight: bold; font-family: Arial,sans-serif; font-size: 0.8em; line-height: 13pt; text-align: right;\" id=\"youtubeLink\">\n\t\t\t</div>\n<iframe src=\"http://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2FCapgemini&amp;width=300&amp;colorscheme=light&amp;show_faces=true&amp;border_color&amp;stream=false&amp;header=false&amp;height=258\" scrolling=\"no\" frameborder=\"0\" style=\"border:none; overflow:hidden; width:300px; height:258px;\" allowTransparency=\"true\"></iframe>\n            <div id=\"linksFeature_PH\" ></div>\n            <div id=\"users_PH\" ></div>\n        </div>        \n"},
			"features":{"antispamFeature": {"spammers": ["jobs_toronto", "hashjobs", "laitjob", "chicagotechjob", "atlantaitjob", "rss2bigdinaz", "tmj_atl_mgmt", "hashjobs", "echhashtags", "dallasitjob"], "disabled": false, "type": "AntispamFeature"}, "feedFeature": {"url": "http:\/\/debate-tv.uk.capgemini.com\/sites\/all\/themes\/capgemini\/rss.php", "disabled": false, "type": "FeedFeature", "title": "Videos"}, "googlenewsFeature": {"disabled": false, "query": "capgemini outsourcing consulting", "type": "GooglenewsFeature", "title": "In the news"}, "editorialFeature": {"disabled": true, "query": "from:tifroz", "type": "EditorialFeature", "modules": [{"filter": {"params": {}, "type": "PicturesPipe"}, "id": "myPics", "title": "My pictures"}, {"filter": {"params": {"tag": ":)"}, "type": "LinksPipe"}, "id": "myLols", "title": "My lols"}]}, "logoFeature": {"url": "", "disabled": false, "type": "LogoFeature"}, "sponsorsFeature": {"ignoreQuery": true, "users": ["capgeminina", "capgeminibe", "capgeminiukppl", "capgeminidk", "capgeminiconsul", "capgemininl", "capgeminifrance", "capgeminijobs", "capgeminioracle", "sogetifr", "capgeminios", "capgemini", "capgeminiukpr"], "title": "Team Capgemini", "disabled": false, "query": "", "type": "SponsorsFeature"}, "toolbarFeature": {"disabled": true, "type": "ToolbarFeature", "queries": []}, "youtubeFeature": {"disabled": false, "type": "YoutubeFeature", "channel": "capgeminimedia", "title": "Capgemini on YouTube"}, "pageFeature": {"titles": {"picGallery": "Pictures", "highlights": "", "links": "Popular links", "realtime": "Real-time tweets for Capgemini"}, "type": "PageFeature", "features": {"picGallery": true, "links": true}}}
	};
	
	TWAZZUP.init(_WIDGETS,$('#searchBox').val());
	TWAZZUP.search($('#searchBox').val());
	if($("#flash").html()){
		$("#flash").slideDown(function(){
			setTimeout(function(){$("#flash").slideUp();},5000);
		});
	}
	$("input[type=text]").fieldtag();
});
