// init hover comments link
$(document).ready(function(){
	$("div.btn-comments a").mouseover(function(i){
	  $(this).children('strong').css("text-decoration", "none");
	});
	$("div.btn-comments a").mouseout(function(i){
	  $(this).children('strong').css("text-decoration", "underline");
	});
});

$(document).ready(function(){
	$("div.article div.title").each( function(i){
	  	if( $(this).height() > 90){
				$(this ).children('.author').css("padding-top", $(this).height()-80);
			}
	  });
});
// sharethis replase text
$(document).ready(function(){

	$(".stbuttontext").text("SHARE THIS ARTICLE");
	
  $(".stbuttontext").mouseover(function(i){
	  $(this).css("text-decoration", "none");
	  $(this).addClass("stbuttontext-hover");
	});
	$(".stbuttontext").mouseout(function(i){
	  $(this).css("text-decoration", "underline");
	  $(this).removeClass("stbuttontext-hover");
	});
});
// init search form
$(document).ready(function(){
	if(!document.getElementById("subscribe")) return;

	$("input").each( function(i){
  	if( $(this).attr("type") == "text" && $(this).attr("alt") != ""){
			var parts = String($(this).attr("alt")).split(':');
			$(this).attr('default_value', jQuery.trim(parts[1]));
			$(this).focus( function(e){
				if(jQuery.trim($(this).val().toLowerCase()) == jQuery.trim($(this).attr('default_value').toLowerCase())){
					$(this).val('');
				}
			});
			$(this).blur( function(e){
				if(this.value == ''){
					$(this).val($(this).attr('default_value'));
				}
			});
		}
	});
	
});

// init send form
$(document).ready(function(){
	if(!document.getElementById("enquiry_form")) return;

	$("input").each( function(i){
  	if( $(this).attr("type") == "text" && $(this).attr("alt") != ""){
			var parts = String($(this).attr("alt")).split(':');
			$(this).attr('default_value', jQuery.trim(parts[1]));
			$(this).focus( function(e){
				if(jQuery.trim($(this).val().toLowerCase()) == jQuery.trim($(this).attr('default_value').toLowerCase())){
					$(this).val('');
				}
			});
			$(this).blur( function(e){
				if(this.value == ''){
					$(this).val($(this).attr('default_value'));
				}
			});
		}
	});

});

//init category expands
var isCategoryExpand = true;

$(document).ready(function(){

	if(!document.getElementById("categories_button")) return;
  var cat_height;
	$("#categories_button").click(function(i){
		if( isCategoryExpand ) {
//	    $(".categories-body .bottom-shadow").slideUp(1000);
      cat_height = $(".categories-body .bottom-shadow .green").height();
      $(".categories-body .bottom-shadow .green").animate({"height":"2px"}, 1000, null);
	    $("#categories_button").removeClass("open");
	    $("#categories_button").addClass("close");
//	    $("#category-title").addClass("minimal");
	    isCategoryExpand = false;
		  return false;
		}
		else{
//		  $(".categories-body .bottom-shadow").slideDown( 1000 );
			$(".categories-body .bottom-shadow .green").animate({"height":cat_height}, 1000, null);
		  $("#categories_button").removeClass("close");
	    $("#categories_button").addClass("open");
//			$("#category-title").removeClass("minimal");
		  isCategoryExpand = true;
		  return false;
		};
	});
});

//init posts expands
var isPostExpand = true;

$(document).ready(function(){

	if(!document.getElementById("posts_button")) return;
  var post_height;
	$("#posts_button").click(function(i){
		if( isPostExpand ) {
//	    $(".posts-body").slideUp(1000);
			post_height = $(".recent-block").height();
			if (active_tab=="recent"){
        $(".recent-block").animate({"height":"5px"}, 1000, null);
        $(".popular-block").css("height","5px");
			}
			else{
			  $(".popular-block").animate({"height":"5px"}, 1000, null);
			  $(".recent-block").css("height","5px");
			}
	    $("#posts_button").removeClass("open");
	    $("#posts_button").addClass("close");
//	    $("#recent_popular").addClass("minimal");
	    isPostExpand = false;
		  return false;
		}
		else{
//			$(".posts-body").slideDown(1000);
      if (active_tab=="recent"){
        $(".recent-block").animate({"height":post_height}, 1000, null);
        $(".popular-block").css("height",post_height);
			}
			else{
			  $(".popular-block").animate({"height":post_height}, 1000, null);
			  $(".recent-block").css("height",post_height);
			}
		  $("#posts_button").removeClass("close");
	    $("#posts_button").addClass("open");
//	    $("#recent_popular").removeClass("minimal");
		  isPostExpand = true;
		  return false;
		};
	});
});

