/* Plugin SEPARATOR */
(function($) {
    $.fn.separator = function(separator) {
        var that = this;
        this.each(function(i) {
            if (++i !== that.length) {
                $(this).html($(this).html() + separator);
            }
        });
    }
})(jQuery);

function wrapHeight() {
    jQuery('#footer').height('auto');
    var headerHeight = jQuery('#header').height();
    var mainHeight = jQuery('#main').height();
    var footerHeight = jQuery('#footer').height();
    var contentHeight = headerHeight + mainHeight + footerHeight;
    var windowHeight = jQuery(window).height();
    if (contentHeight + 32 + 5 < windowHeight) {
        jQuery('#footer').css('height', function() {
            return jQuery(window).height() - headerHeight - mainHeight - 32 - 5;
        });
    }
};

function selectedLink() {
    jQuery('.selected').each(function() {
        jQuery(this).bind('click', function(e) {
            //e.preventDefault();
        });
    });
};

function sequenceElement() {
    var args = Array.prototype.slice.call(arguments);
    jQuery(args).each(function() {
        jQuery(this + ':first-child').addClass('first-elm');
        jQuery(this + ':last-child').addClass('last-elm');
        jQuery(this + ':nth-child(odd)').addClass('odd-elm');
        jQuery(this + ':nth-child(even)').addClass('even-elm');
    });
};

var imgOver = {
    init: function() {
        this.exe();
        if (jQuery.browser.msie) { this.forIE() };
    },
    exe: function() {
        var that = this;
        jQuery('img, input').each(function() {
            if (jQuery(this).attr('src')) {
                jQuery(this).hover(
                    function() { that.srcReplace(this, '_off', '_on') },
                    function() { that.srcReplace(this, '_on', '_off') }
                );
            };
        });
    },
    forIE: function() {
        var that = this;
        jQuery('span').each(function() {
            if (jQuery(this).attr('style')) {
                jQuery(this).hover(
                    function() { that.srcReplaceForIE(this, '_off', '_on') },
                    function() { that.srcReplaceForIE(this, '_on', '_off') }
                );
            }
        });
    },
    srcReplace: function(elm, suffix1, suffix2) {
        var file = elm.src.match(/^(.*)?(\.[^.]*$)/i);
        if (file) {
            if (file[1].lastIndexOf(suffix1) > -1) {
                elm.src = file[1].replace(suffix1, suffix2) + file[2];
            }
        };
    },
    srcReplaceForIE: function(elm, suffix1, suffix2) {
        var styleStr = jQuery(elm).attr('style');
        var s = /src=\"(.*)\"/.exec(styleStr);
        if (s) {
            s = s[1];
            var file = s.match(/^(.*)?(\.[^.]*$)/i);
            if (file) {
                if (file[1].lastIndexOf(suffix1) > -1) {
                    var beforeStr = file[1];
                    var path = file[1].replace(suffix1, suffix2);
                    var newPath = styleStr.replace(beforeStr, path);
                    jQuery(elm).attr('style', newPath);
                }
            }
        };
    }
};

function topSWF() {
    var objectData = (jQuery.browser.msie) ? '' : 'data="/top.swf"';
    jQuery('#swfcontent').html('<object type="application/x-shockwave-flash"' + objectData + ' width="928" height="496" id="dovetop"><param name="movie" value="/top.swf" /><param name="src" value="/top.swf" /><param name="wmode" value="transparent" /><param name="menu" value="false" /></object>');
};

function pagetopBtn() {
    jQuery('.btn_pagetop a').bind('click', function(e) {
        e.preventDefault();
        jQuery.scrollTo('#pagetop', 1000, {easing:'easeOutQuart'});
    });
};

function anchorWithinAPage(node) {
    jQuery(node).click(function(e) {
        e.preventDefault();
        var target = /(#[A-Za-z0-9_-]+)/.exec(this.href);
        if (target) {
            jQuery.scrollTo(jQuery(target[0]), 1000, {easing:'easeOutQuart'});
        }
        //alert(this);
    });
}

function geckoTextarea() {
    if (jQuery.browser.mozilla) {
        jQuery('textarea').css('font-size', '0.95em');
    }
};

function productsListOver() {
    var exe = function(elm, obj, n) {
        var imgObj = jQuery('img', obj)[0];
        var spanObj = jQuery('span', obj)[0];
        jQuery(elm).hover(
            function() { over(imgObj, spanObj, n) },
            function() { over(imgObj, spanObj, '0px') }
        );
    };
    var over = function(obj, objForIE, n) {
        if (jQuery.browser.msie && jQuery.browser.version <= 6) {
            jQuery(objForIE).css('top', n);
        } else {
            jQuery(obj).css('top', n);
        }
    };
    if (jQuery('#products_list').length !== 0) {
        jQuery('ul#products > li > a').each(function(i, elm) {
            exe(elm, jQuery(this).next(), '-38px');
        });
        jQuery('ul#products h3 > a').each(function(i, elm) {
            exe(elm, jQuery(this), '-38px');
        });
    };
}


