﻿$(document).ready(function () {
    imagess("#head_ad_big", "#big_ad", "#small_ad");
});

function replaceBig(smallId, bigId) {

    if (document.cookie.indexOf("shbus_big_ad") < 1) {
        var date = new Date();
        var expireDays = 1;
        date.setTime(date.getTime() + expireDays * 3600 * 1000);
        document.cookie = "shbus_big_ad=1; expire=" + date.toGMTString();
        $(smallId).hide("fast");
        $(bigId).show("slow");

        setTimeout('replaceSmall("' + smallId + '", "' + bigId + '");', 7000);
    }
}

function replaceSmall(smallId, bigId) {

    $(bigId).hide("fast");
    $(smallId).show("slow");
}

function imagess(bigImageId, bigId, smallId) {

    var url = $(bigImageId).attr("src");
    var img = new Image();
    img.src = url;

    if ($.browser.msie) {
        
        img.onreadystatechange = function () {
            
            if (img.readyState == "complete" || img.readyState == "loaded") {
                $(bigImageId).attr("src", img.src);

                //replaceBig(smallId, bigId);
            }
        }
        setTimeout('replaceBig("' + smallId + '", "' + bigId + '");', 3000);
    } else {
    img.onload = function () {
        //alert(img.complete);
        if (img.complete == true) {
            //alert($("#head_ad_img").attr("src"));
            $(bigImageId).attr("src", img.src);
            setTimeout('replaceBig("' + smallId + '", "' + bigId + '");', 3000);
        }
    }
    }
}

