var timerlen = 5;
var slideAniLen = 250;

//var TILE_ID = 211

var timerID = new Array();
var startTime = new Array();
var obj = new Array();
var endHeight = new Array();
var moving = new Array();
var dir = new Array();

var mousedover = false;

//// START PREVIEW OPEN ///////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

$(document).ready(function() {
	window.preview('ad2');
});

function preview(objname){
	if(moving[objname])
		return;
	previewdown(objname);  /// uncomment this line as well as the next in order for the ad to expand open on page load and then retract after set time. ////
    setTimeout("previewup('"+objname+"')", 6000);  //// uncomment the line to the left and adjust the time that the add is expanded on page load. ////

//// START - SET COOKIE FOR PREVIEW FUNCTION //////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	var cookie = getcookie("sbb");
//alert(cookie);
if(cookie)
 {
  document.getElementById(objname).style.display = 'none'; 
 }
 else
 {
  document.getElementById(objname).style.display = 'block';
  var today = new Date();
  var expire = new Date();
  expire.setTime(today.getTime() + 600000);  // currently set for 10 minutes. 600000 milliseconds = 10min.
  document.cookie = "sbb=1;expires="+expire.toGMTString();
}
function getcookie(cookiename) {
var cookiestring=""+document.cookie;
var index1=cookiestring.indexOf(cookiename);
if (index1==-1 || cookiename=="") return ""; 
var index2=cookiestring.indexOf(';',index1);
if (index2==-1) index2=cookiestring.length; 
return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
	}

//// END - SET COOKIE FOR PREVIEW FUNCTION //////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
}

function previewdown(objname){
        if(moving[objname])
                return;

        if(document.getElementById(objname).style.display != "none")
                return; // cannot slide down something that is already visible

        moving[objname] = true;
        dir[objname] = "down";
        startslide(objname);
}

function previewup(objname){
        if(moving[objname])
                return;

        if(document.getElementById(objname).style.display == "none")
                return; // cannot slide up something that is already hidden

        moving[objname] = true;
        dir[objname] = "up";
        startslide(objname);
}

//// END PREVIEW OPEN ///////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function slidedown(objname){
        if(moving[objname])
                return;

        if(document.getElementById(objname).style.display != "none")
                return; // cannot slide down something that is already visible

        moving[objname] = true;
        dir[objname] = "down";
        startslide(objname);
        
if (!mousedover) {
mousedover = true;
var img = new Image();
//img.src = "http://localhost/add_mouseover_counter.php?tileID=" + TILE_ID;
	}
}

function slideup(objname){
        if(moving[objname])
                return;

        if(document.getElementById(objname).style.display == "none")
                return; // cannot slide up something that is already hidden

        moving[objname] = true;
        dir[objname] = "up";
        startslide(objname);
}

function startslide(objname){
        obj[objname] = document.getElementById(objname);

        endHeight[objname] = parseInt(obj[objname].style.height);
        startTime[objname] = (new Date()).getTime();

        if(dir[objname] == "down"){
                obj[objname].style.height = "1px";
        }

        obj[objname].style.display = "block";

        timerID[objname] = setInterval('slidetick(\'' + objname + '\');',timerlen);
}

function slidetick(objname){
        var elapsed = (new Date()).getTime() - startTime[objname];

        if (elapsed > slideAniLen)
                endSlide(objname)
        else {
                var d =Math.round(elapsed / slideAniLen * endHeight[objname]);
                if(dir[objname] == "up")
                        d = endHeight[objname] - d;

                obj[objname].style.height = d + "px";
        }

        return;
}

function endSlide(objname){
        clearInterval(timerID[objname]);

        if(dir[objname] == "up")
                obj[objname].style.display = "none";

        obj[objname].style.height = endHeight[objname] + "px";

        delete(moving[objname]);
        delete(timerID[objname]);
        delete(startTime[objname]);
        delete(endHeight[objname]);
        delete(obj[objname]);
        delete(dir[objname]);

        return;
}


