function $(node){
	node = typeof node == "string" ? document.getElementById(node) : node;
	return node;
}
if(!String.prototype.trim){
	String.prototype.trim = function () {   
		return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');   
	};
}
if (typeof JSON === 'undefined') {
    window.JSON = {};	
}
JSON.update = function(a, b){
    for(var n in b){
	    if(b.hasOwnProperty(n)){
		    if(typeof b[n] !== 'object'){
			    a[n] = b[n];
			}else{
			    JSON.update(a[n], b[n]);
			}
		}
	}
	return a;
};
JSON.compact = function(json){
	for(var n in json){
		if(json.hasOwnProperty(n)){
			var value = json[n];
			if(value == null){
				delete json[n];
			}else if(value !== ''){
				var iValue = Number(value);
				if(!isNaN(iValue)){
					json[n] = iValue;
				}
			}
		}
	}
	return json;
}

//get a Random number 
function getRandom(lowerValue, upperValue){
	var choices = upperValue - lowerValue + 1;
	return Math.floor(Math.random() * choices + lowerValue);
}

var cookie = {
	get: function (name){
        var v = null;
        for(var cookies = document.cookie.split('; '), i = cookies.length; i--;){
            var item = cookies[i].split('=');
            var cookieName = item[0].toLowerCase();
            while (cookieName.charAt(0)==' ') cookieName = cookieName.substring(1,cookieName.length);
            if(cookieName === name.toLowerCase()){
                v = item[1];
                
                try{v = decodeURIComponent(v);}catch(e){}
                break;
            }
        }
        return v;
    },
	set: function (name, value, expires, path, domain, secure){
		var cookieText = name + '=' + value;
		if(typeof(expires) === 'number'){
		    expires = new Date(new Date().getTime() + expires*24*3600*1000);
		}
		if (expires instanceof Date) {
		    cookieText += '; expires=' + expires.toGMTString();
		}
		if (path) {
		    cookieText += '; path=' + path;
		}
		if(domain) {
		    cookieText += '; domain=' + domain;
		}else{
		    cookieText += '; domain=' + cookie.domain;
		}
		if (secure) {
		    cookieText += '; secure';
		}
		document.cookie = cookieText;
	},
	unset: function (name, path, domain, secure){
	    this.set(name, '', -1, path, domain, secure);
	}
};

if(typeof XMLHttpRequest === 'undefined'){
    XMLHttpRequest = function(){
		return new ActiveXObject(navigator.userAgent.indexOf('MSIE 5') > 0 ?'Microsoft.XMLHTTP':'Msxml2.XMLHTTP');
    };
}

function ajax( options ) {
    options = {
		formData: options.formData || false,
		method:options.method || "get",
        type: options.type || "text",
        url: options.url || "",
        timeout: options.timeout || 30000,
        onComplete: options.onComplete || function(){},
        onError: options.onError || function(r){
			//topAlert.call(defaultErrMsg);
			//auto_error_msg('TA:yes|Ajax Error|base.js|ajax()|'+options.url+'|'+serializeJson(options)+'|'+serializeJson(r));
			return false;},
        onSuccess: options.onSuccess || function(){},
		onTimeout:options.onTimeout || function(r){
		    //overlay.hide();
			//topAlert.call('Sorry, some error happened, please try again later!');
			//auto_error_msg('TA:yes|Ajax Timeout|base.js|ajax()|'+options.url+'|'+serializeJson(options)+'|'+serializeJson(r));
		},
        data: options.data || null
    };
    var xml = new XMLHttpRequest();
    xml.open(options.method, options.url, true);
    var requestDone = false;  
    setTimeout(function(){
         requestDone = true;
    }, options.timeout);
    xml.onreadystatechange = function(){
        if ( xml.readyState == 4) {  
		    if(!requestDone){
				if ( httpSuccess( xml ) ) {
					options.onSuccess( httpData( xml, options.type ) );
				} else {
					options.onError(xml);
				}
			}else{
			    options.onTimeout(xml);
			}
            options.onComplete();
            xml = null;
        }
    };
	if(typeof options.data !== 'string'){
	    options.formData = true;
		options.data = serializeJson(options.data);
		if(options.data.indexOf('?') === 0){
		    options.data = options.data.substring(1);
		}
	}
	if(options.formData) {
		xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		if(options.data !== null) {xml.setRequestHeader("Content-length", options.data.length);}
		xml.setRequestHeader("Connection", "close");
	}
    xml.send(options.data);
    function httpSuccess(r) {
        try {
            return !r.status && location.protocol == "file:" ||
                ( r.status >= 200 && r.status < 300 ) ||
                r.status == 304 ||
                navigator.userAgent.indexOf("Safari") >= 0 && typeof r.status == "undefined";
        } catch(e){}
        return false;
    }
    function httpData(r,type) {
        var ct = r.getResponseHeader("content-type");
        var data = !type && ct && ct.indexOf("xml") >= 0;
        data = type == "xml" || data ? r.responseXML : r.responseText;
        if ( type == "script" ) {
            eval.call( window, data );
	}else if(type !== 'xml'){
	    data = data.trim();
		if(data.indexOf('{') === 0){
		    data = data.substring(data.indexOf('{'), data.lastIndexOf('}') + 1);
		}
		try{
			if(typeof JSON !== 'undefined' && JSON.parse){
				return JSON.parse(data);
			}else {
				return evalJson(data);	
			}
		}catch(e){
		    return data;
		}
	}
    return data;
    }
}

