var http;
var articleRating = new Array ();

var starLabels = new Array ();


Effect.OpenUp = function(element,blah,eupdatetext) {
    element = $(element);
    new Effect.SlideDown(element, arguments[1] || { duration: .3 });
    if (eupdatetext) {
        eupdatetext.innerHTML = "Hide Menu";
    }
}
Effect.CloseDown = function(element,blah,eupdatetext) {
    element = $(element);
    new Effect.SlideUp(element, arguments[1] || { duration: .3 });
    if (eupdatetext) {
        eupdatetext.innerHTML = "Show Menu";
    }
}
Effect.Combo = function(element,blah,eupdatetext) {
    element = $(element);
    if (element.style.display == 'none') { 
         new Effect.OpenUp(element, arguments[1] || { duration: .3 }, false || eupdatetext); 
    }
    else { 
         new Effect.CloseDown(element, arguments[1] || { duration: .3 }, false || eupdatetext); 
    }
}



function roundCorners () {
    cCsettings = {
        tl: { radius: 10 },
        tr: { radius: 10 },
        bl: { radius: 10 },
        br: { radius: 10 },
        antiAlias: true,
        autoPad: true
    };
    $$(arguments[0] || 'div.roundedCorners').each(function(div) {
        var cornersObj = new curvyCorners(cCsettings, div);
        cornersObj.applyCornersToAll();
    });
}

/* hides stuff with js so that shit isn't hidden with js disabled and css enabled. */
function hideStuff () {
    $$('div.dynamicHideInit').each(function(div) {
        new Effect.CloseDown (div);
    });
}

/* if ajax is working then get rating widgets for any articles being displayed */
function setupRatingWidgets () {
    starLabels[1] = 'Bad';
    starLabels[2] = 'Ok';
    starLabels[3] = 'Average';
    starLabels[4] = 'Good';
    starLabels[5] = 'Awesome!';
    $$('div.ratingContainer').each(function(div) {
        a_id = div.id.split('-')[1];
        if (a_id) {
            asynchRequestGetArticleRatingWidget (a_id, 'get');
        }
    });
}


function startUpStuff () {
    //roundCorners ();
    hideStuff ();
    http = createRequestObject ();
    setupRatingWidgets ();
    initCookieCrumbMenus ();
    new FancyZoom('search');
}

/* Asynchronous stuffs... */

function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}


function asynchRequestGetArticleRatingWidget (a_id, ra, v) {
    ratingContainer = $('ratingContainerArticle-'+a_id);
    if (ratingContainer) {
        opt = {
                method:'post',
                asynchronous:true,
                postBody:'action='+(ra||'get')+'&a_id='+a_id+'&v='+v,
                
                onSuccess: function (r) {
                    if (r.readyState == 4) {
                        $('ratingContainerArticle-'+a_id).innerHTML = r.responseText;
                    }
                }
            }
        new Ajax.Request('/ratings/', opt);
    }
}

function rateArticle (a_id, s_val) {
    asynchRequestGetArticleRatingWidget (a_id, 'rate', s_val);
}
function starMouseOver (a_id, s_val, mouseout) {
    feedback = $('starFeedback-'+a_id);
    feedback.innerHTML = starLabels[s_val];
    for (i = 1; i <= 5; i++) {
        img = $('imgStar-'+a_id+'-'+i);
        
        if (img) {
                img.src = ((s_val >= i-0.75) && (s_val < i-0.25)) ? '/vis/star_halfactive.png' : ((s_val >= i-0.5) ? '/vis/star_active.png' : '/vis/star_inactive.png');
        }
    }
}
function starMouseOut (a_id, s_val) {
    starMouseOver (a_id, s_val, true);
    feedback = $('starFeedback-'+a_id);
    feedback.innerHTML = "";
}

/* Cookie crumb dropdown menus and things. A static trail is set by default, if JS is enabled then it gets "upgraded" once the page has loaded*/

function initCookieCrumbMenus () {
    
    return true;
}