//init archive & calendar expands
var isArchiveExpand = true;

$(document).ready(function(){

	if(!document.getElementById("archive_button")) return;
	var calendar_height;
	$("#archive_button").click(function(i){
		if( isArchiveExpand ) {
		  calendar_height = $(".calendar-block").height();
		  if (active_tab_1=="calendar"){
        $(".calendar-block").animate({"height":"1px"}, 1000, null);
        $(".archive-block").css("height", "11px");
			}
			else{
			  $(".archive-block").animate({"height":"11px"}, 1000, null);
			  $(".calendar-block").css("height", "1px");
			}
//	    $(".archive-body").slideUp(1000);
	    $("#archive_button").removeClass("open");
	    $("#archive_button").addClass("close");
//	    $("#calendar_archive").addClass("minimal");
	    isArchiveExpand = false;
		  return false;
		}
		else{
//		  $(".archive-body").slideDown(1000);
      if (active_tab_1=="calendar"){
        $(".calendar-block").animate({"height":calendar_height}, 1000, null);
        $(".archive-block").css("height", calendar_height);
			}
			else{
			  $(".archive-block").animate({"height":calendar_height}, 1000, null);
			  $(".calendar-block").css("height", calendar_height);
			}
		  $("#archive_button").removeClass("close");
	    $("#archive_button").addClass("open");
//	    $("#calendar_archive").removeClass("minimal");
		  isArchiveExpand = true;
		  return false;
		};
	});
});

//init links & blogroll expand
var isLinkaExpand = true;

$(document).ready(function(){

	if(!document.getElementById("links_button")) return;
	var link_height;
	$("#links_button").click(function(i){
		if( isLinkaExpand ) {
		  if (active_tab_2=="links"){
        $(".links-block").animate({"height":"5px"}, 1000, null);
        $(".blogroll-block").css("height","5px");
			}
			else{
			  $(".blogroll-block").animate({"height":"5px"}, 1000, null);
        $(".links-block").css("height","5px");
			}
		  if ( $(".links-block").height() >= $(".blogroll-block").height() )
		    link_height = $(".links-block").height();
			else
		    link_height = $(".blogroll-block").height();

	//	    $(".links-body").slideUp(1000);
	    link_height = 200;
	    $("#links_button").removeClass("open");
	    $("#links_button").addClass("close");
//	    $("#links_blogroll").addClass("minimal");
	    isLinkaExpand = false;
		  return false;
		}
		else{
//		  $(".links-body").slideDown(1000);
		  if (active_tab_2=="links"){
        $(".links-block").animate({"height":link_height}, 1000, null);
        $(".blogroll-block").css("height",link_height);
			}
			else{
			  $(".blogroll-block").animate({"height":link_height}, 1000, null);
        $(".links-block").css("height",link_height);
			}
		  $("#links_button").removeClass("close");
	    $("#links_button").addClass("open");
//	    $("#links_blogroll").removeClass("minimal");
		  isLinkaExpand = true;
		  return false;
		};
	});
});

//init banners expands
var isBannerExpand = true;

$(document).ready(function(){

	if(!document.getElementById("banner_button")) return;
	var banners_height;
	$("#banner_button").click(function(i){
		if( isBannerExpand ) {
		  banners_height = $(".hor-banners").height();
		  $(".hor-banners").animate({"height":"5px"}, 1000, null);
//	    $(".banners-block").slideUp(1000);
	    $("#banner_button").removeClass("open");
	    $("#banner_button").addClass("close");
//	    $("#visit_block").addClass("minimal");
	    isBannerExpand = false;
		  return false;
		}
		else{
//		  $(".banners-block").slideDown(1000);
      $(".hor-banners").animate({"height":banners_height}, 1000, null );
		  $("#banner_button").removeClass("close");
	    $("#banner_button").addClass("open");
//	    $("#visit_block").removeClass("minimal");
		  isBannerExpand = true;
		  return false;
		};
	});
});

