$(document).ready(function(){

    $("div#slider1").codaSlider();
    $(".stripNavL").addClass("help");
    $(".stripNavL").mouseover(function(){
        $(this).removeClass("help");
    });
    $(".stripNavR").mouseover(function(){
        $(".stripNavL").removeClass("help");
    });
    
    $("#slider1").find("img").mouseover(function(){
        var i = $(this).parent().parent().find("img").index($(this));
        if(i<4){
          var mtop = 0;
          if(i==3){
              var mleft = parseInt((170*i) + (-72));
          } else {
              var mleft = parseInt((170*i) + 37);
          }
        } else {
            if(i<8){
                var mtop = "120px";
                if(i==7){
                    var mleft = parseInt((170*(i+(-4))) + (-72));
                } else {
                    var mleft = parseInt((170*(i+(-4))) + 37);
                }
            } else {
                var mtop = "235px";
                if(i==11){
                    var mleft = parseInt((170*(i+(-8))) + (-72));
                } else {
                    var mleft = parseInt((170*(i+(-8))) + 37);
                }
            }
        }
        $("#imgBorder").remove();
        var Arel= $(this).parent().attr("rel");
        var Ahref= $(this).parent().attr("title");
        $("#wrapped-text").append("<a href='"+Ahref+"' id='imgBorder' style='margin:"+mtop+" 0 0 "+mleft+"px'><img src='"+Arel+"' alt=''/></a>");
        $("#imgBorder").mouseout(function(){
            $("#imgBorder").remove();
        });
    });
    
    showfilter();
    
    /* this shit autocalculate common price, change id there if you change id at html */
    $("#bilet-count").change(function(){
        var cnt = $(this).val();
        var price = $(this).parent().find("span").html();
        $(".pricecommon").find("span").html(""+parseInt(price*cnt)+" p.");
    });
    
    /* show block */
    $("#s-delivery").click(function(){
        var checked = $(this).attr("checked");
        if(checked==true){
            $("#deliv").slideDown("fast");
        } else {
            $("#deliv").slideUp("fast");
        }
    });
    
    $("h3.green > a").click(function(){
        var rel = $(this).attr("rel");
        $("#"+rel).fadeIn("fast");
    });
    
    /* change this for right image path*/
	$(".preview > a").click(function(){
        var path = $(this).attr("rel");
        $("#big_pic").fadeOut("fast");
        $("#big_pic").attr("src",path);
        $("#big_pic").fadeIn("fast");
        return false;
	});	
    /* show/hide form of responses */
    $(".showform").click(function(){
        if($(this).attr("class")=='showform'){
          $(this).addClass("red");
          $(this).find("span").html("Закрыть форму");
          $("#response").fadeIn("fast");
        } else {
          $(this).removeClass("red");
          $("#response").fadeOut("fast");
          $(this).find("span").html("Оставить отзыв");
        }
    });
    
    /* show responses */
    $("#showallresponses").click(function(){
        if($(this).attr("class")!='red'){
            $(this).addClass("red");
            $(this).find("span").html("Скрыть отзывы");
            $("#allresponse > li[@class=d_none]").slideDown("fast");
        } else {
            $(this).removeClass("red");
			$(this).find("span").html("Раскрыть все отзывы ("+parseInt($("#allresponse").find("li").size()+(-2))+")");
            $("#allresponse > li[@class=d_none]").slideUp("fast");
	    }
    });
    
});

function showfilter(){
  $("a[@rel=click]").click(function(){
      $(this).css("display","none");
      $("#third-link").animate({
        marginLeft: '565px'
      }, "slow", "easeInSine");
      $("#forth-link").animate({
        marginLeft: '-185px'
      }, "slow", "easeInSine");
      $("#search").fadeIn("slow").css("visibility","hidden");
      $("a[@rel=search]").css("display","block");
      $(".filter").fadeIn("slow").css("visibility","visible");
      return false;
  });

  $("a[@rel=search]").click(function(){
      $(this).css("display","none");
      $("a[@rel=click]").css("display","block");
      $("#third-link").animate({
        marginLeft: '380px'
      }, "slow", "easeInSine");
      $("#second-link").animate({
        marginLeft: '-130px'
      }, "slow", "easeInSine");
      $("#fifth-link").animate({
        marginLeft: '-80px'
      }, "slow", "easeInSine");
      $(".filter").fadeOut("slow").css("visibility","hidden");
      $("#search").fadeIn("slow").css("visibility","visible");
      return false;
  });  
}
