// JavaScript Document
function addFavAuth(b,a){new Ajax.Request("/add_to_fav_auth.php",{method:"post",postBody:"auth_id="+b+"&quote_id="+a,onComplete:function(c){showAuthor(c)}})}
function showAlert(){
jQuery(document).ready( function(){
var msg = 'Copied to your clipboard';
jQuery("#modalbody").text(msg);
var animStyle = 'slide';
jQuery('#msg1').notificationmsg({animation:animStyle});
jQuery('#msg1').notificationmsg('show');
});
}
function openBookmarkLogin(a){window.location.href='/loginTwitter.php?bookmarkid='+a;}
var bookmarkVal = 1; 
function changeme(chgval){ 
if(chgval == 1){ 
bookmarkVal = 1; 
}else{ 
bookmarkVal = 0; 
}
} 
function postbookmark(b) {
	if(bookmarkVal == 1) {
		new Ajax.Request("/twitterBookmark.php",{method:"post",postBody:"quotation_id="+b})
	} 
}
function addFav(a){
	new Ajax.Request("/add_to_fav.php",{method:"post",postBody:"quotation_id="+a,onComplete:function(b){
	
	document.getElementById("bookmarklink"+ a ).style.color = '#777777';
	document.getElementById("bookmarklink"+ a ).style.cursor="default";
	var msg = 'Bookmarked successfully';
	jQuery("#bookmarkmodalbody").text(msg);
	var animStyle = 'slide';
	jQuery('#bookmarkmsg1').notificationmsg({animation:animStyle});
	jQuery('#bookmarkmsg1').notificationmsg('show');window.setTimeout("postbookmark(" + a + ")", 7000);
	showQuote(b)}})}



function showAuthor(a){if(a.responseText!=""){showdiv(a.responseText);changeIt("plus.png","imageauth"+a.responseText)}else{hidediv(a.responseText)}}

function showQuote(a){if(a.responseText!=""){
	
	showdiv(a.responseText);changeIt("plus.png","imagequote"+a.responseText)}else{hidediv(a.responseText)}}

function hidediv(a){if(document.getElementById){document.getElementById("hideshow"+a).style.visibility="hidden"}else{if(document.layers){document.hideshow.visibility="hidden"}else{document.all.hideshow.style.visibility="hidden"}}}
function showdiv(a){if(document.getElementById){document.getElementById("hideshow"+a).style.visibility="visible";setTimeout("hidediv("+a+")",1000)}else{if(document.layers){document.hideshow.visibility="visible";setTimeout("hidediv("+a+")",1000)}else{document.all.hideshow.style.visibility="visible";setTimeout("hidediv("+a+")",1000)}}}

function changeIt(a,c){var d=document.getElementById(c);var b="<img src='/images_web/"+a+"' border='0' />";d.innerHTML=b;return}