//init enquiry form expands
var isEnquryExpand = true;

$(document).ready(function(){

	if(!document.getElementById("enqury_button")) return;
	var enquiry_height;

	$("#enqury_button").click(function(i){

		if( isEnquryExpand ) {
			$(".enquiy").animate({"height":"15px"}, 1000, null);
	    $("#enqury_button").removeClass("open");
	    $("#enqury_button").addClass("close");
	    isEnquryExpand = false;
		  return false;
		}
		else{
      $(".enquiy").animate({"height":"320px"}, 1000, null);
		  $("#enqury_button").removeClass("close");
	    $("#enqury_button").addClass("open");
		  isEnquryExpand = true;
		  return false;
		};
	});
});

//init online form expands
var isOnlineExpand = true;

$(document).ready(function(){

	if(!document.getElementById("online_button")) return;
	var online_height;
	online_height = $(".online-block").height();
	$("#online_button").click(function(i){
		if( isOnlineExpand ) {
		  if (active_tab_3=="online"){
        $(".online-block").animate({"height":"5px"}, 1000, null);
        $(".yourblog-block").css("height","5px");
			}
			else{
			  $(".yourblog-block").animate({"height":"5px"}, 1000, null);
        $(".links-block").css("height","5px");
			}
			$("online-block").animate({"height":"5px"}, 1000, null);
//	    $(".online-body").slideUp(1000);
	    $("#online_button").removeClass("open");
	    $("#online_button").addClass("close");
//	    $("#online_yourblog").addClass("minimal");
	    isOnlineExpand	 = false;
		  return false;
		}
		else{
		  if (active_tab_3=="online"){
        $(".online-block").animate({"height":online_height}, 1000, null);
        $(".yourblog-block").css("height",online_height);
			}
			else{
			  $(".yourblog-block").animate({"height":online_height}, 1000, null);
        $(".online-block").css("height",online_height);
			}
//		  $(".online-body").slideDown(1000);
		  $("#online_button").removeClass("close");
	    $("#online_button").addClass("open");
//	    $("#online_yourblog").removeClass("minimal");
		  isOnlineExpand = true;
		  return false;
		};
	});
});

//init comments expands
var isCommentsExpand = true;

$(document).ready(function(){

	if(!document.getElementById("commets_button")) return;

	$("#commets_button").click(function(i){
		if( isCommentsExpand ) {
	    $(".comment-body").slideUp(1000);
	    $("#commets_button").removeClass("open-comments");
	    $("#commets_button").addClass("close-comments");
//	    $("#online_yourblog").addClass("minimal");
	    isCommentsExpand = false;
		  return false;
		}
		else{
		  $(".comment-body").slideDown(1000);
		  $("#commets_button").removeClass("close-comments");
	    $("#commets_button").addClass("open-comments");
//	    $("#online_yourblog").removeClass("minimal");
		  isCommentsExpand = true;
		  return false;
		};
	});
});

//init recent posts & popular tabs
var active_tab = "recent";

$(document).ready(function(){

	$("#popular").click(function(i){
		$("#recent_posts").removeClass("recent-on");
		$("#recent_posts").addClass("recent-off");
		$("ul.recent-block").css("display","none");
		$("#popular").removeClass("popular-off");
		$("#popular").addClass("popular-on");
		$("ul.popular-block").css("display","block");

		active_tab="popular";
		return false;
	});
	$("#recent_posts").click(function(i){
		$("#recent_posts").removeClass("recent-off");
		$("#recent_posts").addClass("recent-on");
		$("ul.recent-block").css("display","block");
		$("#popular").removeClass("popular-on");
		$("#popular").addClass("popular-off");
		$("ul.popular-block").css("display","none");

		active_tab="recent";
		return false;
	});
	
	//on over
	$("#recent_posts").mouseover(function(i){
		if (active_tab=="popular") $(this).addClass("recent-over");
	});
	$("#recent_posts").mouseout(function(i){
	  $(this).removeClass("recent-over");
	});
	$("#popular").mouseover(function(i){
	  if (active_tab=="recent") $(this).addClass("popular-over");
	});
	$("#popular").mouseout(function(i){
	  $(this).removeClass("popular-over");
	});
});