function serializeJson(json){
    var s = [],
	    encode = encodeURIComponent;
	for(var n in json){
	    if(json.hasOwnProperty(n)){
		    s.push(encode(n) + '=' + encode(json[n]));
		}	
	}
	s = '?' + s.join('&');
	return s;
}
function serializeForm(form){
    var elms = form.elements,
	    l = elms.length,
		arr = [];
	while(l--){
	    var elm = elms[l],
		    v = elm.value.trim();
		if(elm.type !== 'submit' && v){
		    arr.push(elm.name + '=' + encodeURIComponent(v));
		}
	}
	return arr.join('&');
}

function stopBubble(e){
    if (e && e.stopPropagation)
        e.stopPropagation()
    else
        window.event.cancelBubble=true
}

//tocde is like 'T-ANALYZE-DIR', b is a boolean varlue to control the message parameter. 
//login("T-ANALYZE-DIR", true);
function login(tcode, b){
	var ad_url = window.location.host,
		sendT = b || true;
		tweet = st.tText.value,
		l = tweet.length,
		tweet_link = 'http://t.co/EizLDA9';
	
	if (st.tText.value.search(tweet_link) == -1) {
		alert("You can edit tweet text as you wish, so long as the link is not removed altogether. (If you'd prefer not to tweet at all, please select the option to purchase your follower analysis.)");
		st.tText.value += ' - ' + tweet_link;
		st.setSize();
		return false;
	}
	
	if( l > 139){
		alert('Max 140 characters, please revise...');
		return false;
	}
	
	if(tweet == st.getText(st.current)) {
		var tweet_text = tweets_data[st.current];
	} else {
		var tweet_text = st.getTweetCode(st.current)+'-R:'+ tweet;
	}
	
	//tweet_text = 'SS-099:Trying out http://t.co/EizLDA9 - breaks down your followers by location, gender, likes and interests, professions etc. #KnowYourFollowers';
	
	
	if(sendT){
		var log_url = 'http://' + ad_url + '/pyapp/twitter/get_auth_url?tcode=' + tcode + '&ad_url=' + ad_url + '&message=' + encodeURIComponent(tweet_text);
	} else {
		var log_url = 'http://' + ad_url + '/pyapp/twitter/get_auth_url?tcode=' + tcode + '&ad_url=' + ad_url;
	}
	window.location.href = log_url;
	
	var loginMsg = 'Connecting to Twitter...',
		doingLogin = false;
		
	if (!doingLogin) {
		doingLogin = true;
		
		var interval = setTimeout(function(){doingLogin = false;}, 30000);
	}
}

