/*
 * cording helper v1.0.2
 * Copyright (c) 2011 Smart Desgin Association Co.,Ltd.
 * http://www.s-design.jp/
 */
(function($){
    var rolloverSuffix = '_on';
    
    $.fn.imgRollover = function(options){
        return this.each(function(){
            $.imgRollover($(this), options);
        });
    };
    $.imgRollover = function(container, options){
        var settings = {
            'inspeed': 0,
            'outspeed': 0,
            'ineasing': 'swing',
            'outeasing': 'swing'
        };
        if (options) 
            $.extend(settings, options);
        
        var src = container.children('img').attr('src');
        if (typeof src != 'undefined') {
            container.css({
                position: "relative"
            }).before("<img style='position:absolute;' src=" + src.substring(0, src.lastIndexOf('.')) + rolloverSuffix + src.substring(src.lastIndexOf('.'), src.length) + " alt='' />");
            
            if (settings.inspeed == 0 && settings.inspeed == 0) 
                container.children('img').hover(function(){
                    $(this).css({
                        'opacity': '0'
                    });
                }, function(){
                    $(this).css({
                        'opacity': '1'
                    });
                });
            else 
            	container.delegate('img', {
        			mouseenter: function() {
        				var current = $(this).attr('class');
	                    if (current != 'current') {
	        				$(this).stop().animate({
	                        	'opacity': '0'
	                    	}, settings.inspeed, settings.outeasing);
	                    }
                },
        			mouseleave: function() {
        				var current = $(this).attr('class');
        				if (current != 'current') {
	        				$(this).stop().animate({
	                        	'opacity': '1'
	                    	}, settings.outspeed, settings.outeasing);
	                    }
        			}
				});
        }
    };
    
    
    $.fn.alphaRollover = function(options){
        return this.each(function(){
            $.alphaRollover($(this), options);
        });
    };
    $.alphaRollover = function(container, options){
        var settings = {
            'inspeed': 0,
            'outspeed': 0,
            'ineasing': 'swing',
            'outeasing': 'swing',
            'opacity': 0.7
        };
        if (options) 
            $.extend(settings, options);
        
        if (settings.inspeed == 0 && settings.inspeed == 0) 
            container.children('img').hover(function(){
                $(this).css({
                    'opacity': settings.opacity
                });
            }, function(){
                $(this).css({
                    'opacity': '1'
                });
            });
        else 
            container.children('img').hover(function(){
                $(this).stop().animate({
                    'opacity': settings.opacity
                }, settings.inspeed, settings.outeasing);
            }, function(){
                $(this).stop().animate({
                    'opacity': '1'
                }, settings.outspeed, settings.outeasing);
            });
    };
    
    
    $.fn.brightRollover = function(options){
        return this.each(function(){
            $.brightRollover($(this), options);
        });
    };
    $.brightRollover = function(container, options){
        var settings = {
            'inspeed': 300,
            'outspeed': 600,
            'ineasing': 'swing',
            'outeasing': 'swing',
            'opacity': 0.7
        };
        if (options) 
            $.extend(settings, options);
        
        container.children('img').hover(function(){
            $(this).stop().css({
                'opacity': 0.2
            })
            $(this).animate({
                'opacity': settings.opacity
            }, settings.inspeed, settings.outeasing);
        }, function(){
            $(this).stop().animate({
                'opacity': '1'
            }, settings.outspeed, settings.outeasing);
        });
    };
    
    $.fn.alphaToObj = function(options){
        return this.each(function(){
            $.alphaToObj($(this), options);
        });
    };
    $.alphaToObj = function(container, options){
        var settings = {
            'speed': 1000,
            'ineasing': 'swing',
            'delay': 0
        };
        if (options) 
            $.extend(settings, options);
        
        container.show().css({
            'opacity': '0'
        }).delay(settings.delay).animate({
            'opacity': '1'
        }, settings.speed, settings.outeasing);
    };
    
    $.fn.smoothScroll = function(options){
        return this.each(function(){
            $.smoothScroll($(this), options);
        });
    };
    $.smoothScroll = function(container, options){
        var settings = {
            'speed': 1000,
            'easing': 'swing'
        };
        if (options) 
            $.extend(settings, options);
        
        container.click(function(e){
            e.preventDefault();
            var scrollArr = $(this).attr('href').split("_");
            var pos = $(scrollArr[0]).offset();
            var ty = Math.min(pos.top, ($(document).height() - $(window).height()));
            $('html,body').animate({
                scrollTop: ty
            }, settings.speed, settings.outeasing);
        });
        
        
    };
    
    
    
    
})(jQuery);

