
/*******************************************************************
 * Create the page object
 *******************************************************************/
var pageObj = {
    color1: "#000000",
    LinkColor: "#000000",
    BgColor: "#ffffff",
    HoverColor: "#000000",
    init: function() {
        //Load sIFR
        pageObj.sifr();

        pageObj.hideWidget();

        pageObj.hidePostPageBlock();

        pageObj.positionSignin();

        pageObj.toggleFavorites();

        //Load relEvents
        pageObj.relEvents();
    },

    sifr: function() {

        if (typeof sIFR == "function") {

            var titles;
            var k;

            //.extrasitem h4
            titles = new Array("#poll h1", ".promoflash h2", ".extras h2", ".casttext", ".morefamily h2",  "#hotposts h1", "#blogposts h1", "#showtime");

            for (k in titles) {

                //alert(titles[k]);

                sIFR.replaceElement(named({
                    sSelector: titles[k],
                    sFlashSrc: globalObj.mediaServer + "/abcfamily/images/flash/abc.swf",
                    sColor: pageObj.color1,
                    sLinkColor: pageObj.LinkColor,
                    sBgColor: pageObj.BgColor,
                    sHoverColor: pageObj.HoverColor,
                    nPaddingTop: 0,
                    nPaddingBottom: 0,
                    sFlashVars: "textalign=left",
                    sWmode: "transparent"
                }));
            }

            //more family
	    sIFR.replaceElement(named({sSelector:"#tagline", sFlashSrc: globalObj.mediaServer + "/abcfamily/images/flash/abc.swf", sColor:"#666666", sLinkColor:"#666666", sBgColor:"#FFFFFF", sHoverColor:"#666666", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left", sWmode:"transparent" }));
            
            //more family
	    sIFR.replaceElement(named({sSelector:".morefamily h4", sFlashSrc: globalObj.mediaServer + "/abcfamily/images/flash/abc.swf", sColor:"#333333", sLinkColor:"#666666", sBgColor:"#FFFFFF", sHoverColor:"#666666", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left", sWmode:"transparent" }));

	    //extras
            sIFR.replaceElement(named({sSelector:".extrasitem h4", sFlashSrc: globalObj.mediaServer + "/abcfamily/images/flash/abc.swf", sColor:"#333333", sLinkColor:"#666666", sBgColor:"#FFFFFF", sHoverColor:"#666666", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left", sWmode:"transparent"}));

            //top talkers
	    sIFR.replaceElement(named({sSelector:"#toptalkers h1", sFlashSrc: globalObj.mediaServer + "/abcfamily/images/flash/abc.swf", sColor:"#000000", sLinkColor:"#666666", sBgColor:"#FFFFFF", sHoverColor:"#666666", nPaddingTop:0, nPaddingBottom:0, sFlashVars:"textalign=left", sWmode:"transparent" }));


        };
    },
    hideWidget: function() {
        var ac = document.getElementById('archivescontent');
        var wc = document.getElementById('widgetscontent');
        var wtab = document.getElementById('widgetstab');
        var atab = document.getElementById('archivestab');
        if (wtab && atab && ac) ac.style.display = 'none';
        if (wc) wc.style.display = "block";

    },

    hidePostPageBlock: function() {
        if (typeof(blog_page_size) != "undefined") {
            for (i = 1; i < blog_page_size; i++) {
                var postPageObj = document.getElementById('post_' + (i + 1));
                if (postPageObj) {
                    postPageObj.style.display = "none";
                }
            }
        }
    },
    
	relEvents:function(){
		var relType;
		var self = pageObj.relEvents;
		self.col = document.getElementsByTagName('a');
		duff(self.col, function(e){
			relType = e.getAttribute('rel');
			switch(relType){
				case 'about':    //movie main
					addEvent(e,"click",function(){
						change_tab('about', 'credit');
						return false;
					});
					break;
				case 'credit':    //movie main
					addEvent(e,"click",function(){
						change_tab('credit', 'about')
						return false;
					});
					break;
				case 'widgets':    //blog
					addEvent(e,"click",function(){
						change_tab('widgets', 'archives');
						return false;
					});
					break;
				case 'archives':    //blog
					addEvent(e,"click",function(){
						change_tab('archives', 'widgets');
						return false;
					});
					var ac = document.getElementById('widgetscontent');
					if (ac) ac.style.display = 'none';					
					break;
				default:
					break;
			}
		});
	},
	
    positionSignin: function() {
        var nr = document.getElementById('narrowright');
        var wa = document.getElementById('wdgtarchv');
        //when widget/archive module is present, and signin module is present
        if ((typeof wa != 'undefined') && (nr != 'undefined')) {
            //nr.className = 'nrblog';
        }
    },
    toggleFavorites: function() {
        var blogpost = document.getElementById("blogposts");
        if (blogpost) {
            var tags = blogpost.getElementsByTagName('ul');

            for (i = 0; i < tags.length; i++) {
                if (tags[i].className.indexOf('favorites') > -1) {
                    tags[i].onclick = function() {
                        var li = this.getElementsByTagName('li');
                        var addHref = null;
                        var isAddCalled = false;
                        for (x = 0; x < li.length; x++) {
                            if (li[x].className.indexOf("off") > -1) {
                                li[x].className = li[x].className.replace("off", "on");
                            } else if (li[x].className.indexOf("on") > -1) {
                                addHref = li[x].getElementsByTagName('a')[0].href;
                                li[x].className = li[x].className.replace("on", "off");
                            }
                            if (li[x].className == "add on") {
                                loadXMLDoc('/abcfamily/_global/modules/general/favorites?type=post&id=' + this.id.replace('fav', '') + '&action=del');
                            } else if (li[x].className == "del on") {
                                //loadXMLDoc('/abcfamily/_global/modules/general/favorites?type=post&id='+this.id.replace('fav','')+'&action=add');
                                isAddCalled = true;
                            }
                        }
                        if (isAddCalled && addHref) {
                            window.location = addHref;
                        }
                    };
                }
            }
        }
    }

};

/*******************************************************************
 * Attach events to the document load
 *******************************************************************/
addEvent(document, "readystatechange", pageObj.init);

//hide tabs and pages
function hideContents(thisweekLen, allmoviesLen) {
    document.getElementById("allmoviescontent").style.display = "none";
    for (i = 1; i < thisweekLen; i++) {
        obj = document.getElementById("thisWeekMovies_" + (i + 1));
        if (obj) {
            obj.style.display = "none";
        }
    }
    for (i = 1; i < allmoviesLen; i++) {
        obj = document.getElementById("allMovies_" + (i + 1));
        if (obj) {
            obj.style.display = "none";
        }
    }
}

