$(function(){
  if($("input.blur").length>0){
    $('input[title!=""]').hint()
    }
  if($("div.subscribe").length>0){
    $("div.subscribe form").hide();

    $("div.subscribe a#subscr").click(function(){
      $(this).siblings().andSelf().hide('fast');
        $("div.subscribe form#subscribe").show();
        return false
     })

    $("div.subscribe a#unsubscr").click(function(){
      $(this).siblings().andSelf().hide('fast');
        $("div.subscribe form#unsubscribe").show();
        return false
     })

    $("div.subscribe div.close").click(function(){
      $(this).parents("form").hide('fast',function(){
        $("input:not([name=submitfrm])", this).val("");
      }).siblings("a").fadeIn('fast');
      return false;
    })

    }if($(".newsmonth").length>0){
    $('h4.end + div').css('background','#fff');$('.newsmonth').accordion({
      header:'h4',
      autoheight:false,
      navigation:false,
      active:'.selected'
    });$('h4.empty').click(function(){
      return false
      })
    }
    if($(".jcwrapper .jCarouselLite").length>0){
    $(".jcwrapper .jCarouselLite").jCarouselLite({
      btnNext:".next",
      btnPrev:".prev",
      visible:4
    })
    
    $(".jcwrapper .jCarouselLite div").hover(function(){
      $("p",this).animate({
        marginTop:"-33px",
        opacity:0.8
      },"slow")
      },function(){
      $("p",this).animate({
        marginTop:1,
        opacity:0.8
      },"slow").dequeue();return false
      })    
    }

    if($(".prg_gallery .jCarouselLite").length>0){
   
    $(".prg_gallery .jCarouselLite").jCarouselLite({
      btnNext:".prg_next",
      btnPrev:".prg_prev",
      visible:4,
      easing:"easeinout",
      speed:500
    });
    $(".prg_gallery li div.onion div").hover(function(){
      $("p",this).animate({
        marginTop:"-44px",
        opacity:0.8
      },"slow")
      },function(){
      $("p",this).animate({
        marginTop:1,
        opacity:0
      },"slow").dequeue();return false
      })
    }
    if($(".home_img").length>0){
    if($(".home_img .jCarouselLite").length>0){
      $(".home_img .jCarouselLite").jCarouselLite({
        btnNext:".next",
        btnPrev:".prev",
        visible:1
      })
      }$(".home_img").hover(function(){
      $("p",this).animate({
        top:310,
        opacity:0.7
      },"slow")
      },function(){
      $("p",this).animate({
        top:361,
        opacity:0
      },"slow").dequeue();return false
      })
    }if($("#title_by_abj").length>0){
    if($("#title_by_abj").attr('class')=='comu'){
      mode='b';page='directories'
      }else if($("#title_by_abj").attr('class')=='docu'){
      mode='a';page='directories'
      }else if($("#title_by_abj").attr('class')=='rent'){
      mode='c';page='resources'
      }$("div.abjad a").livequery("click",function(){
      $("div.abjad a").siblings().removeClass('act');$(this).addClass('act');url=$(this).attr('href');bhs=url.substring(url.length-2);abj=$(this).text();$.ajax({
        url:'/'+page+'/title_by_alpha/'+mode+'/'+abj+'/1/0/'+bhs,
        type:'get',
        dataType:'html',
        success:function(a){
          $("#title_by_abj").slideUp('fast',function(){
            $(this).empty().html(a).slideDown('fast')
            })
          }
        });return false
      });$("div#title_by_abj li.paging a").livequery("click",function(){
      surl=$(this).attr('href');var b=$(this).parents("div#title_by_abj");$.ajax({
        url:surl,
        type:'get',
        dataType:'html',
        success:function(a){
          b.html(a)
          }
        });return false
      })
    }if($(".headmonth").length>0){
    $("#prev,#next").livequery("click",function(){
      $(".headmonth").append('<img id="yearbusy" src="assets/images/year-busy.gif" alt="">');surl=$(this).attr('href');bhs=surl.substring(surl.length-2);var b=$("input#thisyear").val();if($(this).attr('id')=='prev'){
        b--
      }else if($(this).attr('id')=='next'){
        b++
      }else{
        return false
        }next=parseInt(b,10)+1;prev=parseInt(b,10)-1;$("div.headmonth span").text(b);$("div.headmonth #prev").attr('href','news/year/'+prev+'/'+bhs);$("div.headmonth #next").attr('href','news/year/'+next+'/'+bhs);$.ajax({
        url:surl,
        type:'get',
        dataType:'html',
        success:function(a){
          $("div.newsmonth").empty().html(a).find('h4').removeClass("selected");$('div.item').hide();$("img#yearbusy").fadeOut('fast',function(){
            $(this).remove()
            });$("input#thisyear").val(b);$('.empty').click(function(){
            return false
            })
          }
        });return false
      })
    }if($(".newsmonth .paging").length>0){
    $(".paging a").livequery("click",function(){
      surl=$(this).attr('href');if($(this).parent().attr('class')=='pgprev'||$(this).parent().attr('class')=='pgnext'){
        var b=$(this).parent().parent().parent()
        }else{
        var b=$(this).parent().parent()
        }$.ajax({
        url:surl,
        type:'get',
        dataType:'html',
        success:function(a){
          b.html(a).find("li:last").addClass("noborder")
          }
        });return false
      })
    }if($(".programs .paging").length>0){
    $(".paging a").livequery("click",function(){
      var b=$(this).attr('href');var c=$(this).parent().parent();$.ajax({
        url:b,
        type:'get',
        dataType:'html',
        success:function(a){
          c.html(a)
          }
        });return false
      })
    }if($(".upcoming .paging").length>0){
    $(".paging a").livequery("click",function(){
      var b=$(this).attr('href');if($(this).parent().attr('class')=='prevnext'){
        var c=$(this).parent().parent().parent()
        }else{
        var c=$(this).parent().parent()
        }$.ajax({
        url:b,
        type:'get',
        dataType:'html',
        success:function(a){
          c.html(a)
          }
        });return false
      })
    }if($(".edupaging").length>0){
    $(".edupaging ul li a").livequery("click",function(){
      var b=$(this).attr('href');var c=$(this).parent().parent().parent().parent();$.ajax({
        url:b,
        type:'get',
        dataType:'html',
        success:function(a){
          c.html(a)
          }
        });return false
      });$("a.edu_prev, a.edu_next").livequery("click",function(){
      var b=$(this).attr('href');var c=$(this).parent();$.ajax({
        url:b,
        type:'get',
        dataType:'html',
        success:function(a){
          c.html(a)
          }
        });return false
      })
    }if($(".docuboxlist").length>0){
    $(".paging a").livequery("click",function(){
      var b = $(this).attr('href');
      var c = $(this).parent();
      var d = $(this).parent().parent();
      c.remove();
      $.ajax({
        url:b,
        type:'get',
        dataType:'text',
        success:function(a){
          d.html(a)
          }
        });
        return false;
      });
    }

    if($("#subscribe").length>0){
    
      var e=$("#subscribe [@name=bhs]").val();
      if(e=='id'){
      txt='Data diri anda telah dikirim.<br />Terima Kasih.<br /><br /><a href="/">kembali</a>';err_fullname_req='Nama harus diisi';err_fullname_len='Masukkan minimal 3 karakter';err_gender_req='Pilih jenis kelamin';err_job_req='Pekerjaan harus diisi';err_job_num='Masukkan minimal 2 karakter';err_age_req='Masukkan Umur';err_age_num='Masukkan hanya angka';err_edu_req='Pendidikan harus diisi';err_edu_len='Masukkan minimal 2 karakter';err_mail_req='E-mail harus diisi';err_mail_valid='Masukkan alamat e-mail selengkapnya'
      }else{
      txt='Data has been submitted.<br />Thank You.<br /><br /><a href="/">back</a>';err_fullname_req='Name is required';err_fullname_len='';err_gender_req='Select your gender';err_job_req='Job is required';err_job_num='';err_age_req='Age is required';err_age_num='Enter numeric only';err_edu_req='Education is required';err_edu_len='';err_mail_req='E-mail is required';err_mail_valid='Enter valid e-mail address'
      }$("#subscribe").validate({
      rules:{
        fullname:{
          required:true,
          minlength:3
        },
        gender:"required",
        job:{
          required:true,
          minlength:2
        },
        age:{
          required:true,
          number:true
        },
        education:{
          required:true,
          minlength:2
        },
        email:{
          required:true,
          email:true
        }
        },
      messages:{
        fullname:{
          required:err_fullname_req,
          minlength:err_fullname_len
        },
        gender:err_gender_req,
        job:{
          required:err_job_req,
          minlength:err_job_num
        },
        age:{
          required:err_age_req,
          number:err_age_num
        },
        education:{
          required:err_edu_req,
          number:err_edu_len
        },
        email:{
          required:err_mail_req,
          email:err_mail_valid
        }
        },
      errorPlacement:function(a,b){
        if(b.is(":radio")){
          a.appendTo(b.parent().next().next().next())
          }else{
          a.appendTo(b.parent())
          }
        },
      submitHandler:function(b){
        $("div.subscr").remove();
        $("div.removable").append('<img class="subscribe_loading" src="assets/images/subscribe_sending.gif" width="43" height="11" alt="Sending.." />');
        $.ajax({
          url:'/postman/subscribe/'+e,
          type:'post',
          data:{
            out:'ajax',
            bhs:e,
            fullname:$("#subscribe [@name=fullname]").val(),
            gender:$("#subscribe [@name=gender]").val(),
            job:$("#subscribe [@name=job]").val(),
            age:$("#subscribe [@name=age]").val(),
            education:$("#subscribe [@name=education]").val(),
            email:$("#subscribe [@name=email]").val(),
            token:$("#subscribe [@name=token]").val()
            },
          dataType:'html',
          success:function(a){
            $(".removable").fadeOut('fast',function(){
              $(this).replaceWith('<p>'+a+'</p>')
              })
            }
          });return false
        }
      })
    }

    if($("#unsubscribe").length>0){
      $("#unsubscribe input[name=submitfrm]").click(function(){
        if ($("#unsubscribe input[name=email]").val()!='')
        {
          $("div.subscr").remove();
          $("div.removable").append('<img class="subscribe_loading" src="assets/images/subscribe_sending.gif" width="43" height="11" alt="Sending.." />');
          $.ajax({
            url:'/postman/unsubscribe/'+e,
            type:'post',
            data:{
              out:'ajax',
              bhs:e,
              email:$("#unsubscribe [@name=email]").val(),
              token:$("#unsubscribe [@name=token]").val()
              },
            dataType:'html',
            success:function(a){
              $(".removable").fadeOut('fast',function(){
                $(this).replaceWith('<p>'+a+'</p>')
                })
              }
          })
        }
        return false;
      })
    }
  });