locationDetails = whereAmI();

/*
        Date Format 1.1
        (c) 2007 Steven Levithan <stevenlevithan.com>
        MIT license
        With code by Scott Trenda (Z and o flags, and enhanced brevity)
*/

/*** dateFormat
        Accepts a date, a mask, or a date and a mask.
        Returns a formatted version of the given date.
        The date defaults to the current date/time.
        The mask defaults ``"ddd mmm d yyyy HH:MM:ss"``.
*/
var dateFormat = function () {
        var	token        = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloZ]|"[^"]*"|'[^']*'/g,
                timezone     = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
                timezoneClip = /[^-+\dA-Z]/g,
                pad = function (value, length) {
                        value = String(value);
                        length = parseInt(length) || 2;
                        while (value.length < length)
                                value = "0" + value;
                        return value;
                };

        // Regexes and supporting functions are cached through closure
        return function (date, mask) {
                // Treat the first argument as a mask if it doesn't contain any numbers
                if (
                        arguments.length == 1 &&
                        (typeof date == "string" || date instanceof String) &&
                        !/\d/.test(date)
                ) {
                        mask = date;
                        date = undefined;
                }

                date = date ? new Date(date) : new Date();
                if (isNaN(date))
                        throw "invalid date";

                var dF = dateFormat;
                mask   = String(dF.masks[mask] || mask || dF.masks["default"]);

                var	d = date.getDate(),
                        D = date.getDay(),
                        m = date.getMonth(),
                        y = date.getFullYear(),
                        H = date.getHours(),
                        M = date.getMinutes(),
                        s = date.getSeconds(),
                        L = date.getMilliseconds(),
                        o = date.getTimezoneOffset(),
                        flags = {
                                d:    d,
                                dd:   pad(d),
                                ddd:  dF.i18n.dayNames[D],
                                dddd: dF.i18n.dayNames[D + 7],
                                m:    m + 1,
                                mm:   pad(m + 1),
                                mmm:  dF.i18n.monthNames[m],
                                mmmm: dF.i18n.monthNames[m + 12],
                                yy:   String(y).slice(2),
                                yyyy: y,
                                h:    H % 12 || 12,
                                hh:   pad(H % 12 || 12),
                                H:    H,
                                HH:   pad(H),
                                M:    M,
                                MM:   pad(M),
                                s:    s,
                                ss:   pad(s),
                                l:    pad(L, 3),
                                L:    pad(L > 99 ? Math.round(L / 10) : L),
                                t:    H < 12 ? "a"  : "p",
                                tt:   H < 12 ? "am" : "pm",
                                T:    H < 12 ? "A"  : "P",
                                TT:   H < 12 ? "AM" : "PM",
                                Z:    (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
                                o:    (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4)
                        };

                return mask.replace(token, function ($0) {
                        return ($0 in flags) ? flags[$0] : $0.slice(1, $0.length - 1);
                });
        };
}();

// Some common format strings
dateFormat.masks = {
        "default":       "ddd mmm d yyyy HH:MM:ss",
        shortDate:       "m/d/yy",
        mediumDate:      "mmm d, yyyy",
        longDate:        "mmmm d, yyyy",
        fullDate:        "dddd, mmmm d, yyyy",
        shortTime:       "h:MM TT",
        mediumTime:      "h:MM:ss TT",
        longTime:        "h:MM:ss TT Z",
        isoDate:         "yyyy-mm-dd",
        isoTime:         "HH:MM:ss",
        isoDateTime:     "yyyy-mm-dd'T'HH:MM:ss",
        isoFullDateTime: "yyyy-mm-dd'T'HH:MM:ss.lo"
};

// Internationalization strings
dateFormat.i18n = {
        dayNames: [
                "Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat",
                "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
        ],
        monthNames: [
                "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
                "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
        ]
};

// For convenience...
Date.prototype.format = function (mask) {
        return dateFormat(this, mask);
}

