var maxAds = myAds.length;
var currAd = 0;

function prepAdUpdate() {
   jQuery(".ad").each( function(i) {
      //$.get("getAd.php", function(data){ jQuery(".ad:eq("+i+")").html(data); });
      data = myAds[Math.round(Math.random() * myAds.length)];
      jQuery(".ad:eq("+i+")").html(data);
      var intervalID = setInterval("updateAds("+i+")","1"+Math.round(Math.random()*10)+"000");
      jQuery(this).data("intID", intervalID);
   });
}

function slideAdsSide(i,data) {
   var prevWidth = jQuery(".ad:eq("+i+")").width();
   jQuery(".ad:eq("+i+")").animate({width:"-15", opacity: 'hide'}, 1500, function() {
       jQuery(this).html(data);
	   jQuery(this).css("width", prevWidth);
	   jQuery(this).animate({opacity: 'show'}, 1500);
   });
}

function slideAdsUp(i,data) {
   jQuery(".ad:eq("+i+")").slideUp("slow", function() {
      jQuery(this).html(data);
	  jQuery(this).slideDown("slow");
   });
}

function fadeAds(i,data) {
   jQuery(".ad:eq("+i+")").fadeOut("slow", function() {
      jQuery(this).html(data);
	  jQuery(this).fadeIn("slow");
   });
}

function zoomAds(i,data) {
   jQuery(".ad:eq("+i+") .title").animate({fontSize: "50px", opacity: 'hide'}, 1500, function() {
    	try {
		jQuery(".ad:eq("+i+")").hide()
			.html(data)
			.show(1500);
		} catch(e) { return; }
   });
}



function updateAds(i) {
	currAd = (currAd + 1) % (maxAds+1);
	data = myAds[currAd];
    switch(Math.round(Math.random()*10)){ 
        case 1: case 2: case 3: fadeAds(i,data); break;
        case 4: case 5: case 6: slideAdsUp(i,data); break;
        case 7: case 8: default: slideAdsSide(i,data); break;
        case 9: case 0: zoomAds(i,data); break;
    }
}

jQuery(document).ready(function() { 
    prepAdUpdate();
    jQuery(".ad").mouseover(function() { clearInterval(jQuery(this).data("intID")); });

    jQuery(".ad").mouseout(function() {
        jQuery(this).data("intID", setInterval("updateAds("+jQuery(".ad").index(this)+")","1"+Math.round(Math.random()*10)+"000"));
    });
});