//init calendar & archive tabs
var active_tab_1 = "calendar";
$(document).ready(function(){
	$("#archive").click(function(i){
		$("#calendar").removeClass("calendar-on");
		$("#calendar").addClass("calendar-off");
		$(".calendar-block").css("display","none");
		$("#archive").removeClass("archive-off");
		$("#archive").addClass("archive-on");
		$(".archive-block").css("display","block");
    active_tab_1 = "archive";
		return false;
	});
	$("#calendar").click(function(i){
		$("#calendar").removeClass("calendar-off");
		$("#calendar").addClass("calendar-on");
		$(".calendar-block").css("display","block");
		$("#archive").removeClass("archive-on");
		$("#archive").addClass("archive-off");
		$(".archive-block").css("display","none");
    active_tab_1 = "calendar";
		return false;
	});

	//on over
	$("#calendar").mouseover(function(i){
	  if (active_tab_1=="archive") $(this).addClass("calendar-over");
	});
	$("#calendar").mouseout(function(i){
	  $(this).removeClass("calendar-over");
	});
	$("#archive").mouseover(function(i){
	  if (active_tab_1=="calendar") $(this).addClass("archive-over");
	});
	$("#archive").mouseout(function(i){
	  $(this).removeClass("archive-over");
	});
});

//init links & blogroll tabs
var active_tab_2 = "links";
$(document).ready(function(){
	$("#blogroll").click(function(i){
		$("#links").removeClass("links-on");
		$("#links").addClass("links-off");
		$("ul.links-block").css("display","none");
		$("#blogroll").removeClass("blogroll-off");
		$("#blogroll").addClass("blogroll-on");
		$("ul.blogroll-block").css("display","block");
		active_tab_2 = "blogroll";

		return false;
	});
	$("#links").click(function(i){
		$("#links").removeClass("links-off");
		$("#links").addClass("links-on");
		$("ul.links-block").css("display","block");
		$("#blogroll").removeClass("blogroll-on");
		$("#blogroll").addClass("blogroll-off");
		$("ul.blogroll-block").css("display","none");
		active_tab_2 = "links";

		return false;
	});

	//on over
	$("#links").mouseover(function(i){
	  if (active_tab_2 == "blogroll") $(this).addClass("links-over");
	});
	$("#links").mouseout(function(i){
	  $(this).removeClass("links-over");
	});
	$("#blogroll").mouseover(function(i){
	  if (active_tab_2 == "links") $(this).addClass("blogroll-over");
	});
	$("#blogroll").mouseout(function(i){
	  $(this).removeClass("blogroll-over");
	});
});

//init online & yourblog tabs
var active_tab_3 = "online";
$(document).ready(function(){
	$("#yourblog").click(function(i){
		$("#online").removeClass("online-on");
		$("#online").addClass("online-off");
		$("ul.online-block").css("display","none");
		$("#yourblog").removeClass("yourblog-off");
		$("#yourblog").addClass("yourblog-on");
		$("ul.yourblog-block").css("display","block");
		active_tab_3 = "yourblog";

		return false;
	});
	$("#online").click(function(i){
		$("#online").removeClass("online-off");
		$("#online").addClass("online-on");
		$("ul.online-block").css("display","block");
		$("#yourblog").removeClass("yourblog-on");
		$("#yourblog").addClass("yourblog-off");
		$("ul.yourblog-block").css("display","none");
    active_tab_3 = "online";
    
		return false;
	});

	//on over
	$("#online").mouseover(function(i){
	  if (active_tab_3 == "yourblog") $(this).addClass("online-over");
	});
	$("#online").mouseout(function(i){
	  $(this).removeClass("online-over");
	});
	$("#yourblog").mouseover(function(i){
	  if (active_tab_3 == "online") $(this).addClass("yourblog-over");
	});
	$("#yourblog").mouseout(function(i){
	  $(this).removeClass("yourblog-over");
	});
});