var randDARTNumber=0;
var pageURI='';
function genSetRandDARTNumber()
{
  randDARTNumber = Math.round(Math.random()*1000000000000);
}
function genPageURI()
{
  pageURI = escape(document.URL.substring(document.URL.indexOf('/',8)+1));
}
genSetRandDARTNumber();
genPageURI();

function getPageSize(){
    var de = document.documentElement;
    var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
    var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight
    arrayPageSize = new Array(w,h) 
    return arrayPageSize;
}

function refreshAds() {
    genSetRandDARTNumber();
    refreshAd("#leaderboard");
    refreshAd("#square");
}

function refreshAd(id) {
    /*if($(id).size() != 0) {
        $(id)[0].src = $(id)[0].src;
    }*/
    if($(id).size() != 0) {
        adServerURL = $(id)[0].src.substring(0,$(id)[0].src.lastIndexOf("?"));
        qString = $(id)[0].src.substring(($(id)[0].src.lastIndexOf("?")+1),$(id)[0].src.length);
        temp = qString.split("&");
        var qArray = {};
        for(i=0;i<temp.length;i++) {
            z = temp[i].split("=");
            qArray[z[0]] = z[1];
        }
        qArray["randDARTNumber"] = randDARTNumber;
        qArray["adType"] = id.substring(1,id.length);
        newServerURL = adServerURL;
        currOperator = "?";
        i = 0;
        for(var key in qArray) {
            if(i != 0) {
                currOperator = "&";
            }
            newServerURL = newServerURL + currOperator + key + "=" + qArray[key];
            i++;
        }
        $(id)[0].src = newServerURL;
    }
}

function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    } else {
        return document[movieName];
    }
}

function popupWin(aUrl,aName,properties) {
    window.open(aUrl,aName,properties);
}

function showVideo() {
     if(typeof embeddedPlayerManager.getPlayer == "function" && typeof embeddedPlayerManager.getPlayer() == "object") {
          embeddedPlayerManager.getPlayer().unHidePlayer();
     } else {
          setTimeout(function () {
               showVideo();
          }, "250");
     }
}

function checkVideo() {
     if(typeof embeddedPlayerManager.getPlayer().currentClip.title != "undefined") {
          $("#square").hide();
          $("#panel_1_1 div.prWrap").hide();
          $("#companionad").show();
          showVideoDetails();
     } else {
          setTimeout(function () {
               checkVideo();
          }, "250");
     }
}

function showVideoDetails() {
    currClipInfo = embeddedPlayerManager.getPlayer().currentClip;
    if(embeddedPlayerManager.getPlayer().isPlayingAd() == false) {
        $("#video_title").html(currClipInfo.title);
        $("#video_description").html(currClipInfo.shortDescription);
    } else {
        setTimeout(function () {
            showVideoDetails();
        }, "250");
    }
    //setColumnHeights();
}

function jumpToAnchor(anchor) {
    if($(anchor).size() != 0) {
        newPos = $(anchor).offset().top;
        document.documentElement.scrollTop = newPos;
        document.body.scrollTop = newPos;
    }
}

function playSelectedVideo(url) {
    $("#video_title").empty();
    $("#video_description").empty();
    if($("div#videoplayer").size() != 0) {
        param = url.substring(url.lastIndexOf("=")+1, url.length);
        if(embeddedPlayerManager.getPlayer().isPlayingAd() == false) {
               embeddedPlayerManager.getPlayer().playVideo(param);
               embeddedPlayerManager.getPlayer().play();
               contTop = $("div.videos ul").offset().top;
               itemTop = $("div.videos li.active div.image").offset().top;
               diff = itemTop - contTop;
               $("div.videos ul")[0].scrollTop = $("div.videos ul")[0].scrollTop + diff;
        } else {
            alert("Please wait till the pre-roll ad is finished before selecting another video to play.");
        }
    } else {
        window.location = url;
    }
    return false;
}

