﻿$(document).ready(function() {
	//$("#content").wrap("<div id='liquid-content'></div>");

	$(".tab_content object").remove();
    $(".tab_content embet").remove();

    $("li.widget").addClass("sbbox");
    var post = $(".post");
	post.prepend("<div class='post-top'><span><!-- --></span><samp><!-- --></samp></div>");
    post.append("<div class='post-bottom'><span><!-- --></span><samp><!--  --></samp></div>");

	//post.wrap("<div class='post-wrapper'></div>");
	$(".sbbox").append("<span class='sidebar-item-bottom'><!-- --></span>");
	$(".tabs li:first-child").addClass("active");


	var ab = $(".slidethis");
	for(var a=0; a<ab.length; a++){
    	ab[a].innerHTML = a+1;
	}
	var adsense = $(".post-adsense");
	for(var as=0; as<adsense.length; as++){
		var ad_html = adsense[as].innerHTML.length;
       	if(ad_html<1){adsense[as].style.display="none";}
	}
	$("li.page-item-74 a").attr("href", "http://www.watchevolution.com/category/video-gallery");
    $(".videogallery a").attr("href", "http://www.watchevolution.com/category/video-gallery");

$("#ngg_galery_related_images").wrap("<div id='ngg_galery_related_images_wrapper'></div>");	

//preload images
img1= new Image();
img1.src="http://www.watchevolution.com/wp-content/themes/WatchEvolution/images/sidebar_star.jpg";
img2= new Image();
img2.src="http://www.watchevolution.com/wp-content/themes/WatchEvolution/images/navright.jpg";
img3= new Image();
img3.src="http://www.watchevolution.com/wp-content/themes/WatchEvolution/images/navleft.jpg";


    var post_img = $('.post .post-image img');
    if(post_img[0]){
  		for (var i = 0; i<post_img.length; i++){
              post_img[i].onload = function(){
               	if(this.offsetWidth>250){
      				this.style.width = '250';
      			}
        	}
  		}
  	}
                      //arthur@watchmedic.com
	//add forum link
	//$("#nav li:nth-child(3)").after("<li><a href='http://www.watchevolution.com/forum'>Forum</a></li>")

	$(".linklove").remove();
	//$(".post-top + h2").remove();
});



// the tabs

$.tabs = function(containerId, start) {
    var ON_CLASS = 'active';
    var id = '#' + containerId;
    var i = (typeof start == "number") ? start - 1 : 0;
    $(id + '>div:lt(' + i + ')').add(id + '>div:gt(' + i + ')').hide();
    $(id + '>ul>li:nth-child(' + i + ')').addClass(ON_CLASS);
    $(id + '>ul>li>a').click(function() {
        if (!$(this.parentNode).is('.' + ON_CLASS)) {
            var re = /([_\-\w]+$)/i;
            var target = $('#' + re.exec(this.href)[1]);
            if (target.size() > 0) {
                $(id + '>div:visible').animate({opacity:'hide'}, function(){target.animate({opacity:'show'});});
                $(id + '>ul>li').removeClass(ON_CLASS);
                $(this.parentNode).addClass(ON_CLASS);
            } else {
                //
            }
        }
        return false;
    });
};



function rotateImages ( ){
		var items = $(".tabs li a");
		ilength = items.length;
		var to_click_on = false;
		jQuery.each(items, function(i) {
			var j = i+1;
			var click_on = j+1;
			 if ( $(this).parent().hasClass("active") ){
	       		   var to_click_on = click_on;
				   if(to_click_on >= ilength + 1){
					to_click_on = 1;
				   }
				   $(".tabs li:nth-child("+to_click_on +") a").click();
				   return false;
			 } else {

			 }
	    });
}

setInterval ("rotateImages()", 12000);