<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="Welcome Tunes" title_url="http://www.70mmvideos.com" author="Sharath" author_email="sharathkumar1984@gmail.com" author_affiliation="70mmvideos" directory_title="Welcome Tunes" description="Welcome friends to your profile with Welcome Tunes." screenshot="http://hosting.gmodules.com/ig/gadgets/file/110528217722967980113/welcome.jpg" thumbnail="http://hosting.gmodules.com/ig/gadgets/file/110528217722967980113/welcomet.jpg">
<Require feature="opensocial-0.7" /> 
<Require feature="views" /> 
<Require feature="dynamic-height" /> 
<Require feature="tabs" /> 
</ModulePrefs>
<Content type="html" view="canvas,profile">
<![CDATA[
<style type="text/css" >
*{
font-family: Verdana,"MS Trebuchet",Arial, sans-serif;
font-size: 13px;
}
h3{
font-family:Verdana,"Times New Roman",Arial,Helvetica;
font-size: 13px;
font-weight: bold;
font-variant:normal;
color:#355B85;
padding:0;
margin:0;
}
h3 a{
text-decoration:none;
color:#355B85;
}
h3 a:hover{
color:#474747;
}
h3 a:visited{
color:#355B85;
}
.tweet{
padding:2px;
margin-bottom:2px;
padding-top:2px;
padding-bottom:2px;
background-color:#fff;
background-color:#DADDE7;
float:left;
width:99%;
font-size:13px;
}
.tweet a{
color:#355B85;
font-size:13px;
text-decoration:none;
}
.tweet a:hover{
text-decoration:underline;
}
.tweet a:visited{
color:#355B85;
}
.user-img{
float:left;
margin-right:10px;
}
.user{
float:left;
margin-top:15px;
}
.user-img a img{
border:none;

}
#greet{
height:48px;
margin-bottom:5px;
background-color:#CCCCFF;
padding:2px;
}
#settings{
float:left;
margin-right:5px;
font-size:10px;
}
#settings a{
color:#355B85;
}
#links{
float:right;
margin-right:5px;
clear:both;
margin-top:2px;
margin-bottom:5px;
}
.since{
color:#949494;
font-style:italic;
float:right;
padding-right:5px;
}
.text{
float:left;
/*width:500px;*/
}
.since a, .since a:visited{
color:#4A4A4A;
font-size:11px;
/*text-decoration:underline;*/
}
.since a:hover{
color:#4A4A4A;
}
#next_link{
float:right;
margin-right:5px;
display:inline;
}
#back_link{
float:left;
display:inline;
}
#loading{
//margin:0 auto;
margin-left:45%;
//width:50%;
margin-top:50px;
}
#error{
font-weight:bold;
//padding:5px;
//padding-left:20px;
background:#FFF url('http://www.70mmvideos.com/twitter/error.png') no-repeat center left;
color:#00000;
}
#error p{
padding-left:20px;
}
#tooltip{
position:absolute;
margin:5px;
background-color:#eee;
font-size:10px;
color:#000;
}
.button{
padding:2px;
font-size:11px;
// background-color:#DADDE7;
color:#355B85;
text-decoration:underline;
font-family:Verdana,Arial,Helvetica,sans-serif;
}
.button:hover{
// background-color:#DEEFFF;
text-decoration:underline;
}
#links2{
float:left;
width:100%;
margin-top:10px;
margin-bottom:10px;
}
.smalltext{
font-size:10px;
float:left;
clear:both;
}
/*for orkut styled tabs */
.tablib_extension_left_selected, .tablib_extension_left_unselected {
height: 23px;
width: 6px;
float: left;
}
.tablib_extension_left_selected {
background-image: url(http://opensocial-resources.googlecode.com/svn/samples/orkut_ui/img/tabsel_l.gif);
}
.tablib_extension_left_unselected {
background-image: url(http://opensocial-resources.googlecode.com/svn/samples/orkut_ui/img/tabnotsel_l.gif);
}
.tablib_selected, .tablib_unselected {
font-size: 12px;
font-height: 23px;
text-transform: lowercase;
height: 23px;
line-height: 23px;
font-family: Verdana,Arial,sans-serif;
font-weight: 700;
margin: 0px;
padding: 0px;
padding-right: 6px;
width: auto;
border: 0px;
border-bottom: 1px solid #86A1C4;
}
.tablib_selected {
background: url(http://opensocial-resources.googlecode.com/svn/samples/orkut_ui/img/tabsel_r.gif) no-repeat center right;
color: #FFFFFF;
}
.tablib_unselected {
background: url(http://opensocial-resources.googlecode.com/svn/samples/orkut_ui/img/tabnotsel_r.gif) no-repeat center right;
color: #02679C;
}
td.tablib_unselected:hover {
color: #00344F;
text-decoration: underline;
}
.tablib_spacerTab, .tablib_emptyTab {
border-bottom: 1px solid #86A1C4;
}
.tablib_emptyTab {
width: 500px;
}

</style>
<div id="tabs_div">
<div id="your_tweets">
<div id="greet"></div>
<div id="tweets">
<div id="loading"></div>
</div>
</div>
<div id="friends_tweets">
<div id="friends_list">
</div>
</div>
</div>
<script>
gadgets.window.adjustHeight(400);
gadgets.util.registerOnLoadHandler(init);
var x = null;
var tabs = null;
var twitter_id = null;
var twitkut_friends=[];
var friend_no = 0;
//var timeline = "http://twitter.com/statuses/user_timeline/"+twitter_id+".json";
var tweets_data=1;
var viewer=0;
var owner=0;
var friends=[];
var last_tweet_time;
var hide_replies = "false";
//var no_non_replies = 0;
var last_tweet = [];
function refresh()
{
window.location.reload( true );
}
function makeSettings()
{
clearDiv("tweets");
createDiv("tweets","error");
if(isOwner())
{
var html = new Array();
html.push('<form id="settings" action="javascript:validateTwitterId();" >');
html.push('<p>Select and Save Your Welcome Tune : <select id="username3"><option value="indexf" selected="true">Female Welcome Tune</option><option value="index">Male Welcome Tune</option><option value="indexh">Hello Welcome Tune</option><option value="indexhw">How You Doing Welcome Tune</option></select>');
html.push('<br/><p><a href="javascript:getTweets();">Back</a>');
html.push('&nbsp;&nbsp;<a href="javascript:validateTwitterId();refresh();">Save settings</a></p>');
html.push('</form>');
appendDiv("tweets",html.join(''));
//fillDiv("greet","<div class='user'><h3>Change Tune</h3></div>");
}
else
{
getTweets1();
//raiseError("Twitter Updates is not configured properly!");
}

}
function getTweets1()
{
var iframeURL1 = "http://www.70mmvideos.com/welcome/tunes.php?tag=indexf";
_gel("tweets").innerHTML = "<iframe frameborder='0' width='550' height='150' src='"+ iframeURL1 + "'>";
}
function raiseError(error_text)
{
fillDiv("error","<p>"+error_text+"</p>");
makeSettings()
}
function validateTwitterId()
{
if(document.getElementById("username3").value)
{
storeTwitterId();
getTweets();
}
else
{
raiseError("Enter a Sign");
}
}
function resetTextField(field){
document.getElementById(field).value="";
}

function navigateTo(dest) {
var supported_views = gadgets.views.getSupportedViews();
gadgets.views.requestNavigateTo(supported_views[dest]);
}

function gotoCanvas(whereto) {
if(whereto==0)
{
navigateTo("canvas");
}
else if(whereto==1)
{
makeSettings();
}
}
 function getViewName() {
return gadgets.views.getCurrentView().getName();
}

function fillDiv(divname,htmlout)
{
document.getElementById(divname).innerHTML = htmlout;
}
function appendDiv(divname,htmlout)
{
document.getElementById(divname).innerHTML += htmlout;
}

function clearDiv(divname)
{
document.getElementById(divname).innerHTML = "";
}
function createDiv(parent_name,child_name)
{
newdiv = document.createElement('div');
newdiv.setAttribute('id',child_name);
document.getElementById(parent_name).appendChild(newdiv);
}
function removeDiv(parent_name,child_name)
{
var parent = getElementById(parent_name);
var child = getElementById(child_name);
parent.removeChild(child);
}
function generateLoadingImage()
{
fillDiv("loading","<img src='http://www.70mmvideos.com/twitter/ajax-loader.gif' />");
}
 function removeDivChildNodes(parent_name)
{
var parent = document.getElementById(parent_name);
if(parent.hasChildNodes())
{
while(parent.childNodes.length>=1)
{
parent.removeChild(parent.firstChild);
}
}
}
function isOwner()
{
if(owner.getId() == viewer.getId())
{
return 1;
}
else
{
return 0;
}
}
function makeCachedRequest(url, callback, params, refreshInterval) {
var ts = new Date().getTime();
var sep = "?";
if (refreshInterval && refreshInterval > 0) {
ts = Math.floor(ts / (refreshInterval * 1000));
}
if (url.indexOf("?") > -1) {
sep = "&";
}
url = [ url, sep, "nocache=", ts ].join("");
gadgets.io.makeRequest(url, callback, params);
}

//To store user twitter id persistently

function storeSettings()
{
var req = opensocial.newDataRequest();
var twit_id = twitter_id;
if(owner.getId() == viewer.getId())
{
req.add(req.newUpdatePersonAppDataRequest(opensocial.DataRequest.PersonId.VIEWER,"twitterid3",twit_id));
req.add(req.newUpdatePersonAppDataRequest(opensocial.DataRequest.PersonId.VIEWER,"hidereplies3",hide_replies));
req.send(onStoreSettings);
}
}
 function storeActivityInSettings()
{
var req = opensocial.newDataRequest();
var last_tweet = tweets_data[0].created_at;
if(owner.getId() == viewer.getId())
{
req.add(req.newUpdatePersonAppDataRequest(opensocial.DataRequest.PersonId.VIEWER,"last_tweet_time",last_tweet));
req.send(onStoreSettings);
}
}
function onStoreSettings(data)
{
}
//To retrieve user's twitter id


function loadSettings()
{
var req = opensocial.newDataRequest();
//req.add(req.newFetchPersonAppDataRequest(idspec,"twitterid3"),"userdata");
req.add(req.newFetchPersonAppDataRequest(opensocial.DataRequest.PersonId.OWNER,"twitterid3"),"userdata");
req.add(req.newFetchPersonAppDataRequest(opensocial.DataRequest.PersonId.OWNER,"last_tweet_time"),"lastupdate");
req.add(req.newFetchPersonAppDataRequest(opensocial.DataRequest.PersonId.OWNER,"hidereplies3"),"hidereplies3");
req.send(onLoadSettings);
}

function onLoadSettings(data)
{
clearDiv("tweets");
if(owner)
{
var userdata = data.get('userdata').getData();
var lastupdate = data.get('lastupdate').getData();
var replies_option = data.get('hidereplies3').getData();
var twitid = null;

if(userdata[owner.getId()])
{
var twitid = userdata[owner.getId()]['twitterid3'];
try
{
if(lastupdate)
{
last_tweet_time = lastupdate[owner.getId()]['last_tweet_time'];
}
if(replies_option)
{
hide_replies = replies_option[owner.getId()]['hidereplies3'];
}
}
catch(e)
{
}
}

if(twitid)
{
twitter_id = twitid;
x=twitter_id;
getTweets();
}
else
{
//if(getViewName=="canvas")
//{
x="indexf";
getTweets();
//makeSettings();
// fillDiv("tweets", "<h4>Horoscope not configured yet!</h4>");
// }
}
}
else
{
makeSettings();
}

} 
 function storeTwitterId()
{
twitter_id = document.getElementById("username3").value;
//timeline = "http://twitter.com/statuses/user_timeline/"+twitter_id+".json";
storeSettings();

}

function prefetchData()
{

var req = opensocial.newDataRequest();
req.add(req.newFetchPersonRequest("OWNER"),"owner");
req.add(req.newFetchPersonRequest("VIEWER"),"viewer");
req.send(onPrefetchData);
}

function onPrefetchData(data)
{
owner = data.get('owner').getData();
viewer = data.get('viewer').getData();
}

function init()
{
generateLoadingImage();
prefetchData();
if(getViewName() == "canvas")
{
// if(isOwner())
// {
//loadFriends();
createTabs();
// }
}
loadSettings();
}
function createTabs()
{
tabs = new gadgets.TabSet(__MODULE_ID__, null, document.getElementById('tabs_div'));
var params = {
callback: changeSelectedTab
};
params.contentContainer = document.getElementById('your_tweets');
tabs.addTab('Your Welcome Tune', params);
//params.contentContainer = document.getElementById('friends_tweets');
//tabs.addTab('Friends Tweets', params);
tabs.alignTabs('left', 2);
var tabHeaders = document.getElementById('tabs_div_header').rows[0].cells;
var value = null;
var html = null;
for (var i in tabHeaders) {
if (tabHeaders[i].className && tabHeaders[i].className.match(/tablib_selected/)) {
value = tabHeaders[i].innerHTML;
html = "<span class='tablib_extension_left_selected'></span> " + value;
tabHeaders[i].innerHTML = html;
}
if (tabHeaders[i].className && tabHeaders[i].className.match(/tablib_unselected/)) {
value = tabHeaders[i].innerHTML;
html = "<span class='tablib_extension_left_unselected'></span> " + value;
tabHeaders[i].innerHTML = html;
}
}
}
 function changeSelectedTab() {
if (document.getElementById('tabs_div_header')) {
var tabHeaders = document.getElementById('tabs_div_header').rows[0].cells;
for (var i in tabHeaders) {
if (tabHeaders[i].className && tabHeaders[i].className.match(/tablib_selected/)) {
if (tabHeaders[i].childNodes[0].className) {
tabHeaders[i].childNodes[0].className = 'tablib_extension_left_selected';
}
}
if (tabHeaders[i].className !== undefined && tabHeaders[i].className.match(/tablib_unselected/)) {
if (tabHeaders[i].childNodes[0].className) {
tabHeaders[i].childNodes[0].className = 'tablib_extension_left_unselected';
}
}
}
}
}
function getTweets()
{
//_IG_RegisterOnloadHandler(function() {
//var x = prefs.getString("keywords");
var iframeURL = "http://www.70mmvideos.com/welcome/tunes.php?tag="+x;
_gel("tweets").innerHTML = "<iframe frameborder='0' width='550' height='275' src='"+ iframeURL + "'>";
//});
if(isOwner())
{
htmlout = "<br/><br/><div id='links2'><a class='button' style='font-size:12px' href='javascript:makeSettings();' title='Change Settings' />Change Tune</a></div>";
//htmlout += "<br/><br/><p class='smalltext'>* Activity Stream will only be updated when you visit your profile or application page.</p>"
}
appendDiv("tweets",htmlout);
}
</script>
]]> 
</Content>
</Module>