function nextVideo() {
     thisIndex = $("div.videos li").index($("div.videos li.active")[0]) + 1;
     if(thisIndex > $("div.videos li").size()) {
          return false;
     }
     $("div.videos li").removeClass("active").eq(thisIndex).addClass("active");
     contTop = $("div.videos ul").offset().top;
     itemTop = $("div.videos li.active div.image").offset().top;
     diff = itemTop - contTop;
     $("div.videos ul")[0].scrollTop = $("div.videos ul")[0].scrollTop + diff;
     playSelectedVideo($("div.videos li.active a").attr("href"));
}

function setColumnHeights() {
    settings = {
        base: 0,
        columns: [
            "#col_0",
            "#panel_1_0,#panel_1_1,#channel_1_1,#panel_1_2,#channel_1_2,#panel_1_3"
        ],
        columnEnds: []
    };
    heights = [];
    for(i=0;i<settings.columns.length;i++) {
        heights[i] = 0;
        panels = settings.columns[i].split(",");
        for(z=0;z<panels.length;z++) {
            $(panels[panels.length-1] + " div.end").css("margin-top", 0);
            if($(panels[z]).size() != 0) {
               heights[i] += $(panels[z]).outerHeight();
            }
            if(z==panels.length - 1) {
                settings.columnEnds.push(panels[z] + " div.end");
            }
        }
    }
    for(i=0;i<settings.columns.length;i++) {
        if(i != settings.base) {
            diff = heights[settings.base] - heights[i];
            if(diff > 0) {
                $(settings.columnEnds[i]).css("margin-top", diff);
            }
        }
    }
}

function generateID() {
    var curdate = new Date()
    var seconds = curdate.getSeconds();
    var milliseconds = curdate.getTime();
    id = "id" + Math.floor(Math.random()*Math.floor(milliseconds/seconds));
    return id;
}

function getUID() {
    var d = new Date();
    var uID = Math.floor(Math.random()*d.getMilliseconds()) + "-" + Math.floor(Math.random()*d.getMilliseconds());
    return uID;
}

var photoIndex = [];
var currIndex = 0;
var desiredPhotoID = null;
var currDate = new Date();
var currSize = "large";
var currGalleryIndex = 0;
var useLast = false;
var currArticleIndex = 0;

var xmlDoc = "";

// Massage currDate to match the EC timezone
var localTimezoneOffset = currDate.getTimezoneOffset();
var offsetDifference = localTimezoneOffset - 300;
currDate.setMinutes(currDate.getMinutes() + offsetDifference);
currDate = currDate.format("yyyy-mm-dd HH:MM:ss");

function xmlSuccess(xml) {
    photoIndex.length = 0;
    currIndex = 0;
    xmlDoc = $(xml);
    $("photo", xmlDoc).each(function (i) {
        effFrom = $(this).attr("eff_from");
        effThru = $(this).attr("eff_thru");
        if(effFrom == "" || effFrom == undefined) {
            effFrom = new Date();
            effFrom = effFrom.format("yyyy");
            effFrom = parseInt(effFrom) - 5;
            effFrom = effFrom + "-01-01 00:00:00";
        }
        if(effThru == "" || effThru == undefined) {
            effThru = new Date();
            effThru = effThru.format("yyyy");
            effThru = parseInt(effThru) + 5;
            effThru = effThru + "-01-01 00:00:00";
        }
        if(effFrom < currDate && effThru > currDate && $(this).attr("is_active") == "1") {
            newLoc = $(this).attr("large");
            newLoc = newLoc.replace("400x400bd", "0x600");
            photoIndex.push({small:$(this).attr("small"),medium:$(this).attr("medium"),large:$(this).attr("large"),xlrg:newLoc,caption:$(this).attr("caption"),credit:$(this).attr("credit")});
            if (desiredPhotoID != null) {
                currPhotoID = $(this).attr("small");
                currPhotoID = currPhotoID.substring(currPhotoID.lastIndexOf("/")+1,currPhotoID.lastIndexOf("."));
                if(currPhotoID == desiredPhotoID) {
                    currIndex = i;
                }
            }
        }
    });
    if(photoIndex.length != 0) {
        $("h1#photogallery_title").text($("gallery",xmlDoc).attr("long_title"));
        $("div.indicator cite").text("1/"+(photoIndex.lezngth));
        buildPhotoGallery();
        //setTimeout(checkForPhotoGallery, "250");
    }
}

