var AC_FL_RunContent = 0;

var button_standard = '<img alt="" src="http://cache.yappo.com/s1/images/button_standard_cap.png" class="button_standard customContentBG">';
var button_violet = '<img alt="" src="http://cache.yappo.com/s1/images/button_violet_cap.png" class="button_violet customContentBG">';
var button_orange = '<img alt="" src="http://cache.yappo.com/s1/images/button_orange_cap.png" class="button_orange customContentBG">';
var button_purple = '<img alt="" src="http://cache.yappo.com/s1/images/button_purple_cap.png" class="button_purple customContentBG">';
var button_blue = '<img alt="" src="http://cache.yappo.com/s1/images/button_blue_cap.png" class="button_blue customContentBG">';
var button_lightblue = '<img alt="" src="http://cache.yappo.com/s1/images/button_lightblue_cap.png" class="button_lightblue customContentBG">';
var button_navy = '<img alt="" src="http://cache.yappo.com/s1/images/button_navy_cap.png" class="button_navy customContentBG">';


$(document).ready(function() 
{
    if ($.browser.msie && $.browser.version < 7) 
    {
        $("span.button_standard").append(button_standard);
        $("span.button_violet").append(button_violet);
        $("span.button_orange").append(button_orange);
        $("span.button_purple").append(button_purple);
        $("span.button_blue").append(button_blue);
        $("span.button_lightblue").append(button_lightblue);
        $("span.button_navy").append(button_navy);

        if (or == "g") $("span.button_go").find("img").removeClass("customContentBG").addClass("customHeaderBG");
        else $("span.button_go").find("img").removeClass("customContentBG").addClass("button_go");

        $("span.review_bg").find("img").removeClass("customContentBG").addClass("review_bg");
        $("span.details_bg").find("img").removeClass("customContentBG").addClass("details_bg");
        $("span.details_bg_alt").find("img").removeClass("customContentBG").addClass("details_bg_alt");
        $("span.button_login").find("img").removeClass("customContentBG").addClass("button_login");
        $("span.button_bg_gray").find("img").removeClass("customContentBG").addClass("button_bg_gray");
        $("span.button_bg_lightgray").find("img").removeClass("customContentBG").addClass("button_bg_lightgray");
    }


    $(".popup").bind("mouseover", function(e) 
    {
        if ($("#searchCover").attr("src") !== undefined) 
        { 
            var source = $(this).attr("src").replace(/_thumb/, "_cover");

            $("#searchCover").attr("src", source);
            $("#searchCover").bind("load", function() 
            {
                $("#infobox_popup").show();
                confinedDisplay("infobox_popup", e);
            });
        }
        else 
        {
            id = $(this).attr("id");

            $("#infoCover").attr("src", info[id][4]);
            $("#infoTitle").text(info[id][0]);
            $("#infoSummary").text(info[id][5]);
            $("#infoStarring").text(info[id][1]);
            $("#infoLength").text(info[id][2]);
            $("#infoRelease").text(info[id][3]);
            $("#infobox_popup").show();
            confinedDisplay("infobox_popup", e);
        }
    })
    .mouseout(function() 
    {
        $("#infobox_popup").hide();

        if ( $("#searchCover").attr("src") !== undefined ) $("#searchCover").attr("src", "");
        else $("#infoCover").attr("src", "");
    });


    // CLONE THE NICHE AND STUDIO DROP DOWN MENUS FOR THE ADVANCED SEARCH SECTION //
    $("#niche_drop_down").clone().insertAfter("#adv_niche_drop_down").attr({onchange:"", name:"category"}).children("option:nth-child(2)").remove();
    $("#studio_drop_down").clone().insertAfter("#adv_studio_drop_down").attr({onchange:"", name:"producer"}).children("option:nth-child(2)").remove();


    // THE "GAY" LINK IN THE NICHE DROP-DOWN WILL REDIRECT THE USER TO GAYYAPPO
    $(":input[name='category_id']").change(
        function() { 
            if ( $(this).select().val() == 'gaylink') {
              document.location.href = BASE == 'adultglobalvodblah' 
                  ? "http://" + BASE + ".wl.yappo.com/index.php?nats=" + NATS
                  : "http://billing.gayyappo.com/strack/" + NATS + "/4/0/1/s1/index.php";
            }
        }
    );


    // TOGGLES THE VISIBILITY OF THE LANGUAGE DROP-DOWN
    $("div.language").click(
        function() { $(".language").toggle() }
    );


    // REVIEW SLIDE SHOW //
    var current = 0;
    $(".slide").hover(
        function() {
            if ($(this).attr("alt") == "forward") $(this).attr("src", "images/button_review_right-over.png");
            else $(this).attr("src", "images/button_review_left-over.png");
        },
        function() {
            if ($(this).attr("alt") == "forward") $(this).attr("src", "images/button_review_right.png");
            else $(this).attr("src", "images/button_review_left.png");
        }
    );

    $(".slide").click(
        function() { 
            if ($(this).attr("alt") == "forward") {
                if (current < screenshots.length - 1) current++;
            }
            else if (current > 0) current--;

            $("#screenshots").css("backgroundImage", "url(../dynamic_files/" + screenshots[current] + ")");
            $("#slidenumber").text(current + 1);
        }
    );



    $("span.hidereview").click(
        function() { 
            $("span.hidereview").toggle();
            $(this).parent().children("p").slideToggle("normal");
        }
    );


    /** EXPANDS AND CONTRACTS THE ANSWERS IN THE HELP SECTION **/
    $(".helpSection").toggle(
        function() {
            $(this).next("div").show();
            correctLength(1.5 * $(this).next("div").height());
        },
        function() {
            correctLength(-1.5 * $(this).next("div").height());
            $(this).next("div").hide();
        }
    );
});