var expandingAd = new Object();

//** Below input the Tile Id number, and for the ad_rollover_counter also change the Tile ID number to match ad_url
expandingAd.filesdir = "http://bdtvideo.com/pencilads/ads/"; // your website folder where you files are will go here....
// Small SWF size
expandingAd.smallwidth = 1000;
expandingAd.smallheight = 45;
expandingAd.smallid =  "billboard_1000x45";
// Large SWF size
expandingAd.largewidth = 1000;
expandingAd.largeheight = 300;
expandingAd.largeid = "billboard_1000x300";

expandingAd.expandableAdUrl = escape('http://livingshield.com');
//expandingAd.expandableAdUrl = escape('http://localhost/adv_tile_redirect.php?tileID=' +TILE_ID + '&adurl=http://livingshield.com');
expandingAd.big_params_2 = '&expandable_ad_url=' + expandingAd.expandableAdUrl;

expandingAd.putObjects = function () {
	document.write('<div style="width:1000px; height:45px; padding:0;">');
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
    document.write(' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" ');
    document.write(' width="'+ expandingAd.smallwidth +'" height="'+ expandingAd.smallheight +'" id="'+ expandingAd.smallid +'">');
    document.write(' <param name="allowScriptAccess" value="always"/> ');
    document.write(' <param name="allowFullScreen" value="false" /> ');
    document.write(' <param name="wmode" value="transparent"/>');
    document.write(' <param name="movie" value="'+ expandingAd.filesdir + expandingAd.smallid +'.swf?'+ expandingAd.big_params_2 +' "/>');
    document.write(' <param name="quality" value="high" /> ');
    document.write(' <param name="FlashVars" value="'+ expandingAd.big_params_2 +'"/>');
    document.write('<embed src="'+ expandingAd.filesdir + expandingAd.smallid +'.swf?' + expandingAd.big_params_2 +'" flashvars="'+ expandingAd.big_params_2 +'" width="'+ expandingAd.smallwidth +'" height="'+ expandingAd.smallheight +'" name="'+ expandingAd.smallid +'" ');
    document.write(' quality="high" allowscriptaccess="always" wmode="transparent" allowFullScreen="false" swliveconnect="true" type="application/x-shockwave-flash" ');
    document.write(' pluginspage="http://www.macromedia.com/go/getflashplayer" /></object> ');
	document.write(' </div> ');
	//****** Next DIV ******//
	
	document.write(' <div id="ad2" style="position:relative; width:1000px; height:300px; display:none; overflow:hidden;">');
	document.write(' <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ');
    document.write(' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" ');
    document.write(' width="'+ expandingAd.largewidth +'" height="'+ expandingAd.largeheight +'" id="'+ expandingAd.largeid +'"> ');
    document.write(' <param name="allowScriptAccess" value="always"/> ');
    document.write(' <param name="allowFullScreen" value="false" /> ');
    document.write(' <param name="wmode" value="transparent"/> ');
    document.write(' <param name="movie" value="'+ expandingAd.filesdir + expandingAd.largeid +'.swf?'+ expandingAd.big_params_2 +' "/> ');
    document.write(' <param name="quality" value="high" /> ');
    document.write(' <param name="FlashVars" value="'+ expandingAd.big_params_2 +'"/> ');
    document.write('<embed src="'+ expandingAd.filesdir + expandingAd.largeid +'.swf?' + expandingAd.big_params_2 +'" flashvars="'+ expandingAd.big_params_2 +'" width="'+ expandingAd.largewidth +'" height="'+ expandingAd.largeheight +'" name="'+ expandingAd.largeid +'" ');
    document.write(' quality="high" allowscriptaccess="always" wmode="transparent" allowFullScreen="false" swliveconnect="true" type="application/x-shockwave-flash" ');
    document.write(' pluginspage="http://www.macromedia.com/go/getflashplayer" /></object> ');
	
    document.write(' </div> ');
}
expandingAd.putObjects();
