var place_counter = 1;
function sendAnalyticsEvent(accnt){
    //console.log("Currently: "+s_prop16);
    if(window.location.hash.indexOf("#homepage_tab") != -1 && place_counter == 1) {
        var tab_tracking_value = window.location.hash.replace("#", '');
        s_prop16 = "lk_"+tab_tracking_value;
        try {
            s_coxnews.prop16 = s_prop16;
        }
        catch(e) {
            //Must be in G code
        }
    }
    else {
        //We blank s_prop16 which should only be passed on initial page load and not 2nd & subsequent
        s_prop16 = '';
        try {
            s_coxnews.prop16 = s_prop16;
        }
        catch(e) {
            //Must be in G code
        }
    }
    
    if(!accnt) {
        accnt=s_account;
    }
    
    //console.log("Sending: "+s_prop16);
    place_counter = place_counter + 1;
    
    try {
        void s_gs(accnt);
        dlog("s_gs("+accnt+")");
    }
    catch(e) {
        //Might be H code
        s_coxnews.t();
        dlog("s_coxnews.t();");
    }    
} 

function open_a_window(theurl) {
    if(window.opener) {
        window.opener.location = theurl;
        window.close();
        return false;
    }
    window.location = theurl;
    return true;
}

function dlog(message) {
    //logarea = document.getElementById("log");
    //logarea.innerHTML = logarea.innerHTML + message + "<br />";
    try {
        console.log(message);
    }
    catch(e) {
        //pass, because we don't have firebug
    }
}

function next_ad() {
    refresh_ad();
}
function refresh_ad() {
    try {
        sendAnalyticsEvent();
        dlog("sendAnalyticsEvent finished");
    }
    catch(e) { 
        dlog("Couldn't sendAnalyticsEvent "+e);
        //pass
    }
    
    try {
        parent.adcall.location.reload();
        dlog("parent.adcall.location.reload()");
    }
    catch(e) { 
        dlog("Couldn't parent.adcall.location.reload() "+e);
        //pass
    }
    
    try {
        parent.adcall_spon.location.reload();
        dlog("parent.adcall_spon.location.reload()");
    }
    catch(e) { 
        //pass
        dlog("Couldn't parent.adcall_spon.location.reload() "+e);
    }
}
function prev_ad() {
    refresh_ad();
}

function start_ad() {   
    var ad_container = document.getElementById("interstitial");
    ad_container.style.display="block";
    ad_container._timeout_id = window.setTimeout("start_show()", 7000);
}

function mid_ad() {
    document.getElementById("skip_start_ad").style.display = "none";
    document.getElementById("skip_mid_ad").style.display = "block";

    
    document.getElementById("footer").style.display = "none";
    hide_gallery();
    

    var old_ad_frame = document.getElementById("interstitial_ad_frame");
    //newloc = old_ad_frame.src.replace("tile=1", "tile=2");
    //old_ad_frame.src = newloc;

    var new_ad_frame = document.createElement("iframe");
    new_ad_frame.src = old_ad_frame.src.replace("tile=1", "tile=2");
    new_ad_frame.src = new_ad_frame.src.replace("photogallery=intro", "photogallery=middle");
    new_ad_frame.src = new_ad_frame.src.replace("sz=3x2", "sz=3x3");
    new_ad_frame.width = old_ad_frame.width;
    new_ad_frame.height = old_ad_frame.height;
    new_ad_frame.scrolling = old_ad_frame.scrolling;
    new_ad_frame.frameBorder = old_ad_frame.frameBorder;
    new_ad_frame.id = old_ad_frame.id.replace("interstitial_ad_frame", "middle_ad_frame");
    new_ad_frame.name = old_ad_frame.name.replace("interstitial_ad_frame", "middle_ad_frame");

    var ad_container = document.getElementById("interstitial");
    ad_container.style.display="block";


    var ad_frame_container = document.getElementById("interstitial_ad");
    ad_frame_container.innerHTML = '';
    //window.alert("Cleared i_ad");
    
    ad_frame_container.appendChild(new_ad_frame);
    //window.alert(new_ad_frame.id);


    ad_container._timeout_id = window.setTimeout("start_show()", 6000);
}

function start_show() {
    var start_ad_container = document.getElementById("interstitial");
    start_ad_container.style.display="none";
    
    document.getElementById("end_content").style.display = "none";
    
    window.clearTimeout(start_ad_container._timeout_id);
    
    document.getElementById("footer").style.display = "block";
    show_gallery();
}

function restart_show() {
    window.location.reload();
    //document.getElementById("gallery_content").style.display = "block";
    //document.getElementById("gallery_content").style.display = "none";
    //start_show();
    //document.getElementById("gallery_content").style.display = "block";
}

function end_show() {
    document.getElementById("gallery_content").style.display = "none";
    document.getElementById("footer").style.display = "none";
    
    document.getElementById("end_content").style.display = "block";
    
    var old_ad_frame = document.getElementById("middle_ad_frame");
    if(!old_ad_frame) {
        old_ad_frame = document.getElementById("interstitial_ad_frame");
    }

    var new_ad_frame = document.createElement("iframe");
    var src = old_ad_frame.src.replace("tile=2", "tile=3");
    src = src.replace("tile=1", "tile=3");
    src = src.replace("photogallery=middle", "photogallery=exit");
    src = src.replace("photogallery=intro", "photogallery=exit");
    src = src.replace("sz=3x2", "sz=3x4");
    src = src.replace("sz=3x3", "sz=3x4");
    
    new_ad_frame.src = src;
    new_ad_frame.width = old_ad_frame.width;
    new_ad_frame.height = old_ad_frame.height;
    new_ad_frame.scrolling = old_ad_frame.scrolling;
    new_ad_frame.frameBorder = old_ad_frame.frameBorder;
    new_ad_frame.id = "end_ad_frame";
    new_ad_frame.name = "end_ad_frame";
    
    var end_ad_container = document.getElementById("end_ad");
    end_ad_container.innerHTML = ''; //clear it out
    end_ad_container.appendChild(new_ad_frame); //add the add, can't just append it, because if you loop thru gallery several times it'll just pile up the ads.

}

function hide_gallery() {
    var area = document.getElementById("gallery_content")
    area.style.visibility = "hidden";
    area._height = area.style.height;
    area.style.height = "1px";
}

function show_gallery() {
    var area = document.getElementById("gallery_content")
    area.style.visibility = "visible";
    area.style.height = area._height;    
    area.style.display = "block";
}

function start_run() {
    document.getElementById("footer").style.display = "none";
    hide_gallery();
    document.getElementById("gallery_content").style.display = "none";
    start_ad();
}

function js_but_no_flash() {
    if(window.location.href.indexOf(".html")){
        return true;
    }
    return false
}