function xmlError() {
    $("h1#photogallery_title").text("XML not found").siblings("div.thin").empty();
}

function buildPhotoGallery() {
    loc = "photogalleryflash";
    if(arguments.length != 0) {
        loc = arguments[0];
    }
    var so = new SWFObject("/ah/flash/app-pg.swf" + "?" + Math.floor(Math.random()*11), "pg", "400", "470", "9", "#000000");
    so.addParam("wmode", "transparent");
    so.addParam("AllowScriptAccess", "always");
    so.write(loc);
    setTimeout(checkForPhotoGallery, "250");
}

function checkForPhotoGallery() {
    if(($("#photogalleryflash embed").size() == 1 || $("#photogalleryflash object").size() == 1) && typeof thisMovie("pg") != undefined && typeof thisMovie("pg").loadImg == "function") {
        changeImage(photoIndex[currIndex]);
    } else {
        setTimeout(checkForPhotoGallery, "500");
    }
}

function getImage(dir) {
    switch (typeof dir) {
        case 'number':
            currIndex = dir;
        break;
        case 'string':
            if(dir == "next") {
                currIndex++;
            }
            if(dir == "prev") {
                currIndex--;
            }
        break;
    }
    changeImg = true;
    if(currIndex >= photoIndex.length) {
        getGallery("next");
        changeImg = false;
    }
    if(currIndex < 0) {
        getGallery("prev","last");
        changeImg = false;
    }
    if(changeImg) {
        changeImage();
        refreshAds();
        if(typeof s.t == "function") {
            s.t();
        }
    }
}

function getGallery(dir) {
    currGalleryIndex = $("div.galleries li").index($("div.galleries li.active")[0]);
    switch (typeof dir) {
        case 'number':
            currGalleryIndex = dir;
        break;
        case 'string':
            if(dir == "next") {
                currGalleryIndex++;
            }
            if(dir == "prev") {
                currGalleryIndex--;
                if(arguments.length > 1) {
                    useLast = true;
                }
            }
        break;
    }
    if(currGalleryIndex > $("div.galleries li").size() - 1) {
        currGalleryIndex = 0;
    }
    if(currGalleryIndex < 0) {
        currGalleryIndex = $("div.galleries li").size() - 1;
    }
    changeGallery();
}

function changeGallery() {
    $("div.galleries li").removeClass("active").eq(currGalleryIndex).addClass("active");
     contTop = $("div.galleries ul").offset().top;
     itemTop = $("div.galleries li.active div.image").offset().top;
     diff = itemTop - contTop;
     $("div.galleries ul")[0].scrollTop = $("div.galleries ul")[0].scrollTop + diff;
    photoXmlUrl = "http://www.accesshollywood.com/ah/xml/gallery/";
    galleryId = $("div.galleries li.active a")[0].href.match(/\/\d+\/?/);
    galleryId = galleryId.toString();
    galleryId = galleryId.substring(1,galleryId.length);
    if(galleryId.lastIndexOf("/")) {
        galleryId = galleryId.substring(0,galleryId.lastIndexOf("/"));
    }
    photoXmlUrl += galleryId + ".xml";
    $.ajax({
        url: photoXmlUrl + "?" + Math.floor(Math.random()*11),
        dataType: "xml",
        success: function (xml) {
            xmlSuccess(xml);
        },
        error: xmlError
    });
}

function changeImage() {
    if(useLast) {
        currIndex = photoIndex.length - 1;
        useLast = false;
    }
    $("div.caption p, div.content-holder div.footer div.wide p").html(photoIndex[currIndex]["caption"]);
    $("div.indicator cite").text((currIndex+1)+"/"+(photoIndex.length));
    $("div.credit cite").text("CREDIT:" + photoIndex[currIndex]["credit"]);
    thisMovie("pg").loadImg(photoIndex[currIndex][currSize] + "?" + Math.floor(Math.random()*11));
    refreshAds();
    if(typeof s.t == "function") {
        s.t();
    }
}