function learn_more(hash){
	var href = 'http://www.knowyourfollowers.com/info' + hash;
	var w = (screen.width-703)/2 + 145;
	var h = (screen.height-673)/2 - 70;
	mywindow = window.open(href,"newwindow","height=800,width=703,top="+ h +", left="+ w +", toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
	mywindow.focus();
	if(mywindow.location.href != 'about:blank'){
		mywindow.location.reload();	
	}
}

//edit funtion
var st = {
	current: 0,
	tNum: $('tweetNum'),
	tText: $('tweetContent'),
	setSize: function(){
		var l = st.tText.value.length;
		st.tNum.innerHTML = 139 - l;
		if (l < 139){
			st.tNum.style.color = "#CCCCCC";
		}else if (l == 139){
			st.tNum.style.color = "#D40D12";
		}else if (l > 139){
			st.tNum.style.color = "#FF0000";
		}
		
		if(l > 100){st.showSize();}
		if(l <= 100){st.hideSize();}
	},
	showSize: function(){
		st.tNum.style.display = 'block';
	},
	hideSize: function(){
		st.tNum.style.display = 'none';
	},
	checkSize: function(){
		setTimeout(st.setSize, 50);
	},
	getText: function(index){
		var start = tweets_data[index].indexOf(':') + 1;
		return tweets_data[index].slice(start);
	},
	getTweetCode: function(index){
		var start = tweets_data[index].indexOf(':');
		return tweets_data[index].slice(0,start);
	},
	setText: function(){
		st.tText.value = st.getText(0);
	},
	prev: function(){
		st.hideSize();
		if(st.current == 0){
			st.current = tweets_data.length;
		}
		st.tText.value = st.getText(st.current-1);
		st.current--;
	},
	next: function(){
		st.hideSize();
		if (st.current == tweets_data.length-1){
			st.current = -1;
		}
		st.tText.value = st.getText(st.current+1);
		st.current++; 
	}
	,checkTweet: function(){
		var l = st.tText.value.length,
			tweet_link = 'http://t.co/EizLDA9';
			
		if (st.tText.value.search(tweet_link) == -1) {
			alert("You can edit tweet text as you wish, so long as the link is not removed altogether. (If you'd prefer not to tweet at all, please select the option to purchase your follower analysis.)");
			st.tText.value += ' - ' + tweet_link;
			return true;
		}
		
		if( l > 139){
			alert('Max 140 characters, please revise...');
			return true;
		}
	}
};
st.setText();
st.tText.onchange = st.tText.onkeyup = st.tText.onpaste = function(e){st.checkSize(e);};
(function(){
	var oTm = $('tweet_message'),
		oSt = $('sendTweet'),
		oSs = $('sampleShow'),
		oVs = $('viewSample'),
		oUp = $('upT'),
		oDown = $('downT'),
		oWrap = $('wraper');

	oTm.onclick = edit_tweet;
	
	oUp.onclick = st.prev;
	oDown.onclick = st.next;
	
	function edit_tweet(r){
		ajax({url: '/pyapp/log_touch_point?c=show_tweet_us'});
		var s = tweets_data[0].indexOf(':') + 1,
			message = 'Currently, the tweet text is fixed as: "' + tweets_data[0].slice(s) + '" (The ability to edit this tweet will be available from 29th November.)';
		
		var l = st.tText.value.length,
			tweet_link = 'http://t.co/EizLDA9';
			
		if (st.tText.value.search(tweet_link) == -1) {
			alert("You can edit tweet text as you wish, so long as the link is not removed altogether. (If you'd prefer not to tweet at all, please select the option to purchase your follower analysis.)");
			st.tText.value += ' - ' + tweet_link;
			st.setSize();
			return false;
		}
		
		if( l > 139){
			alert('Max 140 characters, please revise...');
			return false;
		}
		
		if(oSs.style.display == 'block'){
			oVs.innerHTML = 'show me your pricing';
			oSs.style.display = 'none';
		}
		
		if(oSt.style.display=='block'){
			oTm.innerHTML = 'edit tweet';
			oSt.style.display = 'none';
		} else {
			oTm.innerHTML = 'hide tweet';
			oSt.style.display = 'block';
		}
	}

		
	
	oVs.onclick = function(){
		ajax({url: '/pyapp/log_touch_point?c=pricing_us'});
		
		if(oSt.style.display == 'block'){
			var s = tweets_data[0].indexOf(':') + 1,
			message = 'Currently, the tweet text is fixed as: "' + tweets_data[0].slice(s) + '" (The ability to edit this tweet will be available from 29th November.)';
			
			var l = st.tText.value.length,
				tweet_link = 'http://t.co/EizLDA9';
				
			if (st.tText.value.search(tweet_link) == -1) {
				alert("You can edit tweet text as you wish, so long as the link is not removed altogether. (If you'd prefer not to tweet at all, please select the option to purchase your follower analysis.)");
				st.tText.value += ' - ' + tweet_link;
				st.setSize();
				return false;
			}
			
			if( l > 139){
				alert('Max 140 characters, please revise...');
				return false;
			}
			
			oTm.innerHTML = "edit tweet";
			oSt.style.display == 'none';
		}	
		
		if(oSs.style.display == 'block'){
			oVs.innerHTML = "show me your pricing";
			oSs.style.display = 'none';
		} else {
			oSt.style.display = "none";
			oVs.innerHTML = "hide pricing";
			oSs.style.display = 'block';
		}
	}
	
	
	$('wrap_box').onclick = function(){
		if($('home_page').style.display != 'none'){
			$('tip-box').style.display = "block";

			if(!this.timer) {this.timer=null; }
			clearTimeout(this.timer);
			this.timer = setTimeout(function(){ $('tip-box').style.display = "none";},10000);
			ajax({url: '/pyapp/log_touch_point?c=img_left_us'});
		}
	}
	
	$('social-bar').onclick = oWrap.onclick = function(e){
		stopBubble(e);
	}
})();

//see pricing
sp = {};
sp.oDiv = $("sampleShow");
sp.oWrap = $("content");
sp.oUl = sp.oWrap.getElementsByTagName("ul")[0];
sp.oOl = sp.oDiv.getElementsByTagName("ol")[0];
sp.aLi = sp.oOl.getElementsByTagName("li");
sp.oPrev = sp.aLi[0].getElementsByTagName("a")[0];
sp.oNext = sp.aLi[1].getElementsByTagName("a")[0];
sp.iTimer = null;
sp.speed = 0;
sp.iTarget = 0;

sp.stopMove = function(){
	clearInterval(sp.iTimer);
    sp.iTimer = null;
};

sp.doMove = function(){
	if( Math.abs(sp.oUl.offsetTop - sp.iTarget) < Math.abs(sp.speed) ){
        clearInterval(sp.iTimer);
        sp.iTimer=null;
    } else {
        sp.oUl.style.top = sp.oUl.offsetTop + sp.speed + "px";
	
		if(sp.oUl.style.top == '-60px' || sp.oUl.style.top == '-120px'){
			sp.stopMove();
		}
	}
};

sp.goTimer = function(){
	if(this.parentNode.className==="up"){
        sp.speed = -5;
        sp.iTarget = -(sp.oUl.offsetHeight - sp.oWrap.offsetHeight);
    } else {
        sp.speed = 5;
        sp.iTarget = 0;
    }

    if(sp.iTimer){
        clearInterval(sp.iTimer);
        sp.iTimer = null;
    }
    sp.iTimer = setInterval("sp.doMove()", 35);
};

sp.oPrev.onclick = sp.goTimer;
sp.oNext.onclick = sp.goTimer;

//change main-title every 3 seconds
;(function(){
	var mt = $('main_title'),
		main_title = [
			'Where are they located?',
			'Mostly men or women?',
			'How many are married?',
			'How many have children?',
			'What jobs do they have?',
			'What likes & interests?',
			'Who else do they follow?'
		],
		l = main_title.length,
		i = 0;
	
	var title_timer = setInterval(function(){
		var j = i % l;
		mt.innerHTML = main_title[j];
		i++;
	},3000);
})();

var snapshot_data = [];
//create the tweets for welvome overlay and followers page
function createTweets(data, type, index){
	var link = 'http://t.co/EizLDA9',
		name = '#KnowYourFollowers',
		text_tmp = '',
		text_tmp1 = '',
		tweet_tmp = '';

	function getStat(index){
		var start = data[index].indexOf(':') + 1;
		return data[index].slice(start);
	};
	
	function getCode(index){
		var start = data[index].indexOf(':')+1;
		return data[index].slice(0,start);
	};
	
	if(type == 0){
		var prefix0 = ["My followers", "Seems you guys"],
			precode0 = ["A1-", "A2-"],
			rdm0 = getRandom(0,1);
			
		text_tmp = prefix0[rdm0] + getStat(index) + name + ' at: ' + link;
		text_tmp1 = prefix0[rdm0] + getStat(index) + link;
		
		if(text_tmp.length < 163){
			if(text_tmp.length > 139 ){
				tweet_tmp = precode0[rdm0] + getCode(index) + text_tmp1;
			} else {
				tweet_tmp = precode0[rdm0] + getCode(index) + text_tmp;
			}
			snapshot_data.push(tweet_tmp);
		}
	}
	if(type == 1){
		text_tmp = name + ' at: ' + link + ' - mine' + getStat(index);
		text_tmp1 = link + ' - mine' + getStat(index);
		
		if(text_tmp.length < 163){
			if(text_tmp.length > 139 ){
				tweet_tmp = 'B1-' + getCode(index) + text_tmp1;
			} else {
				tweet_tmp = 'B1-' + getCode(index) + text_tmp;
			}
			snapshot_data.push(tweet_tmp);
		}
	}
	if(type == 2){
		var prefix2 = ["According to ","Stats via "],
			prefix2_1 = [" you guys", " my followers"],
			precode2 = ["C1-","C2-"],
			rdm2 = getRandom(0,1),
			rdm2_1 = getRandom(0,1);
			
		text_tmp = prefix2[rdm2] + link + prefix2_1[rdm2_1] + getStat(index) + name;
		text_tmp1 = prefix2[rdm2] + link + prefix2_1[rdm2_1] + getStat(index);
		
		if(text_tmp.length < 163){
			if(text_tmp.length > 139 ){
				tweet_tmp = precode2[rdm2] + getCode(index) + text_tmp1;
			} else {
				tweet_tmp = precode2[rdm2] + getCode(index) + text_tmp;
			}
			snapshot_data.push(tweet_tmp);
		}
	}
}

//home page login
(function(){
	var hp = $('home_page'),
		hb = $('home_btn'),
		cb = $('cancel_btn'),
		gsp = $('get_s_pro'),
		gi = $('get_input'),
		gl = $('get_login'),
		gpb = $('get_profile_btn'),
		as = $('analyzing_spinner'),
		nt = $('no_tks'),
		lt = $('login_tip'),
		pt = $('purchaseTip'),
		errorMsg = $('errorMsg'),
		prourl = '/pyapp/profile_snapshot',
		alt_tip = "Enter your Twitter screen name",
		lTimer = null;
	
	//add for test
	var ls = $('load_spinner'),
		ob = $('ok_btn');
	
	function giBlur(){
		if(gi.value == ''){
			gi.value = alt_tip;
			gi.className = 'get-input default';
		}
		
	}
	giBlur();
	gi.onfocus = function(){
		if(gi.value == alt_tip){
			gi.value = '';
			gi.className = 'get-input';
		}
	}
	gi.onblur = giBlur;
	
	gpb.onclick = function(){
		ajax({url: '/pyapp/log_touch_point?c=getsnap'});
		var screenname = gi.value.replace('@', '').trim();
		if(gi.value == alt_tip){
			alert('Please first enter your Twitter screen name')
			return false;
		}
		gsp.style.display = 'none';
		as.style.display = 'block';
		errorMsg.style.display = 'none';
		errorMsg.innerHTML = '';
		
		ajax({
			url: prourl + '?s=' + screenname,
			onSuccess: function(resp){
				if(resp.code !== 0){
					as.style.display = 'none';
					gsp.style.display = 'block';
					errorMsg.innerHTML = resp.message;
					errorMsg.style.display = 'block';
				}else{
					schmapit.rSnapshots = resp.snapshots.split('|');
					
					for(var i=0,l=schmapit.rSnapshots.length; i<l; i++ ){
						var type_num = getRandom(0, 2);
						createTweets(schmapit.rSnapshots, type_num, i);
					}
					
					schmapit.rSnapshots = snapshot_data;
					
					as.style.display = 'none';
					gl.style.display = 'block';
					et.setText();
				}
			},
			onError: function(resp){
				if(resp.code !== 0){
					as.style.display = 'none';
					gsp.style.display = 'block';
					errorMsg.innerHTML = resp.message;
					errorMsg.style.display = 'block';
				}
			}
		})
	}
	
	nt.onclick = function(){
		ajax({url: '/pyapp/log_touch_point?c=nothanks'});
		gsp.style.display = 'none';
		hp.style.display = 'block';
	}
	
	function showLoginTip(){
		var ad_url = window.location.host,
			tweet = st.tText.value,
			l = tweet.length,
			tweet_link = 'http://t.co/EizLDA9';
		
		if (st.tText.value.search(tweet_link) == -1) {
			alert("You can edit tweet text as you wish, so long as the link is not removed altogether. (If you'd prefer not to tweet at all, please select the option to purchase your follower analysis.)");
			st.tText.value += ' - ' + tweet_link;
			st.setSize();
			return false;
		}
		
		if( l > 139){
			alert('Max 140 characters, please revise...');
			return false;
		}
		
		if(tweet == st.getText(st.current)) {
			var tweet_text = tweets_data[st.current];
		} else {
			var tweet_text = st.getTweetCode(st.current)+'-R:'+ tweet;
		}
		
		hp.style.display = "none";
		lt.style.display = "block";
		
		/*
		lTimer = setTimeout(function(){
			//login("T-ANALYZE-DIR");
		},6000);
		*/
	}
	
	
	hb.onclick = function(){
		ajax({url: '/pyapp/log_touch_point?c=button_click'});
		sp.oDiv.style.display = 'none';
		$('viewSample').innerHTML = "show me your pricing";
		showLoginTip();
	};
	
	cb.onclick = function(){
		clearTimeout(lTimer);
		ajax({url: '/pyapp/log_touch_point?c=cancel_click'});
		lt.style.display = "none";
		//hp.style.display = "block";
		gsp.style.display = "block";
		if(gi.value == alt_tip){
			gi.className = 'get-input default';
		}
	};
	
	ob.onclick = function(){
		ajax({url: '/pyapp/log_touch_point?c=ok_click'});
		lt.style.display = "none";
		ls.style.display = "block";
		lTimer = setTimeout(function(){
			login("T-ANALYZE-DIR");
		},1000);
	}
	
	$('twtGetAly').onclick = function(){
			var ad_url = window.location.host,
			tweet = et.tText.value,
			l = tweet.length,
			tweet_link = 'http://t.co/EizLDA9';
		
		if (et.tText.value.search(tweet_link) == -1) {
			alert("You can edit tweet text as you wish, so long as the link is not removed altogether. (If you'd prefer not to tweet at all, please select the option to purchase your follower analysis.)");
			et.tText.value += ' - ' + tweet_link;
			et.setSize();
			return false;
		}
		
		if( l > 139){
			alert('Max 140 characters, please revise...');
			return false;
		}
		
		if(tweet == et.getText(et.current)) {
			var tweet_text = schmapit.rSnapshots[et.current];
		} else {
			var tweet_text = et.getTweetCode(et.current)+'-R:'+ tweet;
		}
		
		var log_url = 'http://' + ad_url + '/pyapp/twitter/get_auth_url?tcode=T-ANALYZE-DIR2&ad_url=' + ad_url + '&message=' + encodeURIComponent(tweet_text);

		window.location.href = log_url;
		
		var loginMsg = 'Connecting to Twitter...',
			doingLogin = false;
			
		if (!doingLogin) {
			doingLogin = true;
			
			var interval = setTimeout(function(){doingLogin = false;}, 30000);
		}
	}
	$('twtGetAlyNoLog').onclick = function(){
		ajax({url: '/pyapp/log_touch_point?c=nologin'});
		alert("We'll be adding this option soon!");
	}
	$('purAlyNoTwt').onclick = function(){
		ajax({url: '/pyapp/log_touch_point?c=pricing_us'});
		gl.style.display = 'none';
		pt.style.display = 'block';
		sp.oDiv.style.display = 'block';
	}
	$('backLink').onclick = function(){
		pt.style.display = 'none';
		sp.oDiv.style.display = 'none';
		gl.style.display = 'block';
	}
})();

//edit tweet funtion
var et = {
	current: 0,
	tNum: $('twtNum'),
	tText: $('eTwtCt'),
	setSize: function(){
		var l = et.tText.value.length;
		et.tNum.innerHTML = 139 - l;
		if (l < 139){
			et.tNum.style.color = "#CCCCCC";
		}else if (l == 139){
			et.tNum.style.color = "#D40D12";
		}else if (l > 139){
			et.tNum.style.color = "#FF0000";
		}
		
		if(l > 100){et.showSize();}
		if(l <= 100){et.hideSize();}
	},
	showSize: function(){
		et.tNum.style.display = 'block';
	},
	hideSize: function(){
		et.tNum.style.display = 'none';
	},
	checkSize: function(){
		setTimeout(et.setSize, 50);
	},
	getText: function(index){
		var start = schmapit.rSnapshots[index].indexOf(':') + 1;
		return schmapit.rSnapshots[index].slice(start);
	},
	getTweetCode: function(index){
		var start = schmapit.rSnapshots[index].indexOf(':');
		return schmapit.rSnapshots[index].slice(0,start);
	},
	setText: function(){
		et.tText.value = et.getText(0);
	},
	prev: function(){
		et.hideSize();
		if(et.current == 0){
			et.current = schmapit.rSnapshots.length;
		}
		et.tText.value = et.getText(et.current-1);
		et.current--;
	},
	next: function(){
		et.hideSize();
		if (et.current == schmapit.rSnapshots.length-1){
			et.current = -1;
		}
		et.tText.value = et.getText(et.current+1);
		et.current++; 
	},
	checkTweet: function(){
		var l = et.tText.value.length,
			tweet_link = 'http://t.co/EizLDA9';
			
		if (et.tText.value.search(tweet_link) == -1) {
			alert("You can edit tweet text as you wish, so long as the link is not removed altogether. (If you'd prefer not to tweet at all, please select the option to purchase your follower analysis.)");
			et.tText.value += ' - ' + tweet_link;
			return true;
		}
		
		if( l > 139){
			alert('Max 140 characters, please revise...');
			return true;
		}
	}
};
et.tText.onchange = et.tText.onkeyup = et.tText.onpaste = function(e){et.checkSize(e);};
(function(){
	var oTm = $('tweet_message'),
		oUp = $('upET'),
		oDown = $('downET');

	//oTm.onclick = edit_tweet;
	
	oUp.onclick = et.prev;
	oDown.onclick = et.next;
	
	function edit_tweet(){
		ajax({url: '/pyapp/log_touch_point?c=show_tweet_us'});
		var s = schmapit.rSnapshots[0].indexOf(':') + 1,
			message = 'Currently, the tweet text is fixed as: "' + schmapit.rSnapshots[0].slice(s) + '" (The ability to edit this tweet will be available from 29th November.)';
		
		var l = st.tText.value.length,
			tweet_link = 'http://t.co/EizLDA9';
			
		if (st.tText.value.search(tweet_link) == -1) {
			alert("You can edit tweet text as you wish, so long as the link is not removed altogether. (If you'd prefer not to tweet at all, please select the option to purchase your follower analysis.)");
			st.tText.value += ' - ' + tweet_link;
			st.setSize();
			return false;
		}
		
		if( l > 139){
			alert('Max 140 characters, please revise...');
			return false;
		}
	}
})();


window.onload = function(){
	var screen_name = cookie.get('s_u_s');
	if (typeof(screen_name) == 'undefined' || screen_name==null) {
	    var tp_url = '/pyapp/log_touch_point?c=kyf_anom';
	    var pathname_kyf = document.location.pathname.replace('/know-your-followers/', '');
	    if(pathname_kyf === '1'){
	        tp_url = '/pyapp/log_touch_point?c=1kyf_anom';
	    }
	    
	    if (typeof(t_count) != 'undefined' && t_count!=null && t_count!='0') {
	        tp_url += '&t=' + t_count;
	    }
	    //alert ('url=' + tp_url);
	    ajax({url:tp_url});
	}
	
	!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
	;(function(d, s, id) {
		var js, fjs = d.getElementsByTagName(s)[0];
		if (d.getElementById(id)) {return;}
		js = d.createElement(s); js.id = id;
		js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=146089695482993";
		fjs.parentNode.insertBefore(js, fjs);
	}(document, 'script', 'facebook-jssdk'));

	;(function() {
		var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
		po.src = 'https://apis.google.com/js/plusone.js';
		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
	})();
	
}

