/* =========================================================

// jquery.tyslide.js

// Datum: 2010-03-19
// Firma: tyclipso.net | Denis Bartelt
// Author: Ron Kappler / Michael Betka
// Mail: tyconauts@tyclipso.net
// Web: http://www.tyclipso.net
// ========================================================= */
(function($) {

    $.fn.tyslide = function(options) {
        return this.each(function() {   
        	var instance = new tyslide(this, options);
        	$(this).data('tyslide', instance);
        });
    };

    var tyslide = function(container, options) {
        var inst = this;

        inst.settings = {
        	'speed': 700,
            'type': 'vertical',
			'slideon' : '#tyslideul',
			'upspritepos' : '0 0',
			'upspriteposia' : '-240px 0',
			'downspritepos' : '-120px 0',
			'downspriteposia' : '-360px 0',
			'tyslideeasing' : 'swing'
        };
		
        inst.container = container;
        inst.rowHeight = 0;
        inst.rowCount = 1;
        inst.containerHeight = 0;
       	inst.items = null;
       	inst.marginTop = 0;
       	
        inst.init = function(options) {
        	$(inst.container).find('a.tydown').unbind('click');
			$(inst.container).find('a.tyup').unbind('click');
			
			if (options) $.extend(inst.settings, options);
	        
	        $(inst.container).find('ul'+inst.settings.slideon+' div.fixfloat').remove();
	        $(inst.container).find('ul'+inst.settings.slideon).append('<div class="fixfloat"/>');
	                
			inst.items = $(inst.container).find('ul'+inst.settings.slideon).children('li');
			
    		if (location.href.indexOf('testMode') >= 0) {
    			debugger;
    		}
			var firstItem = $(inst.items.eq(0));
       		if (firstItem.length) {
       			inst.rowHeight = firstItem.outerHeight();
       			inst.containerHeight = $(inst.container).find('ul'+inst.settings.slideon).height();
				inst.rowCount = Math.ceil((inst.containerHeight / inst.rowHeight));
       		} else {
       			return false;
       		}
       		
       		var margins = $(inst.container).find('ul'+inst.settings.slideon).margin();
			inst.marginTop = margins.top;
			
			inst.easing = inst.settings.tyslideeasing;
			if( $.easing.def ) { inst.easing = inst.settings.tyslideeasing; }
			else { tyslideeasing = ''; }
			
			if (inst.marginTop == 0) $(inst.container).find('a.tyup').css('background-position', inst.settings.upspriteposia ); 
			if (inst.marginTop == -((inst.rowCount-1)*inst.rowHeight)) $(inst.container).find('a.tydown').css('background-position', inst.settings.downspriteposia ); 
			
	        $(inst.container).find('a.tydown').bind('click', inst.slideDown );
			$(inst.container).find('a.tyup').bind('click', inst.slideUp );
		}
		
		inst.slideDown = function() { 
			if ( inst.marginTop > -( inst.rowCount-1) * inst.rowHeight ) {
				inst.marginTop = ( inst.marginTop - inst.rowHeight );
				var goto = inst.marginTop + "px";
				$(inst.container).find('ul'+inst.settings.slideon).animate({
					  "marginTop" : goto
				}, inst.settings.speed,inst.easing);
				if (inst.marginTop <= -((inst.rowCount-1)*inst.rowHeight)) $(inst.container).find('a.tydown').css('background-position', inst.settings.downspriteposia ); 
				if (inst.marginTop <= -inst.rowHeight ) $(inst.container).find('a.tyup').css('background-position', inst.settings.upspritepos ); 
			}
			return false;
		}
    	
		inst.slideUp = function() { 
			if ( inst.marginTop <= -( inst.rowHeight ) ) {
				inst.marginTop = ( inst.marginTop + inst.rowHeight );
				var goto = inst.marginTop + "px";
				$(inst.container).find('ul'+inst.settings.slideon).animate({
					  "marginTop" : goto
				},  inst.settings.speed,inst.easing);
				if (inst.marginTop == 0) $(inst.container).find('a.tyup').css('background-position', inst.settings.upspriteposia ); 
				if (inst.marginTop >= -((inst.rowCount-1) * inst.rowHeight)) $(inst.container).find('a.tydown').css('background-position', inst.settings.downspritepos ); 
			}
			return false;
		}
		
		this.init(options);
		
		return this;
    };
})(jQuery);