//init comments tabs
$(document).ready(function(){

	$("#add_comments").click(function(i){
		$("#view_comments").removeClass("view-comments-on");
		$("#view_comments").addClass("view-comments-off");
		$(".comments-show").css("display","none");
		$("#add_comments").removeClass("add-comments-off");
		$("#add_comments").addClass("add-comments-on");
		$(".add-comments-form").css("display","block");

		return false;
	});
	$("#view_comments").click(function(i){
		$("#view_comments").removeClass("view-comments-off");
		$("#view_comments").addClass("view-comments-on");
		$(".comments-show").css("display","block");
		$("#add_comments").removeClass("add-comments-on");
		$("#add_comments").addClass("add-comments-off");
		$(".add-comments-form").css("display","none");

		return false;
	});
});

$(document).ready(function(){
  $("#enquiry_button").click(function(i){
    var email_to_test = $("#email").val();
    if ( $("#company").val()=='Comapany' ){
      alert('Required field Company is empty');
      return false;
		}
		if ( $("#first_name").val()=='First Name' ){
      alert('Required field First Name is empty');
      return false;
		}
		if ( $("#last_name").val()=='Last Name' ){
      alert('Required field Last Name is empty');
      return false;
		}
		if ( $("#email").val=='Email Address' ){
      alert('Required field Email is empty');
      return false;
		}
		if ( !email_to_test.match(/^[\.\-_A-Za-z0-9]+?@[\.\-A-Za-z0-9]+?\.[A-Za-z0-9]{2,6}$/) ){
      alert('Incorrect Email');
      return false;
		}
		if ( $("#comments_text").val=='How can we help you?' ){
      alert('Empty Message text');
      return false;
		}
		
		var company = $("#company").val();
		var first_name = $("#first_name").val();
		var last_name = $("#last_name").val();
		var email = $("#email").val();
		var comments_text = $("#comments_text").val();
		var phone = $("#phone").val();
		var website = $("#website").val();
		var send_data = 'company=' + company + '&first_name=' + first_name + '&last_name=' + last_name + '&email=' + email + '&website=' + website + '&phone=' + phone + '&comments_text=' + escape(comments_text);
			$.ajax({
		   type: "POST",
		   url: "/blog/send_enquiry.php ",
		   data: send_data,
		   success: function(msg){
		    $('.enquiy').animate({'opacity':0}, 1000, null, function(){
				 	$('.enquiy').css('display', 'none');
				 	$('.enquiy-ok').css('display', 'block');
				 	$('.enquiy-ok').css('opacity', 0);
          $('.enquiy-ok').animate({'opacity':1}, 1000);
//          $('#message-area-text').text(textMessageSend);
				});
		   }
		 });
		
		return false;
  });
});

//comments form validation
$(document).ready(function(){
  $("#submit").click(function(i){
    if ( $("#author").val()=='' ){
      alert('Required field Author is empty');
      return false;
		}
		if ( $("#com_email").val()=='' ){
      alert('Required field Email is empty');
      return false;
		}
		var email_to_test = $("#com_email").val();
		if ( !email_to_test.match(/^[\.\-_A-Za-z0-9]+?@[\.\-A-Za-z0-9]+?\.[A-Za-z0-9]{2,6}$/) ){
      alert('Incorrect Email');
      return false;
		}
		if ( $("#comment").val()=='' ){
      alert('Please, type comment text');
      return false;
		}
  });
  
});
// init font-sizer
var tgs = new Array( 'div', 'p', 'li');
var szs = new Array( '12px', '', '16px');
var startSz = 0;

function ts(trgt, inc)
{
	if (!document.getElementById) return;
	var d = document, cEl = null, sz = startSz, i, j, cTags;
	sz = inc;
	if (sz < 0) sz = 0;
	if (sz > 2) sz = 2;
	startSz = sz;
//	if (!(cEl = d.getElementById(trgt))) cEl = d.getElementsByTagName(trgt)[0];
	if (!(cEl = $("div.resize") )) cEl = $("div.resize");
	$("div.resize").css("font-size", szs[sz]);

}