Community = new function(){}

Community.Page = new function(){
this.hostname = window.location.hostname;
this.path = window.location.pathname;
this.qs = window.location.search.substring(1);
this.vars = this.qs.split("&");
this.baseUrl = (this.hostname.indexOf(".mtvi.com") > 0) ? "http://www.cmt-d.mtvi.com" : "http://www.cmt.com";
//this.baseUrl = "http://www.cmt-d.mtvi.com";
this.headTag = document.getElementsByTagName("head").item(0);
this.cssOverrideSet = false;

this.init = function(){
Community.Widgets.createFooter('footer_container');
Community.Widgets.createArtistlist('searchbar');
Community.Widgets.createMenu('header_menu_container');
}

this.createScript = function(url){
var scriptObj = document.createElement("script");
scriptObj.setAttribute("type", "text/javascript");
scriptObj.setAttribute("src", Community.Page.baseUrl+url);
Community.Page.headTag.appendChild(scriptObj);
}

this.addCSSLink = function(url){
var cssUrl = Community.Page.baseUrl + url;
var linkObj = document.createElement("link");
linkObj.setAttribute("rel", "stylesheet");
linkObj.setAttribute("type", "text/css");
linkObj.setAttribute("href", cssUrl);
Community.Page.headTag.appendChild(linkObj);
}

this.updatePage = function(){	

// trim non-community greeting

if(!document.getElementById('ctl01_ctl00_ctl00_phBody_phBody_quickMenu_pnlCommunityMember')){
var q = document.getElementById('quickmenu');
var spans = q.getElementsByTagName('span');
var container;

for (var x=0; x<spans.length; x++){
if (spans[x].className.indexOf("userGreetingContainer") == 0) container = spans[x];
}

if(container){
for (var i=0; i<container.childNodes.length; i++){
var element = container.childNodes[i];
if(element.nodeName!='BR' && (!element.className || element.className.indexOf("userGreeting") < 0)) container.replaceChild(document.createTextNode(''), element);
}
}
}

// trim friend request text
var pnlDelimiter = document.getElementById('ctl01_ctl00_ctl00_phBody_phBody_quickMenu1_pnlDelimiter');
if(pnlDelimiter){
for (var i=0; i<pnlDelimiter.childNodes.length; i++){
var element = pnlDelimiter.childNodes[i];
if(element.nodeName=='#text'){
if(element.nodeValue.indexOf('||') >= 0){
pnlDelimiter.replaceChild(document.createTextNode(' | '), element);
}
else pnlDelimiter.removeChild(element);
}
}
}

// add User Search link to Friends page
if(Community.Page.path.indexOf('FriendsManagement.aspx') > 0 || Community.Page.path.indexOf('FriendsManagment.aspx') > 0){
var inviteLink = document.getElementById('ctl01_ctl00_ctl00_phBody_phBody_phBody_cFriendManagement_btnReorderFriends');

if(inviteLink){
var tbody = inviteLink.parentNode.parentNode.parentNode;
var newTR = document.createElement('tr');

var newTD = document.createElement('td');
newTD.setAttribute('align', 'right');

var newA = document.createElement('a');
newA.setAttribute('href', '/-/Community/BrowseUsers.aspx'); 
newA.appendChild(document.createTextNode('Browse Members'));

newTD.appendChild(newA);
newTR.appendChild(document.createElement('td'));
newTR.appendChild(newTD);
tbody.appendChild(newTR);
}
}// end user search

// add Upload links to Feed Detail pages
if(Community.Page.path.indexOf('/Content/Picture/Pictures.aspx') >0 || Community.Page.path.indexOf('/Content/Video/Videos.aspx') > 0){
var contentType;
if(Community.Page.path.indexOf('/Content/Picture/Pictures.aspx') >0) contentType = 'photo';
else if(Community.Page.path.indexOf('/Content/Video/Videos.aspx') >0) contentType = 'video';

var hook = document.getElementById('ctl01_ctl00_ctl00_phBody_phBody_phBody_contentFilterControl_lbPersonal');

if(hook){
var sidebar = hook.parentNode.parentNode.parentNode.parentNode;

var a = document.createElement('a');
var text;

switch(contentType){
case 'video': 
a.setAttribute('href', '/-/Content/Video/AddVideo.aspx');
text = 'Upload Videos';
break;
case 'photo': 
a.setAttribute('href', '/-/Content/Picture/AddPhoto.aspx');
text = 'Upload Photos';
break;
default: break;
}	
a.appendChild(document.createTextNode(text));

sidebar.appendChild(a);
}
}// end upload links

}// end this.updatePage

}