function copy_to_clipboard(a){if(window.clipboardData){window.clipboardData.setData("text",a)}else{var b=document.getElementById("divclipboardswf");if(b==null){b=document.createElement("div");b.setAttribute("name","divclipboardswf");b.setAttribute("id","divclipboardswf");document.body.appendChild(b)}b.innerHTML='<embed src="clipboard.swf" FlashVars="clipboard='+encodeURIComponent(a)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>'}alert("The text is copied to your clipboard...");return false}function update_quotes(){$("progress").show();$("error").hide();new Ajax.Updater("quotes","post_quote.php",{method:"post",parameters:$("postquote").serialize(),insertion:Insertion.Top,onSuccess:function(){$("quote").value="";$("first_name").value="";$("last_name").value="";$("progress").hide()}})}function openShareWindow(a){jQuery(document).ready(function(){url="/sendtofriend.php?height=710&width=1000&filename="+a+"&amp;keepThis=true&amp;TB_iframe=true&modal=true";tb_show("",url,"")})}function eMailCard(a,b){jQuery(document).ready(function(){url="/eMailCard.php?height=710&width=1000&quote_id="+b+"&amp;keepThis=true&amp;TB_iframe=true&modal=true";tb_show("",url,"")})}function openEcardWindow(a,b,e,d,c){jQuery(document).ready(function(){url="/ecard_creator.php?height=605&width=900&searchType="+a+"&quote_id="+b+"&secure="+e+"&searchQuery="+d+"&authorSearched="+c+"&amp;keepThis=true&amp;TB_iframe=true&modal=true";tb_show("",url,"")})}function openEmailWindow(d,b,c,a){Modalbox.show("/email_quote.php",{title:"",width:550,params:{author:d,quote_id:b,return_url:c,filename:a}});return false}function openTagEmailWindow(d,b,c,a){Modalbox.show("/email_tag_video.php",{title:"",width:550,params:{video_title:d,video_link:b,return_url:c,filename:a}});return false}function openLoginWindow(){url="/login.php?height=200";tb_show("",url,"");return false}function openMenuWindow(e,c,d,b,a,f,g){Modalbox.show("/Menu2/ScrollWithoutEcard.php",{title:"",width:940,params:{author:e,author_id:c,icon:d,script:b,quote:a,tag:f}});return false}function openTwitterWindow(a){Modalbox.show("/twitter_login.php",{title:"",width:420,height:200,params:{quote_id:a}});return false}/*function openTwitterWindow(a){jQuery(document).ready(function(){url="/twitter_login.php?height=850&width=900&quote_id="+a+"&amp;keepThis=true&amp;TB_iframe=true&modal=true";tb_show("",url,"")})}*//*function openFbWindow(a){jQuery(document).ready(function(){url="/facebook_login.php?height=200&width=420&quote_id="+a+"&amp;keepThis=true&amp;TB_iframe=true&modal=true";tb_show("",url,"")})}*/function openUserTwitterWindow(a){Modalbox.show("/userquote_twit.php",{title:"",width:420,params:{id:a}});return false}/*function userReTweet(a){Modalbox.show("/userquote_twit.php",{title:"",width:420,params:{quote_id:a}});return false}*//*function openVideo(){Modalbox.show("/home_player.php",{title:"",width:590,height:407});return false}*/function openVideo(){jQuery(document).ready(function(){url="/home_player.php?height=650&width=600&amp;keepThis=true&amp;TB_iframe=true&modal=true";tb_show("",url,"")})}function errorReport(){jQuery(document).ready(function(){url="/errorReport.php?height=650&width=600&amp;keepThis=true&amp;TB_iframe=true&modal=true";tb_show("",url,"")})}function openWallpaperWindow(d,b,a,c,subject){Modalbox.show("/QBImageWithIcon/create_wallpaper.php",{title:"",width:1000,params:{author:d,icon:c,author_id:b,quote:a,tag:subject}});return false}function loaded(){var a=document.getElementsByName("thickbox");for(i=0;i<a.length;i++){a[i].style.visibility="visible"}};
function resize(width,height){
	Modalbox.resize(width, height)
}
function modal_close(){
	Modalbox.hide();
	return false;
}
var pauser=0;
var quotevalgot=1;
var countershown=0;
function RandomQuote(){
	if(quotevalgot==1 && countershown<20){
		quotevalgot=0;
		var rnds=new Date().getTime();
		jQuery.get("/randomquotehome.php",{ id:rnds, rndval:rnds}, function(data){
			var RESULT= data;
			quotevalgot=1;
			countershown++;
			jQuery("#Results ul").prepend( RESULT ).find('li:hidden').slideToggle('slow');
			jQuery("#resultItem_"+rnds).css("background-color","rgb(255,255,204)");
			jQuery("#resultItem_"+rnds).animate({backgroundColor:"white"},1500);
			jQuery("#Results ul li:gt(16)").remove(); // Removes everything past the 15th tweet
			jQuery(".desc_"+rnds).truncate({max_length: 230});
		});
	}
	var randomnumber=Math.floor(Math.random()*21)
	if(randomnumber<=10){
		randomnumber=randomnumber+10;		
	}
	randomnumber=randomnumber*1000;
	if(countershown==20){
		clearTimeout(timer);
		document.getElementById('expander').innerHTML='<img src="/images_web/playbtn.png" alt="Pause" border="0"/>';
		document.getElementById('expander').href="javascript:startIt()";
	}else{
		timer=setTimeout("RandomQuote()",randomnumber);
	}
}
var authorvalgot=1;
var counterauthor=0;
function RandomAuthors(){
	if(authorvalgot==1){
		authorvalgot=0;
		var rnds=new Date().getTime();
		jQuery.get("/randomauthorhomepage.php",{ id:rnds, rndval:rnds}, function(data){
			var RESULT= data;
			authorvalgot=1;
			counterauthor++;
			jQuery("#Results_author ul").prepend( RESULT ).find('li:hidden').slideToggle('slow');
			jQuery("#resultItem_"+rnds).css("background-color","rgb(255,255,204)");
			jQuery("#resultItem_"+rnds).animate({backgroundColor:"white"},1500);
			jQuery("#Results_author ul li:gt(4)").remove(); // Removes everything past the 15th tweet
			//jQuery('.expandtext').corners("");
			//jQuery(".desc_"+rnds).truncate({max_length: 230});
		});
	}
	var randomnumber=Math.floor(Math.random()*21)
	if(randomnumber<=10){
		randomnumber=randomnumber+10;		
	}
	randomnumber=randomnumber*1000;
	//timer=setTimeout("RandomQuote()",randomnumber);
	if(counterauthor==20){
		clearTimeout(timerauthor);
	}else{
		timerauthor=setTimeout("RandomAuthors()",randomnumber);
	}
}
flagstart=0;
twittFlag=1;
twitterArr = {};
FadeGeneric = {};
function getSearchGeneric(){
	var url = "http://search.twitter.com/search.json?q=%23quote&callback=?";
	if(twittFlag==1){
		twittFlag=0;
		jQuery.getJSON
		(
		url,
		function(response)
		{
			if( response.results )
			{
				var i = -1;
				var result;
				var html_output='';
				while( (result = response.results[++i]) && !twitterArr[result.id] )
				{
					twitterArr[result.id] = result.from_user;
					q = result.text.replace(/#\w+/g, '');
					q = q.replace(/(RT\s+|RT\s+:\s+|RT\:\s+|RT\s+:|RT:\RT)@(\w+\s+\:|\w+\:|\w+)/g, '');
					q = q.replace(/@(\w+\s+\:|\w+\:|\w+)/g, '');
					q = q.replace(/\:\s+/g, '');
					q = q.replace(/(http|https):\/\/.*?(\s+|$)/g, ''); 
					q =	q.replace(/\./g,'');
					q=jQuery.trim(q)
					html_output += '<li id="TwitterId'+ result.id +'"><a href="http://www.twitter.com/' + result.from_user + '" title="Go to profile" target="_blank"><img src="' + result['profile_image_url']+'" alt="Profile Image"  class="userImg"/></a> <a href="http://www.twitter.com/' + result.from_user + '" title="Go to profile" target="_blank"><strong class="username">'+ result.from_user + '</strong></a> <a href="http://www.iwise.com/quotes/'+q+'" title="iWise search" class="lnk">' + format_txt(result.text) + '</a> <br /><span class="feedInfo">' + get_time(result.created_at) + ' via ' + linkup(result.source) + '</span><br /></li>';
					idgot=result.id;

					//alert(idgot);
					if(flagstart!=0){
						break;
					}
					//
				}
				flagstart=1;
				//alert(html_output);
				twittFlag=1;
				if( html_output !== '' )
				jQuery("#tweetshome ul").prepend( html_output ).find('li:hidden').slideToggle('slow');
				if(!FadeGeneric[idgot]){
					jQuery("#TwitterId"+ idgot).css("background-color","rgb(255,255,204)");
					jQuery("#TwitterId"+ idgot).animate({backgroundColor:"white"},1000);
					FadeGeneric[idgot] = idgot;
				}
				jQuery("#tweetshome ul li:gt(5)").remove();
			}
		}
		)
	}
}
function format_txt(res)
{
	res = res.replace(/(gissisim)/ig, '<strong class="twitterfeeds">$1</strong>');
	return res.makeLink();
}
function linkup(link)
{
	link = link.replace('&lt;a href=&quot;','<a href="');
	link = link.replace('&quot;&gt;','">');
	link = link.replace('&lt;/a&gt;','</a>');
	return link;
}
String.prototype.makeLink = function() {
	return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/~.=]+/, function(m) {
		return m.link(m);
	});
};
function get_time(time_value) { 
	var valArr = time_value.split(" ");
	time_value = valArr[2] + " " + valArr[1] + ", " + valArr[3] + " " + valArr[4];
	var parsedDt = Date.parse(time_value);
	var relTo = (arguments.length > 1) ? arguments[1] : new Date();
	var secs = parseInt((relTo.getTime() - parsedDt) / 1000);
	secs = secs + (relTo.getTimezoneOffset() * 60);
	var r = '';
	if (secs < 60) {
		r = 'a minute ago';
	} else if(secs < 120) {
		r = 'couple of minutes ago';
	} else if(secs < (45*60)) {
		r = (parseInt(secs / 60)).toString() + ' minutes ago';
	} else if(secs < (90*60)) {
		r = 'an hour ago';
	} else if(secs < (24*60*60)) {
		r = '' + (parseInt(secs / 3600)).toString() + ' hours ago';
	} else if(secs < (48*60*60)) {
		r = '1 day ago';
	} else {

		r = (parseInt(secs / 86400)).toString() + ' days ago';
	}
	return r;
}
function twitter_callback ()
{
	return true;
}
jQuery(document).ready( function(){
	jQuery('.resulthomerighttweets').corners();
	jQuery('.resulthomecenter').corners();
	jQuery('.resulthomeright').corners();
	setInterval("getSearchGeneric()",10000);
	getSearchGeneric();
	//jQuery('.expandtext').corners("");
	image1 = new Image();
	image1.src = "images_web/favOff.png";
	image2 = new Image();
	image2.src = "images_web/retweetOFF.png";
	image3 = new Image();
	image2.src = "images_web/ReMailOn.png";
	image4 = new Image();
	image4.src = "images_web/add_fav.png";
	image5 = new Image();
	image5.src = "images_web/retweetRollover.png";
	image6 = new Image();
	image6.src = "images_web/email.png";
});
jQuery(
function()
{
	timer=setTimeout("RandomQuote()",5000);
	//setInterval("getSearchFeed()",20000);
	//RandomQuote();
	timerauthor=setTimeout("RandomAuthors()",5000);
	//setInterval("getSearchFeed()",20000);
	//RandomAuthors();
}
);
function pauseIt(){
	clearTimeout(timer);
	countershown=20;
	document.getElementById('expander').innerHTML='<img src="images_web/playbtn.png" alt="Pause" border="0"/>';
	document.getElementById('expander').href="javascript:startIt()";
}
function startIt(){
	timer=setTimeout("RandomQuote()",5000);
	countershown=0;
	document.getElementById('expander').innerHTML='<img src="images_web/pausebtn.png" alt="Pause" border="0"/>';
	document.getElementById('expander').href="javascript:pauseIt()";
}
function openiTunes(){
 //window.open("http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=310874426");
}
jQuery(function() {
	jQuery('.desc').truncate({max_length: 220});
});
function ShowImg(quote_id,imgsrc,imgsrc2,imgsrc3) {
	if ( imgsrc ) {
		document.getElementById('targetImg_'+quote_id).src = imgsrc;
	} else {
		document.getElementById('targetImg_'+quote_id).src = 'images_web/Blank.gif';
	}
	if ( imgsrc2 ) {
		document.getElementById('targetImg2_'+quote_id).src = imgsrc2;
	} else {
		document.getElementById('targetImg2_'+quote_id).src = 'images_web/Blank.gif';
	}
	if ( imgsrc3 ) {
		document.getElementById('targetImg3_'+quote_id).src = imgsrc3;
	} else {
		document.getElementById('targetImg3_'+quote_id).src = 'images_web/Blank.gif';
	}
}
var followVal = 1; 
function changefollowVal(fchgval){ 
if(fchgval == 1){ 
followVal = 1; 
}else{ 
followVal = 0; 
}
}
function postfollow(author_id) {
	if(followVal == 1) {
		new Ajax.Request("/twitterFollow.php",{method:"post",postBody:"author_id="+author_id,onComplete:function(res){}})
	} 
}
function followAuthor(author_id) {
	new Ajax.Request("/addFollower.php",{method:"post",postBody:"aid="+author_id,onComplete:function(res){
	var msg = 'Followed successfully';
	jQuery("#followmodalbody").text(msg);
	var animStyle = 'slide';
	jQuery('#followmsg1').notificationmsg({animation:animStyle});
	jQuery('#followmsg1').notificationmsg('show');changediv(author_id);window.setTimeout("postfollow(" + author_id + ")", 7000);
	}});
}
function changediv(author_id) {
	jQuery('#chg_'+author_id).html('<div><img src="/images_web/Following.png" alt="Following" title="Following"/></div>');
	//jQuery('.expandtext').corners("");
}
function imgChange1( img,author_id ) {
	document.getElementById('follow'+author_id).src = img;
}
function closePlayer(){
	jQuery('#floatdiv').hide();
}
function openFbWindow(a){
	new Ajax.Request("/facebook_canvas.php",{method:"post",postBody:"quote_id="+a,onComplete:function(b){
	
	document.getElementById("bookmarklink"+ a ).style.color = '#777777';
	document.getElementById("bookmarklink"+ a ).style.cursor="default";
	var msg = 'Posted to Facebook successfully';
	jQuery("#modalbody").text(msg);
	var animStyle = 'slide';
	jQuery('#msg1').notificationmsg({animation:animStyle});
	jQuery('#msg1').notificationmsg('show');
	showQuote(b)}})
}
function openFbTagMsgWindow(a){
	new Ajax.Request("/facebook_canvas.php",{method:"post",postBody:"tag_msg="+a,onComplete:function(b){

	var msg = 'Posted to Facebook successfully';
	jQuery("#modalbody").text(msg);
	var animStyle = 'slide';
	jQuery('#msg1').notificationmsg({animation:animStyle});
	jQuery('#msg1').notificationmsg('show');
	showQuote(b)}})
}
function reTweetMsg(tweetmsg) {

	var msg = 'Tweeted successfully';
	jQuery("#twittermodalbody").text(msg);
	var animStyle = 'slide';
	var img = '/images_web/retweet_2.gif';
	jQuery('#twittermsg1').notificationmsg({animation:animStyle});
	jQuery('#twittermsg1').notificationmsg('show');
	//imgChangeRetweet(img,quoteid); 
	document.getElementById('retweetimgs1').src = img;
	jQuery.ajax({
		type: "POST",
		url: "/reTweetMsg.php",data: "retweet_msg="+ tweetmsg,
		success: function(msg) {
		
			},
		error: function(xhr,msg,e){
			alert(msg);
		}
	});
	
}	
function userReTweet(quoteid) {
	
	var msg = 'Tweeted successfully';
	jQuery("#twittermodalbody").text(msg);
	var animStyle = 'slide';
	var img = '/images_web/retweet_2.gif';
	jQuery('#twittermsg1').notificationmsg({animation:animStyle});
	jQuery('#twittermsg1').notificationmsg('show');
	//imgChangeRetweet(img,quoteid); 
	document.getElementById('retweetimg'+quoteid).src = img;
	jQuery.ajax({
		type: "POST",
		url: "/reTweetQuote.php",data: "quote_id="+ quoteid,
		success: function(msg) {
			},
		error: function(xhr,msg,e){
			alert(msg);
		}
	});
	
}
function imgChangeRetweet( img,quote_id ) {

	if(document.getElementById('retweetimg'+quote_id).src!='http://www.iwise.com/images_web/retweet_2.gif'){
		document.getElementById('retweetimg'+quote_id).src = img;
	}
}
function userQuoteReTweet(quoteid) {
	
	var msg = 'Tweeted successfully';
	jQuery("#twittermodalbody").text(msg);
	var animStyle = 'slide';
	var img = '/images_web/retweet_2.gif';
	jQuery('#twittermsg1').notificationmsg({animation:animStyle});
	jQuery('#twittermsg1').notificationmsg('show');
	//imgChangeUserRetweet(img,quoteid);
	document.getElementById('userretweetimg'+quoteid).src = img;
	jQuery.ajax({
		type: "POST",
		url: "reTweetUserQuote.php",data: "quote_id="+ quoteid,
		success: function(msg) {
			 },
		error: function(xhr,msg,e){
			alert(msg);
		}
	});
	
}
function imgChangeUserRetweet( img,quote_id ) {
	if(document.getElementById('retweetimg'+quote_id).src!='http://www.iwise.com/images_web/retweet_2.gif'){
		document.getElementById('userretweetimg'+quote_id).src = img;
	}
}

function openFbWindow(a){

	new Ajax.Request("/facebook_canvas.php",{method:"post",postBody:"quote_id="+a,onComplete:function(b){
	
	document.getElementById("bookmarklink"+ a ).style.color = '#777777';
	document.getElementById("bookmarklink"+ a ).style.cursor="default";
	var msg = 'Posted to Facebook successfully';
	jQuery("#modalbody").text(msg);
	var animStyle = 'slide';
	jQuery('#msg1').notificationmsg({animation:animStyle});
	jQuery('#msg1').notificationmsg('show');
	showQuote(b)}})
}
function openFbTagMsgWindow(a){

	new Ajax.Request("/facebook_canvas.php",{method:"post",postBody:"tag_msg="+a,onComplete:function(b){

	var msg = 'Posted to Facebook successfully';
	jQuery("#modalbody").text(msg);
	var animStyle = 'slide';
	jQuery('#msg1').notificationmsg({animation:animStyle});
	jQuery('#msg1').notificationmsg('show');
	showQuote(b)}})
}

function reTweetMsg(tweetmsg) {

	var msg = 'Tweeted successfully';
	jQuery("#twittermodalbody").text(msg);
	var animStyle = 'slide';
	var img = '/images_web/retweet_2.gif';
	jQuery('#twittermsg1').notificationmsg({animation:animStyle});
	jQuery('#twittermsg1').notificationmsg('show');
	//imgChangeRetweet(img,quoteid); 
	document.getElementById('retweetimgs1').src = img;
	jQuery.ajax({
		type: "POST",
		url: "/reTweetMsg.php",data: "retweet_msg="+ tweetmsg,
		success: function(msg) {
		
			},
		error: function(xhr,msg,e){
			alert(msg);
		}
	});
	
}	
function userReTweet(quoteid) {
	
	var msg = 'Tweeted successfully';
	jQuery("#twittermodalbody").text(msg);
	var animStyle = 'slide';
	var img = '/images_web/retweet_2.gif';
	jQuery('#twittermsg1').notificationmsg({animation:animStyle});
	jQuery('#twittermsg1').notificationmsg('show');
	//imgChangeRetweet(img,quoteid); 
	document.getElementById('retweetimg'+quoteid).src = img;
	jQuery.ajax({
		type: "POST",
		url: "/reTweetQuote.php",data: "quote_id="+ quoteid,
		success: function(msg) {
			},
		error: function(xhr,msg,e){
			alert(msg);
		}
	});
	
}
function imgChangeRetweet( img,quote_id ) {

	if(document.getElementById('retweetimg'+quote_id).src!='http://www.iwise.com/images_web/retweet_2.gif'){
		document.getElementById('retweetimg'+quote_id).src = img;
	}
}
function userQuoteReTweet(quoteid) {
	
	var msg = 'Tweeted successfully';
	jQuery("#twittermodalbody").text(msg);
	var animStyle = 'slide';
	var img = '/images_web/retweet_2.gif';
	jQuery('#twittermsg1').notificationmsg({animation:animStyle});
	jQuery('#twittermsg1').notificationmsg('show');
	//imgChangeUserRetweet(img,quoteid);
	document.getElementById('userretweetimg'+quoteid).src = img;
	jQuery.ajax({
		type: "POST",
		url: "reTweetUserQuote.php",data: "quote_id="+ quoteid,
		success: function(msg) {
			 },
		error: function(xhr,msg,e){
			alert(msg);
		}
	});
	
}
function imgChangeUserRetweet( img,quote_id ) {
	if(document.getElementById('retweetimg'+quote_id).src!='http://www.iwise.com/images_web/retweet_2.gif'){
		document.getElementById('userretweetimg'+quote_id).src = img;
	}
}