﻿var LiSwitcher = function() { }

LiSwitcher.prototype = {
    initialize: function(CONTROLS, VIEWPORT) {
        this.CONTROLS = CONTROLS || "div#liSwitcher-controls";
        this.PREVIOUS = $(this.CONTROLS).children("a#liSwitcher-previous");
        this.NEXT = $(this.CONTROLS).children("a#liSwitcher-next");
        this.VIEWPORT = VIEWPORT || "div#liSwitcher-viewport div#liSwitcher-viewport-inner";
        this.ITEMS = $(this.VIEWPORT).children("ul").children("li");
        this.INTERVAL = 10000;
        this.index = 0;
        var Scope = this;
        this.timer = setInterval(function() { Scope.nextImage(); }, this.INTERVAL);
        this.jsActive(this.CONTROLS, this.ITEMS);
        this.eventHandlers(this.PREVIOUS, this.NEXT);
    },

    jsActive: function(CONTROLS, ITEMS) {
        $(CONTROLS).show();
        $(ITEMS).not(":first").hide();
    },

    fadeIn: function(index) {
        this.ITEMS.eq(index).fadeIn(); //ClearTypeFadeIn({ speed:500, bgColor:'#000000'});
    },

    hide: function(index) {
        this.ITEMS.eq(index).hide();
    },

    nextImage: function() {
        this.hide(this.index);
        this.index++;
        if (this.index >= this.ITEMS.length) {
            this.index = 0;
        }
        this.fadeIn(this.index);
    },

    previousImage: function() {
        this.hide(this.index);
        this.index--;
        if (this.index <= -1) {
            this.index = this.ITEMS.length - 1;
        }
        this.fadeIn(this.index);

    },

    eventHandlers: function(PREVIOUS, NEXT) {
        var Scope = this;
        $(PREVIOUS).bind("click", function() {
            Scope.previousImage();
            clearInterval(Scope.timer);
            return false;
        });
        $(NEXT).bind("click", function() {
            Scope.nextImage();
            clearInterval(Scope.timer);
            return false;
        });
    }

};


var liSwitcher = new LiSwitcher();
$(function() {
    liSwitcher.initialize();
});
/*jquery de olan prototypeların üzerine yaz*/
jQuery.fn.fadeIn = function(speed, callback) {
    return this.animate({opacity: 'show'}, speed, function() {
    if (jQuery.browser.msie)
        this.style.removeAttribute('filter');
        if (jQuery.isFunction(callback))
            callback();
    });
};
jQuery.fn.fadeOut = function(speed, callback) {
    return this.animate({opacity: 'hide'}, speed, function() {
    if (jQuery.browser.msie)
        this.style.removeAttribute('filter');
        if (jQuery.isFunction(callback))
            callback();
    });
};
jQuery.fn.fadeTo = function(speed,to,callback) {
    return this.animate({opacity: to}, speed, function() {
    if (to == 1 && jQuery.browser.msie)
        this.style.removeAttribute('filter');
        if (jQuery.isFunction(callback))
            callback();
    });
};
/*jquery de olan prototypeların üzerine yaz end*/
//-------------------------------------------------------------------------------------------------------
// ClearTypeFadeTo / ClearTypeFadeIn / ClearTypeFadeOut
//
// Custom fade in and fade out functions for jQuery that will work around
// IE's bug with bold text in elements that have opacity filters set when
// also using Window's ClearType text rendering.
//
// New Parameter:
// bgColor    The color to set the background if none specified in the CSS (default is '#fff')
//
// Examples:
// $('div').ClearTypeFadeIn({ speed: 1500 });
// $('div').ClearTypeFadeIn({ speed: 1500, bgColor: '#ff6666', callback: myCallback });
// $('div').ClearTypeFadeOut({ speed: 1500, callback: function() { alert('Fade Out complete') } });
//
// Notes on the interaction of ClearType with DXTransforms in IE7
// http://blogs.msdn.com/ie/archive/2006/08/31/730887.aspx


(function($) {
    $.fn.ClearTypeFadeTo = function(options) {
        if (options)
            $(this)
				.show()
				.each(function() {
				    if (jQuery.browser.msie) {
				        // Save the original background color
				        $(this).attr('oBgColor', $(this).css('background-color'));
				        // Set the bgColor so that bold text renders correctly (bug with IE/ClearType/bold text)
				        $(this).css({ 'background-color': (options.bgColor ? options.bgColor : '#000') })
				    }
				})
				.fadeTo(options.speed, options.opacity, function() {
				    if (jQuery.browser.msie) {
				        // ClearType can only be turned back on if this is a full fade in or
				        // fade out. Partial opacity will still have the problem because the
				        // filter style must remain. So, in the latter case, we will leave the
				        // background color and 'filter' style in place.
				        if (options.opacity == 0 || options.opacity == 1) {
				            // Reset the background color if we saved it previously
				            $(this).css({ 'background-color': $(this).attr('oBgColor') }).removeAttr('oBgColor');
				            // Remove the 'filter' style to restore ClearType functionality.
				            $(this).get(0).style.removeAttribute('filter');
				        }
				    }
				    if (options.callback != undefined) options.callback();
				});
    };

    $.fn.ClearTypeFadeIn = function(options) {
        if (options)
            $(this)
				.css({ opacity: 0 })
				.ClearTypeFadeTo({ speed: options.speed, opacity: 1, callback: options.callback });
    };

    $.fn.ClearTypeFadeOut = function(options) {
        if (options)
            $(this)
				.css({ opacity: 1 })
				.ClearTypeFadeTo({ speed: options.speed, opacity: 0, callback: options.callback });
    };
})(jQuery);

