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':14266598,'screen_name':"350",'lookup':"350",'name':"350 dot org",'profile_image_url':"http://a0.twimg.com/profile_images/1681069579/durban-350-sized_normal.jpg"},
			"key":"agd0d2F6enVwchsLEgRQYWdlIhFwYWdlOjE0MjY2NTk4OjM1MAw",
			"lookup":"350",
			"basequery":"#350 OR 350.org OR from:350 OR cop15 OR #climateaction",
			"useroverlayQuery":"#350 OR 350.org OR from:350 OR cop15 OR #climateaction",
			"title":"350.org",
			"desc":"24 October 2009, International Day of Climate Action. Join a global movement to solve the climate crisis",
			"skin":{"css":"body {\u000a    background : #8dc3e4 url(\"http://a1.twimg.com/profile_background_images/28595630/350-twitter-bg.png\") no-repeat fixed left top;\u000a    color:#333333\u000a}\u000aa {\u000a    color:#2c77c7;\u000a}\u000a#twRCol .sectionTitle, #twRCol .sectionTitle a {\u000a    background-color:#f7921c;\u000a    color:#ffffff;\u000a}\u000a#twLCol .sectionTitle, #twLCol .sectionTitle a {\u000a    background-color:#1882be;\u000a    color:#ffffff;\u000a}    \u000adiv#slide_pane_wrapper {\u000abackground-color:#1482be;\u000abackground-image:none;\u000aborder-left:2px solid #1576ab;\u000a}\u000a    ","html":"        <div id=\"twRCol\">\u000a            <div id=\"sponsorsFeature_PH\" ></div>\u000a            <div id=\"highlightsFeature_PH\" ></div>\u000a            <div id=\"realtimeFeature_PH\" ></div>\u000a        </div>\u000a        <div id=\"twLCol\">        \u000a            <div id=\"editorialFeature_myPics_PH\"></div>\u000a            <div id=\"editorialFeature_myLols_PH\"></div>\u000a            <div id=\"picGalleryFeature_PH\" ></div>\u000a            <div id=\"feedFeature_PH\" ></div>\u000a            <div id=\"googlenewsFeature_PH\" ></div>\u000a            <div id=\"youtubeFeature_PH\" ></div>\u000a            <div id=\"linksFeature_PH\" ></div>\u000a            <div id=\"users_PH\"></div>\u000a        </div>        \u000a"},
			"features":{"antispamFeature": {"spammers": [], "type": "AntispamFeature"}, "feedFeature": {"disabled": false, "url": "http:\/\/feeds2.feedburner.com\/350org", "type": "FeedFeature", "title": "350 Blog"}, "editorialFeature": {"disabled": true, "query": "from:mocy", "type": "EditorialFeature", "modules": [{"filter": {"type": "PicturesPipe", "params": {}}, "id": "myPics", "title": "My pictures"}, {"filter": {"type": "LinksPipe", "params": {"tag": ":)"}}, "id": "myLols", "title": "My lols"}]}, "googlenewsFeature": {"disabled": false, "lang": "", "title": "In the news", "type": "GooglenewsFeature", "query": "350.org"}, "logoFeature": {"url": "", "disabled": false, "type": "LogoFeature"}, "pageFeature": {"titles": {"picGallery": "", "highlights": "", "links": "", "realtime": "Real-time tweets about 350"}, "type": "PageFeature", "features": {"picGallery": true, "links": true}}, "toolbarFeature": {"disabled": true, "type": "ToolbarFeature", "queries": [{"q": "Climate Change", "label": "Climate Change"}, {"q": "Copenhagen", "label": "Copenhagen"}, {"q": "October 24", "label": "October 24"}, {"q": "Bill Mckibben", "label": "Mckibben"}]}, "youtubeFeature": {"disabled": false, "type": "YoutubeFeature", "channel": "350org", "title": "Videos"}, "sponsorsFeature": {"ignoreQuery": false, "users": ["350", "billmckibben", "extremeice", "350speaks", "tokyo350", "350nz", "350vt", "350dance", "350river", "350australia", "avl350", "350Dominicana", "rancagua350", "southbay350", "rockingham350", "fillthehill", "350vermont", "350nowpilipinas"], "title": "350.org", "disabled": false, "query": "", "type": "SponsorsFeature"}}
	};
	
	TWAZZUP.init(_WIDGETS,$('#searchBox').val());
	TWAZZUP.search($('#searchBox').val());
	if($("#flash").html()){
		$("#flash").slideDown(function(){
			setTimeout(function(){$("#flash").slideUp();},5000);
		});
	}
	$("input[type=text]").fieldtag();
});