function enlargeImage() {
    windowDetails = getPageSize();
    $("div.overlay, div.content-holder").remove();
    $("html").css("overflow","hidden");
    $("html")[0].scrollTop = 0;
    $("<div class='overlay'></div>").css({position:"absolute",zIndex:10000,top:0,left:0,width:windowDetails[0],height:windowDetails[1],opacity:.75}).appendTo("body");
    contentHolderFrag = $("<div class='content-holder'><div class='header'><div class='thin'><div class='logo'>&nbsp;</div></div><div class='channel'>&nbsp;</div><div class='wide'><div class='ad'>&nbsp;</div></div></div><div class='image-holder'><div class='wide'><div id='flashcontent'>&nbsp;</div></div><div class='channel'>&nbsp;</div><div class='thin'><div class='ad'>&nbsp;</div></div></div><div class='footer'><div class='description'><div class='wide'>&nbsp;</div><div class='channel'>&nbsp;</div><div class='thin'><div class='nav'></div></div></div></div></div>");
    contentHolderFrag.css({position:"absolute",zIndex:11000,top:0,left:0,width:windowDetails[0],height:windowDetails[1]}).appendTo("body");
    $("div.logo *").appendTo("div.content-holder div.logo");
    $("div#header div.ad *").appendTo("div.content-holder div.header div.ad");
    $("#panel_1_0").clone().prependTo("div.content-holder div.image-holder div.thin").end().css("background-position","-1000px -1000px");
    $("div#panel_1_1 div.ad *").appendTo("div.content-holder div.image-holder div.ad");
    $("div.photogallery div.nav div.credit").clone().prependTo("div.content-holder div.footer div.wide");
    $("div.photogallery div.thin div.caption *").clone().prependTo("div.content-holder div.footer div.wide");
    $("div.photogallery h1").clone().prependTo("div.content-holder div.footer div.wide");
    $("div.photogallery div.thin div.nav div.indicator").clone().prependTo("div.content-holder div.footer div.thin div.nav");
    $("div.photogallery div.nav ul").clone().appendTo("div.content-holder div.footer div.thin div.nav");
    $("div.content-holder div.description div.nav ul li.magnify").attr("class","shrink");
    $("div#photogalleryflash").empty();
    buildPhotoGallery("flashcontent");
    baseWidth = 680;
    baseHeight = windowDetails[1];
    newHeight = baseHeight - $("div.content-holder div.header").height() - $("div.content-holder div.footer").height() - 20;
    currSize = "xlrg";
    if($("div.content-holder #flashcontent embed").size() != 0) {
        $("div.content-holder #flashcontent embed").attr("width",baseWidth);
        $("div.content-holder #flashcontent embed").attr("height",newHeight);
    }
    if($("div.content-holder #flashcontent object").size() != 0) {
        $("div.content-holder #flashcontent object").attr("width",baseWidth);
        $("div.content-holder #flashcontent object").attr("height",newHeight);
    }
    newHeight = newHeight - 300;
    $("div.content-holder div.image-holder div.thin div#panel_1_0").css("margin-bottom",newHeight);
    $("div.content-holder div.nav li.prev a").bind("click", function () {
        getImage("prev");
        return false;
    });
    $("div.content-holder div.nav li.next a").bind("click", function () {
        getImage("next");
        return false;
    });
    $("div.content-holder div.nav li.shrink a").bind("click", function () {
        collapsePhoto();
        return false;
    });
    setTimeout(changeImage, "250");
    pgHeight = $("div.photogallery").outerHeight({margin:true});
    $("div.photogallery").children().hide().end().css("height",pgHeight);
}

