/*
This is a callback for the fivestar widget that modifies the summary on star click.
*/
function fivestarResult(voteResult) {
	$('form#fivestar-form-node-'+voteResult.vote.id + ' div.description').html(voteResult.result.summary);
}


/* 
BEGIN WHAT WAS FORMERLY menu.js 
*/

/*
BEGIN WHAT WAS FORMERLY utils.js
*/

function switch_404_search(key){

	var yahoo_search = 'http://search.yahoo.com/search';
	var elm = document.getElementById('search_scope_' + key);
	var form = document.getElementById('404search');
	var search_field = document.getElementById('search_field');
	var submit = document.getElementById('submit_button');
	if(key == 'flock' && form.action == yahoo_search){
		//alert(key + ': ' + form.action);
		form.action = '/search/node';
		search_field.name = 'keys';
		submit.name = 'op';			
	}
	if(key == 'web' && form.action != yahoo_search){
		form.action = yahoo_search;
		search_field.name = 'p';
	}

}

document.getElementsByClassName = function(clsName){
	var retVal = new Array();
	var elements = document.getElementsByTagName("*");
	for(var i = 0;i < elements.length;i++){
		if(elements[i].className.indexOf(" ") >= 0){
			var classes = elements[i].className.split(" ");
			for(var j = 0;j < classes.length;j++){
				if(classes[j] == clsName)
					retVal.push(elements[i]);
			}
		}
		else if(elements[i].className == clsName)
			retVal.push(elements[i]);
	}
	return retVal;
}

function featured_focus(nid){
	var elms = document.getElementsByClassName('featured_container');
	for(i = 0; i < elms.length; i++){
		elms[i].style.display = 'none';
	}
	document.getElementById('featured_' + nid).style.display = 'block';
}

function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
	//document.getElementById(szDivID).style.display = iState ? "block" : "none";
	//return;
	if(document.layers)	   //NN4+
	{
	   document.layers[szDivID].display = iState ? "block" : "none";
	}
	else if(document.getElementById)	  //gecko(NN6) + IE 5+
	{
		var obj = document.getElementById(szDivID);
		obj.style.display = iState ? "block" : "none";
	}
	else if(document.all)	// IE 4
	{
		document.all[szDivID].style.display = iState ? "block" : "none";
	}
}

function gs_reset(){
	divs = document.getElementsByClassName('gs_item');
	for(i = 0; i < divs.length; i++){
		divs[i].style.display = 'none';
	}
	
	navs = document.getElementsByClassName('gs_current');
	for(i = 0; i < navs.length; i++){
		navs[i].className='';
	}
}

function gs_show(id){
	gs_reset();
	document.getElementById(id).style.display = 'block';
	document.getElementById('gsnav_' + id).className = 'gs_current';
	
}

/*
END WHAT WAS FORMERLY utils.js
*/

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function display_update_survey(div, percentage){
	if(document.referrer == ''){
		var show_survey = false;
		if(document.location.search.match(/test=/)){
			show_survey = true;	 
		}
		var cookie = readCookie('update_survey'); 
		//If visitor has cookie indicating s/he's already seen the survey, don't show the survey.
		if(!cookie || show_survey){
			//Show the survey to only a few people. 
			var rand = 1 + Math.floor(Math.random() * 100);
			if(rand <= percentage || show_survey == true){
				//Set a cookie after showing the message so we don't show it again for a while.
				createCookie('update_survey', 'displayed', 90);
				document.getElementById(div).style.display = 'block'; 
				//document.location.href='http://www.flock.com/survey/0.7.14';
			}
		}
	}
}

function mailto_link(user, domain){
	var glue = '@';
	document.location.href = 'mailto:' + user + glue + domain;
}

/* Value checks for input search fields */
function checkFocus(obj) {
  if (obj.value == obj.getAttribute("title")) {
    obj.value = "";
  }
}

function checkBlur(obj) {
  if (obj.value == "") {
    obj.value = obj.getAttribute("title");
  }
}

