﻿
//
// Copyright (c) 2008  Kivanc Toker - http://www.kivanctoker.com
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
// compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing permissions and limitations under the
// License.
//
function SlideItemByClick(target,way,container,distance)
{
    var position = $(target).position();
    
    var height_item = $(target).height();
    var width_item = $(target).width();
    
    var height_cont = $(container).height();
    var width_cont = $(container).width();
    
    if(way=='left')
    {
        if(position.left<0)
            $(target).animate({"left": "+="+distance+"px"}, 200);
    }
    else if(way=='right')
    {
        if(position.left+width_item>width_cont+1)
            $(target).animate({"left": "-="+distance+"px"}, 200);
    }
    else if(way=='up')
    {
        if(position.top<0)
            $(target).animate({"top": "+="+distance+"px"}, 200);
    }
    else if(way=='down')
    {
        if(position.top+height_item>height_cont)
            $(target).animate({"top": "-="+distance+"px"}, 200);
    }
    else
    {
        
    }
}

function SlideItem(target,way,container,distance)
  {
    var position = $(target).position();
    
    var height_item = $(target).height();
    var width_item = $(target).width();
    
    var height_cont = $(container).height();
    var width_cont = $(container).width();
    
    if(way=='left')
    {
        if(position.left<=0)
            $(target).animate({"left": "+="+distance+"px"},20, function(){SlideItem(target,way,container,distance);});
    }
    else if(way=='right')
    {
        if(position.left+width_item>=width_cont)
            $(target).animate({"left": "-="+distance+"px"}, 20, function(){SlideItem(target,way,container,distance);});
    }
    else if(way=='up')
    {
        if(position.top<=0)
            $(target).animate({"top": "+="+distance+"px"}, 20, function(){SlideItem(target,way,container,distance);});
    }
    else if(way=='down')
    {
        if(position.top+height_item>=height_cont)
            $(target).animate({"top": "-="+distance+"px"}, 20, function(){SlideItem(target,way,container,distance);});
    }
    else
    {
        
    }
  };
  
function ToggleItem(target)
  {
      if ($(target).is(":hidden"))
      {
        $(target).slideDown("slow");
      }
      else
      {
        $(target).slideUp();
      }
  };