function my_kwicks(){
  $('.kwicks').kwicks({
  duration:300,   
    max:131,  
    spacing:0  
  });
}
 $(document).ready(function(){          
  my_kwicks();
});
/*/
$(function(){
  $('#gallery a').lightBox();
});
$(document).ready(function(){
  $('.slideshow').cycle({
    fx:'scrollLeft',
    speed:1000,
    timeout:7000
  });
});
*/
$(function(){
  $(".submit").click(function(){
    var name = $("#nama").val();
    var comment = $("#komentar").val();
    var dataString = 'nama='+name+'&komentar='+comment;
    if(comment=='' || name==''){
      alert("Silakan Login");
    }else{
      $("#flash").show();
      $("#flash").fadeIn(400).html('<img src="loading.gif" align="absmiddle"> <span class="loading">Loading Comment...</span>');
      $.ajax({
        type:"POST",
        url:"input_komentar.php",
        data:dataString,
        cache:false,
        success:function(html){
        $("div#update").prepend(html);
        document.getElementById('komentar').value='';
        document.getElementById('komentar').focus();
        $("#flash").hide();
        }
      });
    } return false;
  });
});

function submitForm(form){
  $(form).ajaxSubmit({
    success:function(response){
      if(response.indexOf('Terimakasih') > -1){
        alert(response);
        $(form).clearForm();
      }else alert('Error:'+response);
    }
  }); 
  return false; 
}

$(document).ready(function(){
  $().ajaxStart(function(){
    $('#loading').show();
  }).ajaxStop(function(){
    $('#loading').hide();
  });
  $('#myForm').submit(function(){ $('input[type=submit]', this).attr('disabled', 'disabled');
    $.ajax({
      type:'POST',
      url:$(this).attr('action'),
      data:$(this).serialize(),
      success:function(data){
        $('#shoutboxdata').html(data);
      }
    })
    return false;
  });
  
  $("#login_form").submit(function(){
    $("#msgbox").removeClass().addClass('messagebox').text('Validating....').fadeIn(1000);
    $.post("logf.php",{ user_name:$('#username').val(),password:$('#password').val(),rand:Math.random() } ,function(data){
      if(data=='yes'){
        $("#msgbox").fadeTo(200,0.1,function(){
          $(this).html('Logging in.....').addClass('messageboxok').fadeTo(900,1,function(){
            document.location='secure.php';
          });
        });
      }else{
        $("#msgbox").fadeTo(200,0.1,function(){
          $(this).html('ada yang salah...').addClass('messageboxerror').fadeTo(900,1);
        });
      }
    });
    return false; 
  });
    $("#password").blur(function(){
    $("#login_form").trigger('submit');
  });
});

function makeScrollable(wrapper, scrollable){
  var wrapper = $(wrapper), scrollable = $(scrollable);
  scrollable.hide();
  var loading = $('<div class="loading">Loading...</div>').appendTo(wrapper);
  var interval = setInterval(function(){
    var images = scrollable.find('img');
    var completed = 0;
    // Counts number of images that are succesfully loaded
    images.each(function(){
      if (this.complete) completed++;  
    });
    if (completed == images.length){
      clearInterval(interval);
      // Timeout added to fix problem with Chrome
      setTimeout(function(){
        loading.hide();
        // Remove scrollbars  
        wrapper.css({overflow:'hidden'});     
        scrollable.slideDown('slow', function(){
          enable();  
        });          
      }, 1000);  
    }
  }, 100);
  function enable(){
    // height of area at the top at bottom, that don't respond to mousemove
    var inactiveMargin = 99;          
    // Cache for performance
    var wrapperWidth = wrapper.width();
    var wrapperHeight = wrapper.height();
    // Using outer height to include padding too
    var scrollableHeight = scrollable.outerHeight()+2*inactiveMargin;
    // Do not cache wrapperOffset, because it can change when user resizes window
    // We could use onresize event, but it's just not worth doing that 
    // var wrapperOffset = wrapper.offset();
    // Create a invisible tooltip
    var tooltip = $('<div class="sc_menu_tooltip"></div>')
      .css('opacity', 0)
      .appendTo(wrapper);
    // Save menu titles
    scrollable.find('a').each(function(){        
      $(this).data('tooltipText', this.title);        
    });
    // Remove default tooltip
    scrollable.find('a').removeAttr('title');    
    // Remove default tooltip in IE
    scrollable.find('img').removeAttr('alt');
    var lastTarget;
    //When user move mouse over menu      
    wrapper.mousemove(function(e){
      // Save target
      lastTarget = e.target;
      var wrapperOffset = wrapper.offset();
      var tooltipLeft = e.pageX - wrapperOffset.left;
      // Do not let tooltip to move out of menu.
      // Because overflow is set to hidden, we will not be able too see it 
      tooltipLeft = Math.min(tooltipLeft, wrapperWidth - 75); //tooltip.outerWidth());
      var tooltipTop = e.pageY - wrapperOffset.top+wrapper.scrollTop() - 40;
      // Move tooltip under the mouse when we are in the higher part of the menu
      if (e.pageY - wrapperOffset.top < wrapperHeight/2){
        tooltipTop += 80;
      }
      tooltip.css({top:tooltipTop, left:tooltipLeft});
      // Scroll menu
      var top = (e.pageY -  wrapperOffset.top) * (scrollableHeight - wrapperHeight) / wrapperHeight - inactiveMargin;
      if (top < 0){
        top = 0;
      }
      wrapper.scrollTop(top);
    });
    // Setting interval helps solving perfomance problems in IE
    var interval = setInterval(function(){
      if (!lastTarget) return;
      var currentText = tooltip.text();
      if (lastTarget.nodeName == 'IMG'){          
        // We've attached data to a link, not image
        var newText = $(lastTarget).parent().data('tooltipText');
        // Show tooltip with the new text
        if (currentText != newText){
          tooltip
            .stop(true)
            .css('opacity', 0)  
            .text(newText)
            .animate({opacity:1}, 1000);
        }
      }
    }, 200);
    // Hide tooltip when leaving menu
    wrapper.mouseleave(function(){
      lastTarget = false;
      tooltip.stop(true).css('opacity', 0).text('');
    });
    /*
    //Usage of hover event resulted in performance problems
    scrollable.find('a').hover(function(){
      tooltip
        .stop()
        .css('opacity', 0)
        .text($(this).data('tooltipText'))
        .animate({opacity:1}, 1000);
  
    }, function(){
      tooltip
        .stop()
        .animate({opacity:0}, 300);
    });
    */      
  }
}
$(function(){  
  makeScrollable("div.sc_menu_wrapper", "div.sc_menu");
});
/*
  Added by Romi Web Studio
*/
$(function(){
  $('#slider').nivoSlider({
    effect:'random',
    slices:10,
    animSpeed:600,
    pauseTime:6000,
    startSlide:0,
    directionNav:false, 
    directionNavHide:false,
    controlNav:true,
    captionOpacity:0.8
  });
  $("a[rel='gal']").colorbox({current:"Foto {current} dari {total}",transition:"fade",opacity:0.8});
});