/** PRELOAD IMAGES **/
if (document.images)
{
    var button_home      = new Image();
    button_home.src      = 'http://cache.yappo.com/s1/images/button_home-over.png';

    var button_tryUsFree = new Image();
    button_tryUsFree.src = 'http://cache.yappo.com/s1/images/button_tryUsFree-over.png';

    var button_movieCard = new Image();
    button_movieCard.src = 'http://cache.yappo.com/s1/images/button_movieCard-over.png';

    var button_buyTime   = new Image();
    button_buyTime.src   = 'http://cache.yappo.com/s1/images/button_buyTime-over.png';

    var button_help      = new Image();
    button_help.src      = 'http://cache.yappo.com/s1/images/button_help-over.png';

    var button_search    = new Image();
    button_search.src    = 'http://cache.yappo.com/s1/images/button-simpleSearch.png';
}



/** ADJUSTS THE HEIGHT OF THE LEFT-SIDE COLUMN **/
function correctLength(extraLength)
{
    var contentHeight = $("#content").height();
    $("#lside").height(extraLength + contentHeight);
    $("#lside").css("borderRight", "1px solid #47425A");
}



function searchToggle(changed, original) 
{
    $("#advancedsearch").slideToggle("medium");

    var type = $("#si").val() == "advanced" ? "tdc" : "advanced";
    $("#si").val(type);

    var text = $("span.searchtoggle").text() == original ? changed : original;
    $("span.searchtoggle").text(text);

    if ($.browser.msie && $.browser.version < 7) 
    {
        if (g == "s") $("span.searchtoggle").append(button_navy);
        else $("span.searchtoggle").append(button_purple);
    }
}



function go()
{
    if (document.dl) window.location.href = document.dl.ticket.value;
    return true;
}


function newImage(arg)
{
    if (document.images)
    {
        rslt = new Image();
        rslt.src = arg;
        return rslt;
    }
    else return false;
}


function changeImage(image_id)
{
    document.getElementById(image_id).src = "images/" + image_id + "-over.png";
    return false;
}


function returnImage(image_id)
{
    document.getElementById(image_id).src = "images/" + image_id + ".png";
    return false;
}


function changeMovieCover(image_id)
{
    if (document.images) document.getElementById('movieCover').src = image_id;
    return false;
}


function returnMovieCover(image_id)
{
    document.getElementById('movieCover').src = image_id;
    return false;
}


function init()
{
    // Increases all sections to the height of the tallest section //

    var rside = (document.getElementById('rside')) ? document.getElementById('rside').offsetHeight : 0;
    var lside = (document.getElementById('lside')) ? document.getElementById('lside').offsetHeight : 0;
    var main  = document.getElementById('main').offsetHeight; 
    var temp  = (rside > lside) ? rside : lside;
    var max   = (main  > temp)  ? main  : temp;

    if (lside != 0) 
    {
        document.getElementById('lside').style.height       = max + 'px';
        document.getElementById('lside').style.offsetHeight = max + 'px';
    }

    document.getElementById('main').style.height       = max + 'px';
    document.getElementById('main').style.offsetHeight = max + 'px';

    if (rside != 0) 
    {
        document.getElementById('rside').style.height       = max + 'px';
        document.getElementById('rside').style.offsetHeight = max + 'px'; 
    }

    //alert('lside: ' + lside + ', main: ' + main + ', rside: ' + rside + "\n\n" + 'Current lside: ' + document.getElementById('lside').style.offsetHeight + "\n" + 'Current main: '  + document.getElementById('main').style.offsetHeight + "\n");
}


function CreateBookmarkLink(title, url)
{
    // Firefox
    if (window.sidebar) window.sidebar.addPanel(title, url, "");

    // Internet Explorer
    else if (window.external) window.external.AddFavorite(url, title);

    // Opera
    else if (window.opera && window.print) return true;

    else
    {
        alert("Oops, your browser doesn't support this feature.\n" +
              "If you are using Netscape Navigator, click 'Bookmarks'\n" +
              "and then 'Add Bookmark' to add this site to your favorites.");
    }
}


function handleKeyPress(e, name)
{
    var formName = name;

    if (!e) e = window.event;

    if (e && e.keyCode == 13)
    {
        document.forms[formName].submit();
        return false;
    }

    return true;
}


function showElement(element)
{
    document.getElementById(element).style.display = 
        (document.getElementById(element).style.display == "none") ? "block" : "none";
}


function threeMinutesLeft(time)
{
    chance = getCookie('chance');

    if (chance != 1 && time <= 3)
    {
        setCookie('chance', 1, 9999);
        var timeleft = (time == 1) ? '1 minute' : time + ' minutes'
        var r = confirm('You only have ' + timeleft + ' left...\nClick "OK" to save $5 on our most popular 120 minute package.\n\nThis is a ONE TIME offer!');
        if (r === true) window.location.href="?r=chance";
    }
}


function setCookie(cookie_name, value, expiredays)
{
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);

    document.cookie = cookie_name + "="  + escape(value) + 
       ( (expiredays == null) ? "" : ";expires=" + exdate.toGMTString() );
}


function getCookie(cookie_name)
{
    if (document.cookie.length > 0)
    {
        start = document.cookie.indexOf(cookie_name + "=")
        if (start != -1)
        { 
            start = start + cookie_name.length + 1;
            end = document.cookie.indexOf(";", start);
            if (end == -1) end = document.cookie.length;

            return unescape(document.cookie.substring(start, end))
        } 
    }
    return "";
}
//this is pretty much the same code, but I do need the path and domain
function Set_Cookie( name, value, expires) {
var today = new Date();
today.setDate(today.getDate()+expires) ;
document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + today.toGMTString() : "" ) +
";path=/";
}

