// $Id: views_bookmark.js,v 1.1.2.13 2008/01/07 08:38:56 quicksketch Exp $
if (Drupal.jsEnabled) {
  $(document).ready(function () {

    $('#edit-field-picture-upload').bind('change', function(){
      file = document.getElementById("edit-field-picture-upload").value;
      validate_imageUpload_filename(file, 'edit-field-picture-upload');
    });
    $('.view-content-featured-reviews .item-list ul').after('<div class="readmore" style="padding-right: 5px;"><a href="reviews">view all</a>');
    $('#edit-field-product-photos-upload').bind('change', function(){
      file = document.getElementById("edit-field-product-photos-upload").value;
      validate_imageUpload_filename(file, 'edit-field-product-photos-upload');
    });
    $('.featured-review-content').html($('.view-content-featured-reviews ul li:first .review-content').html());
    $('.featured-article-content').html($('.view-content-featured-articles ul li:first .article-content').html());
    $('.view-content-featured-articles li').hover(function () {
      var curr = $(this).children('div.article-content').html();
       if (curr  != $('.featured-article-content').html()) {
           $('.featured-article-content').fadeOut(100, function () {
             $('.featured-article-content').html(curr);
             $('.featured-article-content').fadeIn(350);
           });
       }
    },        
    function () {});
    $("#block-mluserworkflow-profile_completeness .open").toggle(
		  function () {
        $("#block-mluserworkflow-profile_completeness .item-list").show(); 
        $(this).html('<span>close tasks</span>');  
		},function () {
        $("#block-mluserworkflow-profile_completeness .item-list").hide();
        $(this).html('<span>view open tasks</span>');			

		});
    $("#block-mluserworkflow-profile_completeness2 .open").toggle(
      function () {
        $("#block-mluserworkflow-profile_completeness2 .item-list").show(); 
        $(this).html('<span>close tasks</span>');  
    },function () {
        $("#block-mluserworkflow-profile_completeness2 .item-list").hide();
        $(this).html('<span>view open tasks</span>');     

    });
    $('.view-content-featured-reviews li').hover(function () {
      var curr = $(this).children('div.review-content').html();
       if (curr != $('.featured-review-content').html()) {
         $('.featured-review-content').fadeOut(100, function(){
           $('.featured-review-content').html(curr);
           $('.featured-review-content').fadeIn(350);
         });
       }
    },
    function () {});
   
    $('.view-content-madeloud-highlights div.item-list ul')
    
    .cycle({ 
        fx:    'scrollRight',
        sync: 0,
        height: '195px',
        timeout: 16000,
        pause: 1,
        delay: -4500,
        cleartype:  1,
        cssBefore: { opacity: 1 },
        pager:  '#hl-nav ul',
        pagerAnchorBuilder: function(idx, slide) { 
            return '<li><a href="#">' + $(".view-content-madeloud-highlights .item-list ul li:eq(" + idx + ") .view-data-node-data-field-mlhighlight-label-field-mlhighlight-label-value").html() + '</a></li>';
        },
        animOut:  { opacity: .0}
    });

    
    
    $("#sidebar h2").wrapInner("<span></span>");
    $(".pre h2").wrapInner("<span></span>");    
  });
}


function validate_imageUpload_filename(file, id_tag){
  var file_name;
  var name_array;

  if(file.indexOf("\\") > -1){
    name_array = file.split("\\");
    file_name = name_array[name_array.length - 1];
  }else if(file.indexOf("/") > -1){
    name_array = file.split("/");
    file_name = name_array[name_array.length - 1];
  }else{
    file_name = file
  }
  
  //name_array = file.split("\\");
  //file_name = name_array[name_array.length - 1];
  // alert('file_name = '+ file_name);
  
  if(file_name.match(/^[a-zA-Z_0-9 \-]{1,}\.[a-zA-Z]{3,}?$/) == null){
        alert("Invalid file name entry. Valid file name includes alphanumeric, '-', '_' and space characters.");
        document.getElementById(id_tag).value = '';
  }
}