function collapsePhoto() {
    $("html").css("overflow","auto");
    $("div.content-holder div.logo *").appendTo("div#header div.logo");
    buildPhotoGallery();
    $("div.photogallery").children().show();
    $("div.content-holder div.header div.ad *").appendTo("div#header div.ad");
    $("div.content-holder div.image-holder div.ad *").appendTo("div#companionad");
    $("#panel_1_0").css("background-position","0 0");
    if($("div#photogalleryflash embed").size() != 0) {
        $("div#photogalleryflash embed").attr("width",400);
        $("div#photogalleryflash embed").attr("height",500);
    }
    if($("div#photogalleryflash object").size() != 0) {
        $("div#photogalleryflash object").attr("width",400);
        $("div#photogalleryflash object").attr("height",500);
    }
    currSize = "large";
    $("div.overlay, div.content-holder").remove();
    setTimeout(changeImage, "250");
}

function hideLoadingBG() {
    $("div#photogalleryflash, div#flashcontent").css("background-image","none");
}

function showLoadingBG() {
    $("div#photogalleryflash").css("background-image","url(/ah/images/anim/pg_loading_01.gif)");
    $("div#flashcontent").css("background-image","url(/ah/images/anim/pg_loading_02.gif)");
}

function getArticle(dir) {
    currArticleIndex = $("div.articles li").index($("div.articles li.active")[0]);
    switch (typeof dir) {
        case 'number':
            currArticleIndex = dir;
        break;
        case 'string':
            if(dir == "next") {
                currArticleIndex++;
            }
            if(dir == "prev") {
                currArticleIndex--;
            }
        break;
    }
    if(currArticleIndex > $("div.articles li").size() - 1) {
        currArticleIndex = 0;
    }
    if(currArticleIndex < 0) {
        currArticleIndex = $("div.articles li").size() - 1;
    }
    changeArticle();
}

function changeArticle() {
    $("div.articles li").removeClass("active").eq(currArticleIndex).addClass("active");
    contTop = $("div.articles ul").offset().top;
     itemTop = $("div.articles li.active div.image").offset().top;
     diff = itemTop - contTop;
     $("div.articles ul")[0].scrollTop = $("div.articles ul")[0].scrollTop + diff;
    articleJSONUrl = "http://ahcms2.nbcuni.com/services/ah2_showcase_article.php?q=";
    articleId = $("div.articles li.active a")[0].href.match(/\/\d+\/?/);
    articleId = articleId.toString();
    articleId = articleId.substring(1,articleId.length);
    if(articleId.lastIndexOf("/")) {
        articleId = articleId.substring(0,articleId.lastIndexOf("/"));
    }
    articleJSONUrl += articleId;
    $.ajax({
        dataType: 'jsonp',
        jsonp: 'jsonp_callback',
        url: articleJSONUrl,
        success: function (data) {
            populateArticle(data);
        }
    });
}

function populateArticle(data) {
    if(data.article.error == false) {
        createdAt = data.images.data[0].CREATED_AT;
        createdAt = createdAt.substring(0,7);
        temp = createdAt.split("-");
        imageDir = "/ah/images/content/" + temp[0] + temp[1] + "/230x306/" + data.images.data[0].FILENAME;
        $("div.article div.photo-collection div.image img").attr("src",imageDir);
        $("div.article h1").html(data.article.data[0].LONG_TITLE);
        $("div.article div.wide").html(data.article.data[0].CONTENT);
    } else {
        //console.log(data.article.error);
    }
}

