function jmark( item )
{
    $.get( '/helpguide/mark_as_read.php?title='+item+'&sid='+document.getElementById("si_id").value );
}

function update_record()
{
  var order = $('#widgets').sortable('serialize');
  var url = 'wid_handler.php?a=s&s='+s_id+'&p='+p_name;
  $.post( url, order, function(data){

      var wi_obj = eval(data);

      if( wi_obj.images_left && wi_obj.images_left != '' ){
        if( wi_obj.images_left < 0 )
            $("#images_amount" ).html('<b style="color:red">'+wi_obj.images_left+'</b>');
        else
            $("#images_amount" ).html('<b>'+wi_obj.images_left+'</b>');
      }

      if( wi_obj.videos_left && wi_obj.videos_left != '' ){
        if( wi_obj.videos_left < 0 )
            $("#videos_amount" ).html('<b style="color:red">'+wi_obj.videos_left+'</b>');
        else
            $("#videos_amount" ).html('<b>'+wi_obj.videos_left+'</b>');
      }

      if( wi_obj.max_widgets && wi_obj.max_widgets != '' )
        $("#widgets_amount").html('<b>'+wi_obj.max_widgets+'</b>');

      if( wi_obj.widgets_left && wi_obj.widgets_left != '' ){
        if( wi_obj.widgets_left < 0 )
            $("#widgets_left").html('<b style="color:red">'+wi_obj.widgets_left+'</b>');
        else
            $("#widgets_left").html('<b>'+wi_obj.widgets_left+'</b>');
      }
      $("#widgets_tick").attr("class", "nav-tick");
  });
}


function showhidetips( mobj )
  {
    $( "#tipsdiv" ).slideToggle(600);
  }

function expcolap( status, divid )
{
    var options = {};
    options[ "status" ] = status;
    options[ "divid" ] = divid;
    options[ "id_u_site" ] = $("#si_id").val();
    $.post( '/include/box_colexpand.php', options );
}

