
var $DOP = jQuery.noConflict();

function Prototypes()
{
    this.ResizeImage_DefaultWidth = 0;
    this.ResizeImage_DefaultHeight = 0;

    // -----> BEGIN IMAGE RESIZE

    this.ResizeImageAfterLoad = function(container, cw, ch, pos)
    {
        $DOP(container).width(cw);
        $DOP(container).height(ch);
        $DOP('img', container).stop(true, true).animate({opacity:'0'}, 0);

        $DOP('img', container).load(function()
        {
            this.ResizeImage_DefaultWidth = $DOP('img', container).width();
            this.ResizeImage_DefaultHeight = $DOP('img', container).height();

            var defaultW = this.ResizeImage_DefaultWidth;
            var defaultH = this.ResizeImage_DefaultHeight;
            var currW = 0;
            var currH = 0;

            if (defaultW <= cw && defaultH <= ch)
            {
                currW = defaultW;
                currH = defaultH;
            }
            else
            {
                currH = ch;
                currW = (defaultW*ch)/defaultH;

                if (currW > cw)
                {
                    currW = cw;
                    currH = (defaultH*cw)/defaultW;
                }
            }

            $DOP('img', container).width(currW);
            $DOP('img', container).height(currH);

            if (pos.toLowerCase() == 'top'){this.TopItem(container, ch);}
            if (pos.toLowerCase() == 'bottom'){this.BottomItem(container, ch);}
            if (pos.toLowerCase() == 'left'){this.LeftItem(container, cw);}
            if (pos.toLowerCase() == 'right'){this.RightItem(container, cw);}
            if (pos.toLowerCase() == 'horizontal-center'){this.HCenterItem(container, cw);}
            if (pos.toLowerCase() == 'vertical-center'){this.VCenterItem(container, ch);}
            if (pos.toLowerCase() == 'center'){this.CenterItem(container, cw, ch);}
            if (pos.toLowerCase() == 'top-left'){this.TLItem(container, cw, ch);}
            if (pos.toLowerCase() == 'top-center'){this.TCItem(container, cw, ch);}
            if (pos.toLowerCase() == 'top-right'){this.TRItem(container, cw, ch);}
            if (pos.toLowerCase() == 'middle-left'){this.MLItem(container, cw, ch);}
            if (pos.toLowerCase() == 'middle-right'){this.MRItem(container, cw, ch);}
            if (pos.toLowerCase() == 'bottom-left'){this.BLItem(container, cw, ch);}
            if (pos.toLowerCase() == 'bottom-center'){this.BCItem(container, cw, ch);}
            if (pos.toLowerCase() == 'bottom-right'){this.BRItem(container, cw, ch);}

            $DOP('img', container).stop(true, true).animate({opacity:'1'}, 0);
        });
    }

    this.ResizeImage = function(container, cw, ch, pos)
    {
        $DOP(container).width(cw);
        $DOP(container).height(ch);

        var defaultW = this.ResizeImage_DefaultWidth;
        var defaultH = this.ResizeImage_DefaultHeight;
        var currW = 0;
        var currH = 0;

        if (defaultW <= cw && defaultH <= ch)
        {
            currW = defaultW;
            currH = defaultH;
        }
        else
        {
            currH = ch;
            currW = (defaultW*ch)/defaultH;

            if (currW > cw)
            {
                currW = cw;
                currH = (defaultH*cw)/defaultW;
            }
        }

        $DOP('img', container).width(currW);
        $DOP('img', container).height(currH);

        if (pos.toLowerCase() == 'top'){this.TopItem(container, ch);}
        if (pos.toLowerCase() == 'bottom'){this.BottomItem(container, ch);}
        if (pos.toLowerCase() == 'left'){this.LeftItem(container, cw);}
        if (pos.toLowerCase() == 'right'){this.RightItem(container, cw);}
        if (pos.toLowerCase() == 'horizontal-center'){this.HCenterItem(container, cw);}
        if (pos.toLowerCase() == 'vertical-center'){this.VCenterItem(container, ch);}
        if (pos.toLowerCase() == 'center'){this.CenterItem(container, cw, ch);}
        if (pos.toLowerCase() == 'top-left'){this.TLItem(container, cw, ch);}
        if (pos.toLowerCase() == 'top-center'){this.TCItem(container, cw, ch);}
        if (pos.toLowerCase() == 'top-right'){this.TRItem(container, cw, ch);}
        if (pos.toLowerCase() == 'middle-left'){this.MLItem(container, cw, ch);}
        if (pos.toLowerCase() == 'middle-right'){this.MRItem(container, cw, ch);}
        if (pos.toLowerCase() == 'bottom-left'){this.BLItem(container, cw, ch);}
        if (pos.toLowerCase() == 'bottom-center'){this.BCItem(container, cw, ch);}
        if (pos.toLowerCase() == 'bottom-right'){this.BRItem(container, cw, ch);}
    }

    this.ResizeImage2 = function(container, width, height)
    {
        $DOP('img', container).css('width', '300px');
        $DOP('img', container).css('height', height);
        alert(width);
    }

    // -----> END IMAGE RESIZE

    // -----> BEGIN ITEM RESIZE

    this.ResizeItem = function(container, cw, ch, dw, dh, pos)
    {
        $DOP(container).width(cw);
        $DOP(container).height(ch);

        var defaultW = dw;
        var defaultH = dh;
        var currW = 0;
        var currH = 0;

        if (defaultW <= cw && defaultH <= ch)
        {
            currW = defaultW;
            currH = defaultH;
        }
        else
        {
            currH = ch;
            currW = (defaultW*ch)/defaultH;

            if (currW > cw)
            {
                currW = cw;
                currH = (defaultH*cw)/defaultW;
            }
        }

        $DOP(container).children().width(currW);
        $DOP(container).children().height(currH);

        if (pos.toLowerCase() == 'top'){this.TopItem(container, ch);}
        if (pos.toLowerCase() == 'bottom'){this.BottomItem(container, ch);}
        if (pos.toLowerCase() == 'left'){this.LeftItem(container, cw);}
        if (pos.toLowerCase() == 'right'){this.RightItem(container, cw);}
        if (pos.toLowerCase() == 'horizontal-center'){this.HCenterItem(container, cw);}
        if (pos.toLowerCase() == 'vertical-center'){this.VCenterItem(container, ch);}
        if (pos.toLowerCase() == 'center'){this.CenterItem(container, cw, ch);}
        if (pos.toLowerCase() == 'top-left'){this.TLItem(container, cw, ch);}
        if (pos.toLowerCase() == 'top-center'){this.TCItem(container, cw, ch);}
        if (pos.toLowerCase() == 'top-right'){this.TRItem(container, cw, ch);}
        if (pos.toLowerCase() == 'middle-left'){this.MLItem(container, cw, ch);}
        if (pos.toLowerCase() == 'middle-right'){this.MRItem(container, cw, ch);}
        if (pos.toLowerCase() == 'bottom-left'){this.BLItem(container, cw, ch);}
        if (pos.toLowerCase() == 'bottom-center'){this.BCItem(container, cw, ch);}
        if (pos.toLowerCase() == 'bottom-right'){this.BRItem(container, cw, ch);}
    }

    // -----> END ITEM RESIZE

// -----> BEGIN ITEM POSITIONS

    // -----> TOP
    this.TopItem = function(container, ch)
    {
        $DOP(container).height(ch);
        $DOP(container).children().css({'margin-top':0});
    }

    // -----> BOTTOM
    this.BottomItem = function(container, ch)
    {
        $DOP(container).height(ch);
        $DOP(container).children().css({'margin-top':ch-$DOP(container).children().height()});
    }

    // -----> LEFT
    this.LeftItem = function(container, cw)
    {
        $DOP(container).width(cw);
        $DOP(container).children().css({'margin-left':0});
    }

    // -----> RIGHT
    this.RightItem = function(container, cw)
    {
        $DOP(container).width(cw);
        $DOP(container).children().css({'margin-left':cw-$DOP(container).children().width()});
    }

    // -----> HORIZONTAL CENTER
    this.HCenterItem = function(container, cw)
    {
        $DOP(container).width(cw);
        $DOP(container).children().css({'margin-left':(cw-$DOP(container).children().width())/2});
    }

    // -----> VERTICAL CENTER
    this.VCenterItem = function(container, ch)
    {
        $DOP(container).width(ch);
        $DOP(container).children().css({'margin-top':(ch-$DOP(container).children().height())/2});
    }

    // -----> CENTER
    this.CenterItem = function(container, cw, ch)
    {
        this.HCenterItem(container, cw);
        this.VCenterItem(container, ch);
    }

    // -----> TOP-LEFT
    this.TLItem = function(container, cw, ch)
    {
        this.TopItem(container, ch);
        this.LeftItem(container, cw);
    }

    // -----> TOP-CENTER
    this.TCItem = function(container, cw, ch)
    {
        this.TopItem(container, ch);
        this.HCenterItem(container, cw);
    }

    // -----> TOP-RIGHT
    this.TRItem = function(container, cw, ch)
    {
        this.TopItem(container, ch);
        this.RightItem(container, cw);
    }

    // -----> MIDDLE-LEFT
    this.MLItem = function(container, cw, ch)
    {
        this.VCenterItem(container, ch);
        this.LeftItem(container, cw);
    }

    // -----> MIDDLE-RIGHT
    this.MRItem = function(container, cw, ch)
    {
        this.VCenterItem(container, ch);
        this.RightItem(container, cw);
    }

    // -----> BOTTOM-LEFT
    this.BLItem = function(container, cw, ch)
    {
        this.BottomItem(container, ch);
        this.LeftItem(container, cw);
    }

    // -----> BOTTOM-CENTER
    this.BCItem = function(container, cw, ch)
    {
        this.BottomItem(container, ch);
        this.HCenterItem(container, cw);
    }

    // -----> BOTTOM-RIGHT
    this.BRItem = function(container, cw, ch)
    {
        this.BottomItem(container, ch);
        this.RightItem(container, cw);
    }

// -----> END ITEM POSITIONS

// -----> BEGIN RANDOMIZE

    this.randomize = function(theArray)
    {
        theArray.sort(function(){return 0.5-Math.random()});
        return theArray;
    }

// -----> END RANDOMIZE
}