$(document).ready(function () {
    $("div#logo").each(function () {
        var so = new SWFObject("http://accesshollywood.nbcunifiles.com/ah/flash/access-logo.swf", "logo", "250", "130", "9", "#000000");
        so.addParam("wmode", "transparent");
        so.write(this.id);
    });
    
    $("div.videos a[@href*=video]").bind("click", function () {
        playSelectedVideo(this.href);
        //jumpToAnchor("a[@name=top]");
        thisIndex = $("div.videos li a").index(this);
        $("div.videos li").removeClass("active").eq(thisIndex).addClass("active");
        return false;
    });
    
    $("div.galleries a").bind("click", function () {
        $("div.galleries li").removeClass("active");
        $(this).parents("li").addClass("active");
        currGalleryIndex = $("div.galleries li").index($("div.galleries li.active")[0]);
        changeGallery();
        //setTimeout(changeGallery, "1500");
        return false;
    });
    
    $("div.articles a").bind("click", function () {
        $("div.articles li").removeClass("active");
        $(this).parents("li").addClass("active");
        getArticle();
        return false;
    });
    
    $("div.article div.nav a").bind("click", function () {
        getArticle($(this).parent()[0].className);
        return false;
    });
    
    $(".flashcontent").each(function () {
        var newID = generateID();
        $(this).attr("id",newID);
        classNames = $(this)[0].className.split(" ");
        fontSize = 22;
        for(i=0;i<classNames.length;i++) {
            check = classNames[i].split("-");
            if(check.length > 1) {
                fontSize = check[1];
            }
        }
        $(this).removeClass("flashcontent").height(fontSize*2);
        txtString = $("#" + newID).text();
        uid = getUID();
        var so = new SWFObject("http://accesshollywood.nbcunifiles.com/ah/flash/reflectionHeadlines.swf?uid=" + uid, newID, "990", "88", "9", "#000000");
        so.addParam("wmode", "transparent");
        so.addVariable("text",txtString);
        so.addVariable("size",fontSize);
        so.addVariable("uid",uid);
        so.write(newID);
    });
    
    $("ul.tabs a").bind("click", function () {
        thisIndex = $("ul.tabs a").index(this);
        $("ul.tabs a").removeClass("on").eq(thisIndex).addClass("on");
        switch($("ul.tabs a:eq(" + thisIndex + ")").parent("li").attr("class")) {
                case 'videos':
                        $("#square").hide();
                        $("#panel_1_1 div.prWrap").hide();
                        $("#companionad").show();
                        embeddedPlayerManager.getPlayer().unHidePlayer();
                        embeddedPlayerManager.getPlayer().play();
                        $("body")[0].scrollTop += 2;
                break;
                case 'galleries':
                        $("#square").css({width:"300px",height:"250px"}).show();
                        $("#panel_1_1 div.prWrap").show();
                        $("#companionad").hide();
                        if($("#videoplayer").size() != 0) {
                                embeddedPlayerManager.getPlayer().pause();
                                embeddedPlayerManager.getPlayer().hidePlayer();
                        }
                break;
                case 'articles':
                        $("#square").css({width:"300px",height:"250px"}).show();
                        $("#panel_1_1 div.prWrap").show();
                        $("#companionad").hide();
                        if($("#videoplayer").size() != 0) {
                                embeddedPlayerManager.getPlayer().pause();
                                embeddedPlayerManager.getPlayer().hidePlayer();
                        }
                break;
        }
        $("#showcase div.panel").removeClass("on").eq(thisIndex).addClass("on");
        $("#showcase div.more").removeClass("on").eq(thisIndex).addClass("on");
        return false;
    });
    
    if(typeof galleryID != "undefined") {
        var photoXmlUrl = "/ah/xml/gallery/";
        photoXmlUrl += galleryID + ".xml";
    
        $.ajax({
            url: photoXmlUrl + "?" + Math.floor(Math.random()*11),
            dataType: "xml",
            success: function (xml) {
                xmlSuccess(xml);
            },
            error: xmlError
        });
    }
    
    $("div.photogallery li.prev a").bind("click", function () {
        getImage("prev");
        return false;
    });
    
    $("div.photogallery li.next a").bind("click", function () {
        getImage("next");
        return false;
    });
    
    $("div.photogallery li.magnify a").bind("click", function () {
        enlargeImage();
        return false;
    });
    
    if($("ul.tabs a.on").parent("li").attr("class") == "videos") {
          setTimeout(function () {
               showVideo();
          }, "500");
    }
});