function jtoggle(mobj)
{
  var secobj = $(mobj).parent().parent().parent().find("div:eq(1)");
  if( $(mobj).parent().attr("class") == "box-minimise" )
  {
     $(mobj).parent().attr("class", "box-expand");
     expcolap( ' style="display:none;" ', $(secobj).attr("id") );
  }
  else
  {
     $(mobj).parent().attr("class", "box-minimise");
     expcolap( ' ', $(secobj).attr("id") );
  }


  $(secobj).slideToggle(600);


}

 function initMenu( divname )
 {
    $('#'+divname+' li a').click(
    function()
    {
      var checkElement = $(this).next();
      if((checkElement.is('ul')) && (checkElement.is(':visible')))
      {
          $('#'+divname+' ul:visible').slideUp('normal');
          return false;
      }
      if((checkElement.is('ul')) && (!checkElement.is(':visible')))
      {
          var myhref = $(this).attr("href");
          $('#'+divname+' ul:visible').slideUp('normal');
          checkElement.slideDown('normal', function(){ if(window.location.href != myhref && window.location.href != '/'+myhref) window.location.href=myhref; });
          return false;
      }
    }
 );
 }


  $(document).ready(function() {

    $('#fisheye').Fisheye(
    {
        maxWidth: 30,
        items: 'a',
        itemsText: 'span',
        container: '.fisheyeContainter',
        itemWidth: 145,
        proximity: 15,
        halign : 'center'
    }
    )


  initMenu('menu_website');
  initMenu('menu_marketing');
  initMenu('menu_administration');
  initMenu('menu_member');

  $(".widget-item-overlay-content .wm-preview").hover(
  function()
  {
    $(this).parent().parent().find("span:last").html('Preview');
  }
  );
  $(".wm-info").hover(
  function()
  {
    $(this).parent().parent().find("span:last").html('More Info');
  }
  );
  $(".wm-drag").hover(
  function()
  {
    $(this).parent().parent().find("span").html('Drag Me');
  }
  );

  $(".widget-item-overlay-content").animate({b:1},1000).slideUp("slow");

  $(".widget-item-normal").hover(
  function()
  {
    $(this).find(".widget-item-overlay-content").slideDown("fast");
  },
  function()
  {
    $(this).find(".widget-item-overlay-content").slideUp("fast");
  }
  );





  //$("#info_message").animate({ab:44}, 2000).slideDown("slow").animate({ab:44}, 4000).slideUp("slow");

  $("#expand_q").click( function(){
    $("#q").slideDown('slow');
    $("#expand_q").hide();
    $("#minimize_q").show();
  });

  $("#minimize_q").click( function(){
    $("#q").slideUp('slow');
    $("#minimize_q").hide();
    $("#expand_q").show();
  });


   $("#show").click( function(){
    $("#bb_content").slideDown('slow');
    $("#expand_bb_content").hide();
    $("#minimize_bb_content").show();
  });

  $("#minimize_bb_content").click( function(){
    $("#bb_content").slideUp('slow');
    $("#minimize_bb_content").hide();
    $("#expand_bb_content").show();
  });

   /*
   $(".options").click( function()
      {
        var options = $(this).parent().parent().parent().find("#options");
        var info    = $(this).parent().parent().parent().find(".widget-label");
        if(info.is(":hidden"))
            options.slideUp( "slow", function(){info.slideDown("slow");} );
        else
            info.slideUp("slow", function(){options.slideDown("slow");});
      }
    );

    */
    $("#test-list").sortable({
      handle : '.handle',
      update : function () {
		var order = $('#test-list').sortable('serialize');
        // $("#info").html('http://member2.independentowners.com/'+document.getElementById('baseurl').value+'&component=box_images&ajax='+document.getElementById('cid').value+'&'+order);

		 $.get( '/'+document.getElementById('baseurl').value+'&component=box_images&ajax='+document.getElementById('cid').value+'&'+order );
      }
    });


    /* widgets sorting */

    $("#widgets, #widgets_pool, #widgets_pool2, #widgets_pool3, #widgets_pool4").sortable({
		    connectWith: '.wis',
			placeholder: 'ui-state-highlight',
            cursor: 'crosshair',
            tolerance: 'intersect',
            update : function()
            {
 	            update_record();
            }
		});
		$("#widgets, #widgets_pool, #widgets_pool2, #widgets_pool3, #widgets_pool4").disableSelection();
});

    function addwi(id)
    {
      var content = '<div id="'+id+'" class="widget_holder">';
      content +=  $("#"+id).html();
      content += '</div>';
      content = content.replace("addwi('"+id+"')", "removewi(this)");
      content = content.replace('mra_expanded_but_new', "mra_expanded_but_close");
      content = content.replace('Add this Widget', "Remove");
      $("#widgets").append(content);
      update_record();
    }

    function removewi(t_obj)
    {
      //alert($(t_obj).parent().parent().parent().attr('id'));
      $(t_obj).parent().parent().parent().replaceWith("");
      update_record();
    }

    function display(id)
    {
      // hide everything
      /*
      $("#custom_wi_pool").slideUp("slow", function()
      {
        $("#extra_wi_pool").slideUp("slow", function()
        {
            $("#io_wi_pool").slideUp("slow", function()
            {
                $("#"+id).slideDown("slow");
            });
        });
      });
      */
      //
      //
      // hide menus
      $("#io_wi_pool").hide();
      $("#extra_wi_pool").hide();
      $("#custom_wi_pool").hide();

      // show widgets and its menu button
      //
      $("#"+id).show("slow");
      $(".widget-item-overlay-content").animate({b:1},2000).slideUp("slow");
    }


function popupguide(mylink, windowname, ttt)
{
jmark(ttt);
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=550,height=550,scrollbars=yes');
return false;
}