Community.Data = new function(){
this.discussionCategories = "";
this.fnVideoCategory = "";

this.setDiscussionCategories = function(obj){
Community.Data.discussionCategories = obj.categories.category;
Community.Page.setDiscussionCSS();
}
}

Community.Widgets = new function(){
this.hostname = 'http://www.cmt.com';

this.menuHTML = '<div id="menu_links"><a href="http://www.cmt.com/video/">Videos</a> + <a href="http://www.cmt.com/photos/">Photos</a> + <a href="http://www.cmt.com/music/radio/">Radio</a> + <a href="http://www.cmt.com/music/lyrics/">Lyrics</a></div><ul id="header_menu"><li><a href="http://www.cmt.com/" class="top">Home</a></li><li><a href="http://www.cmt.com/news/" class="top trigger">News</a><ul><li><a href="http://www.cmt.com/video/franchise/1369/cmt_insider.jhtml">CMT News Clips</a></li><li><a href="http://www.cmt.com/news/nashville_skyline/archive.jhtml">Nashville Skyline</a></li><li><a href="http://www.cmt.com/news/hot_dish/archive.jhtml">Hot Dish</a></li><li><a href="http://www.cmt.com/news/today_in_country_music/">Today in Country Music</a></li><li><a href="http://www.cmt.com/news/archive.jhtml">News Archives</a></li></ul></li><li><a href="http://www.cmt.com/music/" class="top trigger">Music</a><ul><li><a href="http://www.cmt.com/music/artists/">Artists</a></li><li><a href="http://www.cmt.com/video/music-videos/">Music Videos</a></li><li><a href="http://www.cmt.com/music/new-video-voting/">New Video Voting</a></li><li><a href="http://www.cmt.com/music/radio/">Radio CMT</a></li><li><a href="http://www.cmt.com/music/new-music/">New Music / The Leak</a></li><li><a href="http://www.cmt.com/music/lyrics/">Lyrics</a></li><li><a href="http://www.cmt.com/music/tours/">Tours</a></li><li><a href="http://www.cmt.com/music/studio_330_sessions/">Studio 330 Sessions</a></li><li><a href="http://blog.cmt.com/">Country Music Blog</a></li><li><a href="http://mp3.rhapsody.com?pcode=via&amp;cpath=cmt_web&amp;rsrc=cmt_downloadtextnav">Download on Rhapsody</a></li></ul></li><li><a href="http://www.cmt.com/shows/" class="top trigger">Shows</a><ul><li><a href="http://www.cmt.com/shows/schedule/">TV Schedule</a></li><li><a href="http://www.cmt.com/on_tv/cmt_pure_country/">CMT Pure Country</a></li><li><a href="http://www.cmt.com/shows/be_on_tv/">Be on TV</a></li><li><a href="http://www.cmt.com/video/show-videos/">CMT Show Videos</a></li><li><a href="http://www.palladia.tv" rel="nofollow">Palladia HD</a></li><li><a href="http://blog.cmt.com/category/shows/">Shows Blog</a></li></ul></li><li><a href="http://www.cmt.com/community/" class="top trigger">Community</a><ul><li><a href="http://community.cmt.com">Message Boards</a></li><li><a href="http://blog.cmt.com/">CMT Blog</a></li><li><a href="http://www.cmt.com/one_country/">CMT One Country</a></li><li><a href="http://www.cmt.com/community/newsletters/">Newsletters</a></li><li><a href="http://cmtauctions.com" rel="nofollow">Auctions</a></li><li><a href="http://www.cmt.com/community/sweepstakes/">Sweepstakes</a></li><li><a href="http://www.cmt.com/interact/help/">FAQ</a></li></ul></li><li><a href="http://www.cmt.com/mobile/" class="top trigger">Mobile</a><ul><li><a href="http://www.cmt.com/mobile/shows.jhtml">Mobile Shows</a></li><li><a href="http://www.cmt.com/mobile/wap.jhtml">CMT Mobile Web (WAP)</a></li><li><a href="http://www.cmt.com/mobile/carriers.jhtml">Mobile Providers</a></li><li><a href="http://www.cmt.com/mobile/faq/">Mobile FAQ</a></li></ul></li></ul>';
// creates a js variable called this.headerObj

this.artistBrowseHTML='<div id="header_search"><iframe id="searchbox" frameborder="0" style="border: 1px solid #ffffff; margin: 0pt; padding: 0pt; overflow: hidden; width: 425px; height: 28px;" src="http://www.cmt.com/sitewide/community/html/searchform.html">search cmt</iframe></div><div id="header_browse">Browse Artists<br/><a class="browselink" href="http://www.cmt.com/artists/browse/a.jhtml">A</a><a class="browselink" href="http://www.cmt.com/artists/browse/b.jhtml">B</a><a class="browselink" href="http://www.cmt.com/artists/browse/c.jhtml">C</a><a class="browselink" href="http://www.cmt.com/artists/browse/d.jhtml">D</a><a class="browselink" href="http://www.cmt.com/artists/browse/e.jhtml">E</a><a class="browselink" href="http://www.cmt.com/artists/browse/f.jhtml">F</a><a class="browselink" href="http://www.cmt.com/artists/browse/g.jhtml">G</a><a class="browselink" href="http://www.cmt.com/artists/browse/h.jhtml">H</a><a class="browselink" href="http://www.cmt.com/artists/browse/i.jhtml">I</a><a class="browselink" href="http://www.cmt.com/artists/browse/j.jhtml">J</a><a class="browselink" href="http://www.cmt.com/artists/browse/k.jhtml">K</a><a class="browselink" href="http://www.cmt.com/artists/browse/l.jhtml">L</a><a class="browselink" href="http://www.cmt.com/artists/browse/m.jhtml">M</a><a class="browselink" href="http://www.cmt.com/artists/browse/n.jhtml">N</a><a class="browselink" href="http://www.cmt.com/artists/browse/o.jhtml">O</a><a class="browselink" href="http://www.cmt.com/artists/browse/p.jhtml">P</a><a class="browselink" href="http://www.cmt.com/artists/browse/q.jhtml">Q</a><a class="browselink" href="http://www.cmt.com/artists/browse/r.jhtml">R</a><a class="browselink" href="http://www.cmt.com/artists/browse/s.jhtml">S</a><a class="browselink" href="http://www.cmt.com/artists/browse/t.jhtml">T</a><a class="browselink" href="http://www.cmt.com/artists/browse/u.jhtml">U</a><a class="browselink" href="http://www.cmt.com/artists/browse/v.jhtml">V</a><a class="browselink" href="http://www.cmt.com/artists/browse/w.jhtml">W</a><a class="browselink" href="http://www.cmt.com/artists/browse/x.jhtml">X</a><a class="browselink" href="http://www.cmt.com/artists/browse/y.jhtml">Y</a><a class="browselink" href="http://www.cmt.com/artists/browse/z.jhtml">Z</a><a class="browselink" href="http://www.cmt.com/artists/browse/123.jhtml">#</a></div>';

// creates a js variable called this.artistBrowseHTML

this.pageFooterHTML='<div id="footer"><table cellspacing="0" cellpadding="0" border="0" width="100%"><tr><td width="61%"><p class="nav"><nobr><a href="http://www.cmt.com/news/">News</a> | <a href="http://www.cmt.com/music/">Music</a> | <a href="http://www.cmt.com/shows/">On TV</a> | <a href="http://www.cmt.com/community/">Community</a> | <a href="http://www.cmt.com/mobile/">Mobile</a> | <a href="http://www.cmt.com/video/">Videos</a> | <a href="http://www.cmt.com/photos/">Photos</a> | <a href="http://www.cmt.com/music/radio/">Radio</a> | <a href="http://www.cmt.com/music/lyrics/">Lyrics</a></nobr></p><p class="nav"><a href="http://webtools.cmt.com/">CMT Webtools</a> | <a href="http://www.cmt.com/interact/help/">Help/FAQ</a> | <a href="http://www.cmt.com/adspecs/">Advertising</a> | <a href="http://www.cmt.com/sitemap/">Sitemap</a> | <a href="http://www.cmt.com/one_country/">CMT One Country</a> | <a href="http://learn.rhapsody.com/?pcode=via&amp;cpath=cmt_web&amp;rsrc=cmtfooter" rel="nofollow">Rhapsody</a></p><p>E-commerce on this website is brought to you by MTVN Direct Inc.</p></td><td width="39%" align="right" class="copyright_border"><p class="copyright"><a href="http://www.cmt.com/interact/terms/">Terms of Use</a> | <a href="https://jobhuntweb.viacom.com/jobhunt/main/jobhome.asp">Job Opportunities</a><br/><a href="http://www.cmt.com/interact/terms/privacy.jhtml">Privacy Statement</a> | <a href="http://www.cmt.com/interact/terms/user_content.jhtml">User Generated Content Statement</a><br/><a href="http://www.cmt.com/interact/terms/copyright_compliance_policy.jhtml">Copyright Compliance Policy</a></p></td></tr></table><div id="mtvn_attribution"><img src="http://www.cmt.com/sitewide/assets/img/logos/mtvn_logo_dark.gif" width="129" height="24" border="0" alt="MTV Networks"/> 2008 Country Music Television, Inc., a Viacom company. A division of <a href="http://www.cmt.com/interact/help/help_mtvn_info.jhtml">MTV Networks</a>. All Rights Reserved.</div></div>';
// creates a js variable called this.pageFooterHTML

this.create = function(name, contextNodeID){
switch(name){
case 'css': this.addCSS(); break;
case 'hat': this.setHat(); break;
case 'nav': Community.Widgets.createNav(contextNodeID); break;
case 'artistlist': Community.Widgets.createArtistlist(contextNodeID); break;
case 'footer': Community.Widgets.createFooter(contextNodeID); break;
case 'search': Community.Widgets.createSearch(contextNodeID); break;
case 'menu': Community.Widgets.createMenu(contextNodeID); break;
default: break;
}
}

this.createSearch = function(contextNodeID){
var div = document.createElement('div');
div.innerHTML = '<' + 'iframe src="' + Community.Widgets.hostname + '/widgets/search/iframe.jhtml" width="321" height="33" frameborder="0" scrolling="no" style="float:right;">search mtv</iframe>';
var contextNode = document.getElementById(contextNodeID);
if (contextNode) contextNode.appendChild(div);
}

this.createMenu = function(contextNodeId){
var obj = Community.Widgets.menuHTML;
if(obj){
var container = document.getElementById(contextNodeId); 
container.innerHTML = obj;
}
}

this.createNav = function(contextNodeId, headerObj){
var obj = Community.Widgets.headerObj;
if(obj){
var container = document.getElementById(contextNodeId); 
container.innerHTML = obj;
}
}

this.createFooter = function(contextNodeId){
var obj = Community.Widgets.pageFooterHTML;

if (obj){
var container = document.getElementById(contextNodeId);
container.innerHTML = obj;
}
}

this.createArtistlist = function(contextNodeId){
var obj = Community.Widgets.artistBrowseHTML;
if(obj){
var container = document.getElementById(contextNodeId); 
container.innerHTML = obj;
}
}

/***
*
* JSON Methods (can remove once replaced)
*
***/

this.createP = function(p, useSeparator){
var pElement = document.createElement('p');
if(p.id) pElement.setAttribute('id', p.id);
if(p['class']) pElement.className = p['class'];

if (p.a){
for (var x=0; x<p.a.length; x++){
pElement.appendChild(Community.Widgets.createA(p.a[x]));
if (x<p.a.length-1 && useSeparator) pElement.appendChild(document.createTextNode("|"));
}
}
else{ pElement.innerHTML = p.content; }
return pElement;
}

this.createImg = function(img){
var imgElement = document.createElement('img');
if(img.id) imgElement.setAttribute('id', p.id);

if(img['class']) imgElement.className = img['class'];
if(img.height) imgElement.setAttribute('height', img.height);
if(img.width) imgElement.setAttribute('width', img.width);
if(img.src) imgElement.setAttribute('src', img.src);
if(img.border) imgElement.setAttribute('border', img.border);
if(img.alt) imgElement.setAttribute('height', img.alt);

return imgElement;
}

this.createUL = function(ul){
var ulElement = document.createElement('ul');
if(ul.id) ulElement.setAttribute('id', ul.id);
if(ul['class']) ulElement.className = ul['class'];
if(ul.li.length==undefined) ulElement.appendChild(Community.Widgets.createLI(ul.li));
else{
for (var x=0; x<ul.li.length; x++){
ulElement.appendChild(Community.Widgets.createLI(ul.li[x]));
}
}
return ulElement;
}

this.createLI = function(li){
var liElement = document.createElement('li');

if(li.content) liElement.innerHTML = li.content;

if(li.id) liElement.setAttribute('id', li.id);
if(li['class']) liElement.className = li['class'];

if(li.a) liElement.appendChild(Community.Widgets.createA(li.a));
else if(li.span){
if(li.span instanceof Array){ 
for (var i=0; i<li.span.length; i++){
liElement.appendChild(Community.Widgets.createSpan(li.span[i]));
}
}
else liElement.appendChild(Community.Widgets.createSpan(li.span));
} 

if (li.ul) liElement.appendChild(Community.Widgets.createUL(li.ul));
if (li.div) liElement.appendChild(Community.Widgets.createDiv(li.div));

if (window.attachEvent){
liElement.onmouseover=function() {	this.className+=" sfhover";	}
liElement.onmouseout=function() { this.className=this.className.replace(new RegExp(" sfhover\\b"), ""); }
}

return liElement;
}

this.createDiv = function(div, useSeparator){
var divElement = document.createElement('div');

if(div.id) divElement.setAttribute('id', div.id);
if(div['class']) divElement.className = div['class'];

if(div.div instanceof Array){
for (var i=0; i<div.div.length; i++){
divElement.appendChild(Community.Widgets.createSubDiv(div.div[i], useSeparator));
}

}	
else if(div.div instanceof Object && div.div.div instanceof Array){
for (var i=0; i<div.div.div.length; i++){
divElement.appendChild(Community.Widgets.createSubDiv(div.div.div[i], useSeparator));
}
}
else if(div.div instanceof Object && div.div.a instanceof Array){
var divContainer = document.createElement('div');
if(div.div.id) divContainer.setAttribute('id', div.div.id);
if(div['class']) divContainer.className = div['class'];
divElement.appendChild(divContainer);

for (var i=0; i<div.div.a.length; i++){
divContainer.appendChild(Community.Widgets.createA(div.div.a[i]));
if (i<div.div.a.length-1 && useSeparator) divContainer.appendChild(document.createTextNode(" | ")); 
}
}

if(div.dl instanceof Array){
for (var i=0; i<div.dl.length; i++){
var dl = div.dl[i];
var dlElement = document.createElement('dl');
if(dl.id) dlElement.setAttribute('id', dl.id);
if(dl.dt){
var dtElement = document.createElement('dt');
dtElement.innerHTML = dl.dt;
dlElement.appendChild(dtElement);
}

if(dl.dd instanceof Array){
for (var j=0; j<dl.dd.length; j++){
var ddElement = document.createElement('dd');
ddElement.appendChild(Community.Widgets.createA(dl.dd[j].a));
dlElement.appendChild(ddElement);
}
}

divElement.appendChild(dlElement);
}
}

if(div.a){
if(div.a instanceof Array){
for (var i=0; i<div.a.length; i++){
divElement.appendChild(Community.Widgets.createA(div.a[i]));
if (i<div.a.length-1 && useSeparator) divElement.appendChild(document.createTextNode(" | "));
}
}
else divElement.appendChild(Community.Widgets.createA(div.a));
}

if(div.p){
if(div.p instanceof Array){
for (var i=0; i<div.p.length; i++){
divElement.appendChild(Community.Widgets.createP(div.p[i], useSeparator));
}
}
else divElement.appendChild(Community.Widgets.createP(div.p, useSeparator));
}

if(div.img){
if(div.img instanceof Array){
for (var i=0;i<div.img.length;i++){
divElement.appendChild(Community.Widgets.createImg(div.img[i]));
}
}
else divElement.appendChild(Community.Widgets.createImg(div.img));
}

if(div.content && !(div.content instanceof Array)){
divElement.innerHTML = div.content;
}

return divElement;
}

this.createSubDiv = function(subDiv, useSeparator){

var subDivElement = document.createElement('div');
if(subDiv.id) subDivElement.setAttribute('id', subDiv.id);
if(subDiv['class']) subDivElement.className = subDiv['class'];
if(subDiv.strong) subDivElement.appendChild(Community.Widgets.createStrong(subDiv.strong));

if(subDiv.a instanceof Array){
for (var i=0; i<subDiv.a.length; i++){
subDivElement.appendChild(Community.Widgets.createA(subDiv.a[i]));
if (i<subDiv.a.length-1 && useSeparator) subDivElement.appendChild(document.createTextNode(" | "));
}
}

if(subDiv.div instanceof Array){
for (var i=0; i<subDiv.div.length; i++){
subDivElement.appendChild(Community.Widgets.createSubDiv(subDiv.div[i], useSeparator));
}
}
else if(subDiv.div instanceof Object && subDiv.div.a instanceof Array){
for (var i=0; i<subDiv.div.a.length; i++){
subDivElement.appendChild(Community.Widgets.createA(subDiv.div.a[i]));
if (i<subDiv.div.a.length-1 && useSeparator) subDivElement.appendChild(document.createTextNode(" | ")); 
}
}

//if(subDiv.div) subDivElement.appendChild(Community.Widgets.createDiv(subDiv.div, useSeparator));

if(subDiv.p){
if(subDiv.p instanceof Array){
for (var i=0; i<div.p.length; i++){
subDivElement.appendChild(Community.Widgets.createP(subDiv.p[i], useSeparator));
}
}
else subDivElement.appendChild(Community.Widgets.createP(subDiv.p, useSeparator));
}

if(subDiv.img){
if(subDiv.img instanceof Array){
for (var i=0;i<div.img.length;i++){
subDivElement.appendChild(Community.Widgets.createImg(subDiv.img[i]));
}
}
else subDivElement.appendChild(Community.Widgets.createImg(subDiv.img));
} 

if(subDiv.content && !(subDiv.content instanceof Array)){
subDivElement.innerHTML = subDiv.content;
}

return subDivElement;
}

this.createA = function(a){
var aElement = document.createElement('a');

if(a.id) aElement.setAttribute('id', a.id);
if(a['class']) aElement.className = a['class'];
if(a.href) aElement.setAttribute('href', a.href);
if(a.target) aElement.setAttribute('target', a.target);
if(a.onclick) aElement.setAttribute('onclick', a.onclick);
if(a.img){
aElement.appendChild(Community.Widgets.createImg(a.img));
}
else {
aElement.innerHTML = a.content;
}	

return aElement;
}

this.createSpan = function(span){
var spanElement = document.createElement('span');

if(typeof span == 'object'){
if(span['class']) spanElement.className = span['class'];
if(span.content) spanElement.innerHTML = span.content;
if(span.a instanceof Array){
for(var i=0; i<span.a.length; i++){
spanElement.appendChild(Community.Widgets.createA(span.a[i]));
spanElement.innerHTML += "\n";
spanElement.appendChild(document.createTextNode(""));
}
}
}
else { spanElement.innerHTML = span + "\n";}

return spanElement;
}

this.createStrong = function(strong){
var strongElement = document.createElement('strong');
strongElement.innerHTML = strong;
return strongElement;
}
}

Community.Page.addCSSLink('/sitewide/styles/global_header.css');
Community.Page.addCSSLink('/sitewide/styles/global_footer.css');
Community.Page.addCSSLink('/sitewide/styles/global_main.css');
Community.Page.addCSSLink('/sitewide/community/styles/master.css');
