
function showcomments(contentId,isGirls)
{
    $("adunit_1").style.display = "none";
    $("commentblock").style.display = "block";
    refreshComments(currentCommentPage,contentId, isGirls);    
}


function refreshComments(page,contentId, isGirls) 
{
    currentContentId = contentId;
    var ajUpdateComments = new Ajax.Updater('commentblock', 'viewcomments.castle', {parameters:'content.id='+contentId+'&currentPage='+page+'&isGirls='+isGirls.toString(), onComplete:function(request) { showSuccessComments() }, asynchronous:true, evalScripts:true});
}

function showSuccessComments()
{
    if (registration_data != null && registration_data.error != null) {
        $('errortext').innerHTML = "<strong><span class='errormsg'>"+ registration_data.error + "</span></strong>";
        $('showeditcomment').style.display = 'block';
    }

    var lbox = $$('div#commentblock .lbOn');
	for(i = 0; i < lbox.length; i++) {
		valid = new lightbox(lbox[i]);
	}
}

function addComment(contentId)
{
}

function commentSubmitted(request)
{
    eval("registration_data = " + request.responseText + ";");
    if (registration_data.setcookiescript != null) {
        eval(registration_data.setcookiescript);
    }
    currentCommentPage = 1;
    $('pop_comment_count').innerHTML = "<strong>" + registration_data.ActiveCommentList + " COMMENTS</strong>";
    refreshComments(currentCommentPage,currentContentId);
    
}

function refreshnewsblogbutton()
{
    if (MODE == "BLOG") {
        $("newsblog").innerHTML = "Lose The Rush";
        $("newsblog").onclick = function () { updatePage(BLOG_PAGE,CURRENT_PAGE,'NORMAL');return false; };
    } else {
        $("newsblog").innerHTML = "Add The Rush";
        $("newsblog").onclick = function () { updatePage(BLOG_PAGE,CURRENT_PAGE,'BLOG');return false; };
    }
}

function showSuccessMessage()
{
    if (lastUpdate != '') {
        $('lastupdate').innerHTML = lastUpdate;
    }

    refreshnewsblogbutton();
    
    if (typeof(gLastUpdate) != 'undefined' && gLastUpdate + '' != '')
    {
        $('lastupdate').innerHTML = gLastUpdate;
    }
    var lbox = $$('div#results .lbOn');
	for(i = 0; i < lbox.length; i++) {
		valid = new lightbox(lbox[i]);
	}
}
function searchsubmit()
{
    CURRENT_KEYWORD = $("txtkeyword").value;
    CURRENT_PAGE = 1;
    BLOG_PAGE = 1;
    refreshcontent(BLOG_PAGE, "1,1,1,1,1,1,1,1,1,1,1,1",CURRENT_PAGE,CURRENT_KEYWORD,MODE, MOOD,null);
}



function pipes_update(p1,girls,sports,p4,p5,p6,p7,
                        p8,p9,p10,p11,p12,main_switch)
{
    args = getArgs();
    qs = args["usercustom"];
    categoryid = args["categoryid"];
    if (typeof(categoryid) == "undefined") {
        categoryid = null;
    }
    if (typeof(qs) == "undefined") {
        qs = "0,0,0,0,0,0,0,0,0,0,0,0";
    }
    // alert(main_switch);
    var uc_qs = qs.split(",");
    var uc_new = [p1 ? 1 : 0,girls ? 1 : 0,sports ? 1 : 0,p4 ? 1 : 0,p5 ? 1 : 0,p6 ? 1 : 0,p7 ? 1 : 0,p8 ? 1 : 0,p9 ? 1 : 0,p10 ? 1 : 0,p11 ? 1 : 0,p12 ? 1 : 0];
    var new_qs = uc_new.join(",");
    CURRENT_PIPES = new_qs;
    CURRENT_KEYWORD = "";
    CURRENT_PAGE  = 1;
    BLOG_PAGE = 1;
    if (new_qs == "0,0,0,0,0,0,0,0,0,0,0,0")
    {
        if (typeof(MODE) == "undefined" || MODE == "NORMAL")
        {
            MODE = "HELP";
        }
    }
    $("txtkeyword").value = "";
    refreshcontent(BLOG_PAGE, new_qs,CURRENT_PAGE,CURRENT_KEYWORD,MODE, MOOD,categoryid);
}

function slider_update(slideid,newposition) 
{
    // alert (slideid + ' ' + newposition);
    if (slideid == "'seriousId'") {
        MOOD = newposition;
        updatePage(BLOG_PAGE, CURRENT_PAGE,MODE,MOOD);
    }
}

function turnPage(curPage)
{
    return updatePage(BLOG_PAGE,curPage,MODE,MOOD)
}
 function updatePage(curBlogPage,curPage,mode, mood)
 {
    if (typeof(mode) != "undefined" && mode != null && mode != MODE) {
            MODE = mode;
    }
    if (curPage == -1) 
    {
        CURRENT_PAGE = (CURRENT_PAGE > 1) ? CURRENT_PAGE - 1 : 1;
        curPage = CURRENT_PAGE;
    }
    if (curPage == null) {
        CURRENT_PAGE++;
        curPage = CURRENT_PAGE;
    }
    CURRENT_PAGE = curPage;
    BLOG_PAGE = curBlogPage;
    
    refreshcontent(BLOG_PAGE,CURRENT_PIPES,curPage,CURRENT_KEYWORD,MODE, MOOD,null);
    return false;
 }

function refreshcontent(blog, pipes,page,keyword,mode, mood, categoryid) 
{
    if (typeof(pageTracker) == 'undefined' || pageTracker == null) {
        pageTracker = _gat._getTracker("UA-5026831-2");
        pageTracker._initData();
    }
    if (keyword + "" != "") {
        pageTracker._trackPageview("/mainpage/" + pipes + "/" + page + "/" + escape(keyword));
    } else {
        sMood = (mood == 0 || mood == 3)  ? "" : "/mood/"+ mood;
        if (mode == "NORMAL") {
            pageTracker._trackPageview("/mainpage/" + pipes + "/" + page + sMood);
        } 
        else {
            pageTracker._trackPageview("/mainpage/" + escape(mode) + sMood);
        }
    }
    if (categoryid != null) {
        scategoryid = "&categoryid=" + categoryid;
    } else 
        scategoryid = "";

    sparam = 'blogPage='+blog+'&usercustom='+pipes+scategoryid+'&currentPage='+page+'&keyword='+keyword+"&mode="+mode+'&mood='+mood;
    // alert(sparam);
        
    var ajUpdate = new Ajax.Updater('results', 'viewresults.castle', {parameters:sparam, onComplete:function(request) { showSuccessMessage() } , asynchronous:true, evalScripts:true});
}

function clickticker(surl,short)
{
    var anchor = $("clickerticker");
    anchor.href = surl;
    if (typeof(pageTracker) == 'undefined' || pageTracker == null) {
        pageTracker = _gat._getTracker("UA-5026831-2");
        pageTracker._initData();
    }
    pageTracker._trackPageview(short);

    var lb = new lightbox(anchor);
    try { lb.deactivate();
    } catch (ex) {
    }
    lb.activate();
}

function MoveUp()
{
    new Effect.MoveBy('imageboxInside', -321, 0 , {duration: 0.4,  transition: Effect.Transitions.sinoidal});
}

function MoveDown()
{
    new Effect.MoveBy('imageboxInside', 321, 0 , {duration: 0.4,  transition: Effect.Transitions.sinoidal});
}