function ab(){
	var head = 'Get Flock – The Browser For The Modern Web';
	var sub = 'It\'s Fast, Convenient and Fun';

	var opts = {
		lp1:	{
				head:	'The Flock Browser - Keeps you connected with all the services you love',
				sub:	'Get ready to meet your new favorite browser!'
			},
		lp2:	{
				head:	'Flock - The browser loved by bloggers, shutterbugs and social animals alike',
				sub:	'Upgrade your web experience by downloading today!'
		},
		lp3:	{
				head:	'Try Flock, the browser built on Firefox, and connected to every service you love',
				sub:	'Download today, and get ready to meet your new favorite browser!'
		},
		lp4:	{
				head:	'Your parents browse... You Flock',
				sub:	'Download today, and get ready to meet your new favorite browser!'
			},
		lp5:	{
				head:	'Flock - The browser that puts you at the center of your web 2.0 action',
				sub:	'Get ready to meet your new favorite browser!'
			},
		lp6:	{
				head:	'Download Flock today, and you\'ll never go back to your conventional browser',
				sub:	'Get ready to meet your new favorite browser!'
			},
		lp7:	{
				head:	'This is not your parents\' browser...',
				sub:	'Experience the browser built for the way we use the web today!'
			},
		lp8:	{
				head:	'Your browser is so outdated...',
				sub:	'Download Flock, the browser built for the way we use the web today!'
			},
		lp9:	{
				head:	'Your parents use a conventional browser... you should be a Flock user',
				sub:	'Download today and meet your new favorite browser!'
			},
		lp10:	{
				head:	'Your parents use a conventional browser... you should be a Flock user',
				sub:	'Download today and get ready to meet your new favorite browser!'
			},
		lp11:	{
				head:	'Not down with the forced upgrade from IE6 to IE7?',
				sub:	'Stand up for YOUR choice -- upgrade to Flock!'
			},
		lp12:	{
				head:	'Flock - The browser designed for the needs of photographers',
				sub:	'Upload, Manage and Share all of your images directly from your browser'
			},
		lp13:	{
				head:	'Flock - Built on Firefox, and connected to your favorite services',
				sub:	'Get ready to meet your new favorite browser'
			},
		lp14:	{
				head:	'Flock - Built on Firefox, and connected to your favorite services',
				sub:	'Flock makes connecting and sharing with your friends as easy as drag-and-drop'
			},
		lp15:	{
				head:	'Flock - The browser built for the way you use the web today',
				sub:	'Flock makes connecting and sharing with your friends as easy as drag-and-drop'
			},
		lp16:	{
				head:	'Flock - The browser built for media consumers and shutterbugs',
				sub:	'Set up your favorite media services and RSS feeds, and Flock brings the web to you'
			},
		yahoo:	{
				head:	'Yahoo! Users Love Flock',
				sub:	'Get ready to meet your new favorite browser!'
			},
		sb_sf:	{ head: 'Upload, Share, Discover:', sub: 'Get Flock Now' },
		sb_hu:	{ head: 'Publish, Share, and Discover photos with Flock.', sub: 'Let us introduce the world\'s most innovative browser' },
		sb_uc:	{ head: 'Publish and share your images effortlessly.', sub: 'Get Flock Now' },
		sb_in:	{ head: 'You ditched the film camera... why are you using a dated browser?', sub: 'Get Flock now' },
		sb_cs:	{ head: 'Nothing gets your photos from your camera to your friends faster than Flock.', sub: 'Let us introduce the world\'s most innovative browser' },
		nh_sf:	{ head: 'Flock brings the latest news stories from your favorite sites to you.', sub: 'Let us introduce the world\'s most innovative browser' },
		nh_hu:	{ head: 'Flock brings your news to you.', sub: 'Like having a fleet of paper-boys.' },
		nh_uc:	{ head: 'Your news in your browser.', sub: 'Get Flock Now.' },
		nh_in:	{ head: 'Flock detects and collects your feeds so you can read your news - online or offline.', sub: 'Let us introduce the world\'s most innovative browser' },
		nh_cs:	{ head: 'Flock gathers the latest from your favorite news, blogs, and sites.', sub: 'Let us introduce the world\'s most innovative browser' },
		mj_sf:	{ head: 'Flock: the best browser to find photos and videos on the web.', sub: 'Let us introduce the world\'s most innovative browser' },
		mj_hu:	{ head: 'Find dogs in tutus even faster.', sub: 'Get Flock and discover the good stuff.' },
		mj_uc:	{ head: 'Find the good stuff before anyone else.', sub: 'Get Flock and have your media delivered.' },
		mj_in:	{ head: 'You\'ve ditched the landline, why are you using a dated browser?', sub: 'Let us introduce the world\'s most innovative browser' },
		mj_cs:	{ head: 'The fastest way to get to YouTube videos.', sub: 'Let us introduce the world\'s most innovative browser' },
		bl_sf:	{ head: 'Flock Makes Blogging Easy.', sub: 'Let us introduce the world\'s most innovative browser' },
		bl_hu:	{ head: 'Get Flock and Bring Your Own Blog.', sub: 'Let us introduce the world\'s most innovative browser' },
		bl_uc:	{ head: 'Don\'t know HTML?', sub: 'Flock has got you covered.' },
		bl_in:	{ head: 'Blog anything, anywhere, anytime.', sub: 'Get Flock, the browser for bloggers.' },
		bl_cs:	{ head: 'Flock - The Browser Made For Bloggers', sub: 'Let us introduce the world\'s most innovative browser' },
		sa_sf:	{ head: 'Flock brings your friends into the browser.', sub: 'Let us introduce the world\'s most innovative browser' },
		sa_hu:	{ head: 'The Flock Browser is better than a hot tub party.', sub: 'Let us introduce the world\'s most innovative browser' },
		sa_uc:	{ head: 'Get Flock and be at the center of your online universe.', sub: 'Let us introduce the world\'s most innovative browser' },
		sa_in:	{ head: 'You\'ve moved out of your parents\' house... why are you still using their browser?', sub: 'Let us introduce the world\'s most innovative browser' },
		sa_cs:	{ head: 'Flock lets you give your refresh button a break.', sub: 'Let us introduce the world\'s most innovative browser' }
	}

	//Generic A/B Testing
	if(document.location.search.match(/utm_campaign=.*_ab_q12008/) ||
		document.location.search.match(/utm_campaign=.*_pdSearch/)
	){
		var temp = document.location.search;
		//if(document.location.search.match(/utm_content=pl:notapplicable,pr:flock\.com,ct:lp([0-9]*)/)){
		if(document.location.search.match(/utm_content=.*ct:lp([0-9]*)/)){
			var num = temp.replace(/(.*)(ct:lp)(\d*)(.*)/, "$3");
			num = 'lp' + num;
			eval('var item = opts.' + num + ';');
			if(typeof item != 'undefined'){
				head = item.head;
				sub = item.sub;
			}
		}
	}
	//Yahoo tracking
	if(document.location.search.match(/utm_campaign=yahoo_persona/)){
		var temp = document.location.search;
		var key = temp.replace(/(.*)ct:([a-zA-Z]{2}_[a-zA-Z]{2})(.*)/, "$2");//.toLowerCase();
		key = key.toLowerCase();
		eval('var item = opts.' + key + ';');
		if(typeof item != 'undefined'){
			head = item.head;
			if(typeof item.sub != 'undefined'){
				sub = item.sub;
			}
		}
	}
	//Google tracking
	if(document.location.search.match(/utm_campaign=google_persona/)){
		var temp = document.location.search;
		var key = temp.replace(/(.*)ct:([a-zA-Z]{2}_[a-zA-Z]{2})_(.*)/, "$2");//.toLowerCase();
		key = key.toLowerCase();
		eval('var item = opts.' + key + ';');
		if(typeof item != 'undefined'){
			head = item.head;
			if(typeof item.sub != 'undefined'){
				sub = item.sub;
			}
		}
	}
	if(document.location.search.match(/utm_campaign=.*yahoo_downloads/)){
		head = opts.yahoo.head;
		sub = opts.yahoo.sub;
	}

	updateFlockHeaders(head, sub);
}
