$(document).ready(function(){

//-----=====jokerbox=====-----
$('.content a:has(img),.posttdMessage a:has(img)').click(function (event) {
    var big_img = $(this).attr("href");

  $("body").append("<div class='overlay'><table border='0' align='center' cellpadding='0' cellspacing='0'><tr><td background='/jokerbox/jokerbox_topleft.png' width='12' height='12'></td><td height='12' align='center' background='/jokerbox/jokerbox_topmid.png'></td><td background='/jokerbox/jokerbox_topright.png' width='12' height='12'></td></tr><tr><td background='/jokerbox/jokerbox_leftmid.png' width='12'></td><td align='center' bgcolor='#FFFFFF'><div class='big_image'><img src='"+big_img+"' /></div></td><td background='/jokerbox/jokerbox_rightmid.png' width='12'></td></tr><tr><td background='/jokerbox/jokerbox_bottleft.png' width='12' height='12'></td><td height='12' align='center' background='/jokerbox/jokerbox_bottmid.png'></td><td background='/jokerbox/jokerbox_bottright.png' width='12' height='12'></td></tr></table></div>");

    $(".overlay").show("fast");

//close modal window
$(".big_image img").click(function () {
  $(".big_image").fadeOut("fast", function(){$(".overlay").hide("fast", function(){$(".overlay").remove();});});
});
event.preventDefault();
  });

//-----=====count images=====-----
   var thumb = $('#thumbs img').length;
function count_img(){
   if (thumb == 3){
        $('#thumbs').append('<img class="add_thumbs" src="http://csexe.com.ua/images/add_img.gif" />');
   } else
   if(thumb == 2){
        $('#thumbs').append('<img class="add_thumbs" src="http://csexe.com.ua/images/add_img.gif" /><img class="add_thumbs" src="http://csexe.com.ua/images/add_img.gif" />');
   } else
   if(thumb == 1){
        $('#thumbs').append('<img class="add_thumbs" src="http://csexe.com.ua/images/add_img.gif" /><img class="add_thumbs" src="http://csexe.com.ua/images/add_img.gif" /><img class="add_thumbs" src="http://csexe.com.ua/images/add_img.gif" />');
   } else
   if(thumb == 0){
        $('#thumbs').append('<img class="add_thumbs" src="http://csexe.com.ua/images/add_img.gif" /><img class="add_thumbs" src="http://csexe.com.ua/images/add_img.gif" /><img class="add_thumbs" src="http://csexe.com.ua/images/add_img.gif" /><img class="add_thumbs" src="http://csexe.com.ua/images/add_img.gif" />');
   } else {}
}
count_img();

//-----=====get forum post=====-----
$('.f_details').click(function(){
   $(this).next().slideDown('slow', function(){
   $('.f_name:visible').not(this).slideUp('200');
   });
});

//-----=====gallery=====-----
$("#thumbs img").fadeTo("def", 0.5);

$("#thumbs img").click(function () {
	  $("#largeImg img").fadeIn(1000);
      $(this).fadeTo("def", 1);
    });
$("#thumbs img").not('.add_thumbs').click(function(){
var largePath = $(this).attr("src");
$("#largeImg img").attr({ src: largePath }); return false;
	});

//-----=====gallery UPDATE=====-----
$(".thumbs img").fadeTo("def", 0.5);

$(".thumbs img").click(function () {
      $(this).fadeTo("def", 1);
    });
$(".thumbs a").not('.add_thumbs').click(function(){
var largePath = $(this).attr("href");
$("#largeImg img").attr({ src: largePath }); return false;
	});

//-----=====login form=====-----
//$(".login_form").hover(function () {
//$(".login_form_name, .login_form_pass").hide("fast");
//}, function() {
//$(".login_form_name, .login_form_pass").show("fast");
//});
$(".loginBlock").mouseleave(function () {
   $(".loginDiv span").show();
   $(".passwordDiv span").show();
});
$(".loginDiv input").click(function () {
   $(".loginDiv span").hide();
});
$(".passwordDiv input").click(function () {
   $(".passwordDiv span").hide();
});

//-----=====button=====-----
//$(".button_img img").click(function () {
//$(".button_code").slideToggle('200');
//});

//-----=====pr links=====-----
$("input[readonly]").click(function () {
	  $(this).select(); return false;
    });

//-----=====pr links=====-----
$("textarea[readonly]").click(function () {
	  $(this).select(); return false;
    });
$(".footer_stats,.ffooter_stats").fadeTo("slow", 0.3);

//-----=====comments=====-----
var commForm = $(".cTop a:last").attr("href");
var ent = $(".cTop a:last").attr("name");
$(".comm_more a").attr({ href: ent });

$(".comm_more").click(function (event) {
 var name = $(this).prev().find("b").text();
$("textarea[name='message']").val(name+", ");
event.preventDefault();
});

//-----=====Add panel: images=====-----
$("input[name='but_1']").click(function () {
$("textarea[name='message']").val('<div id="thumbs">$IMAGE1$</div><div id="largeImg">$IMAGE1$</div>');
    });
$("input[name='but_2']").click(function () {
$("textarea[name='message']").val('<div id="thumbs">$IMAGE1$$IMAGE2$</div><div id="largeImg">$IMAGE1$</div>');
    });
$("input[name='but_3']").click(function () {
$("textarea[name='message']").val('<div id="thumbs">$IMAGE1$$IMAGE2$$IMAGE3$</div><div id="largeImg">$IMAGE1$</div>');
    });
$("input[name='but_4']").click(function () {
$("textarea[name='message']").val('<div id="thumbs">$IMAGE1$$IMAGE2$$IMAGE3$$IMAGE4$</div><div id="largeImg">$IMAGE1$</div>');
    });
$("input[name='small']").click(function () {
$("textarea[name='brief']").val('$IMAGE5$');
    });
$("input[name='text']").click(function () {
$("textarea[name='message']").val('<div class="content_pad"></div>');
    });
$("input[name='clear']").click(function () {
$("textarea[name='message'], textarea[name='brief']").val('');
    });

//-----=====modal=====-----
function jmodal(){
$(".m_overlay").fadeTo("fast", 0.5);
$(".m_overlay").fadeIn("fast", function(){
	$(".m_container").show();
	});
var m_height = $(".m_content").height();
var m_width = $(".m_content").width();

$(".m_container").animate({marginBottom: m_height*2}, 100);
$(".m_content").slideDown("slow");

$(".m_close").click(function(){
	$(".m_container").hide("fast", function(){
	$(".m_overlay").hide();
	});
});
}

//-----=====forum [оформлено]=====-----
$('.threadDescr:contains("[Оформлено]")').css('color','#EE5400');

//-----=====uid fade=====-----
$(".uid_block").hover(function(){
$(this).fadeTo("fast", 1);
}, function(){
$(this).fadeTo("fast", 0.5);
})

//-----=====helper=====-----
$(".helper li a:first").css({backgroundColor:"#523C2C", borderBottom:"1px solid #523C2C"});
$(".helper li a").click(function(){
  $(".helper li a").removeAttr("style");
  $(this).css({backgroundColor:"#523C2C", borderBottom:"1px solid #523C2C"});

var getName = $(this).attr("name");
$(".helper_content").children('div:visible').slideUp(200, function(){
  $("#"+getName).slideDown(0);
});
})

//-----=====sms=====-----
$("#sms").toggle(
  function () {
    $(".mobile_service").slideDown("200");
  },
  function () {
    $(".mobile_service").slideUp("200");
  }
);

});
