﻿function slider(_isim,_bekleme,_hiz,_yukseklik,_genislik,_resimler,yapisacagi,zoom) {
	this.hiz=_hiz;
	this.isim=_isim;
	this.bekleme=_bekleme;
	this.yukseklik=_yukseklik;
	this.genislik=_genislik;
	this.resimler=_resimler;
	this.yuklenenler=0;
	this.ters=false;
	this.ustunde=false;
	this.container=jQuery('<div class="magnify" style="border:solid 1px #ccc;text-align:center;overflow:hidden;position:relative;display:none;z-index=2;width:'+_genislik+'px;height:'+_yukseklik+'px;"></div>').prependTo(jQuery('#'+yapisacagi)).hover(function() {
	    if (this.objesi.resimler.length>1) jQuery(this).find('div').fadeIn(300);
	    this.objesi.ustunde=true;
	    clearTimeout(this.objesi.timer);
	},function() {
		jQuery(this).find('div').fadeOut(300);
		this.objesi.ustunde=false;
		this.objesi.start();
	});
	this.container.get()[0].objesi=this;
	this.cevir=function() {
		this.container.find('img:gt(1)').each(function(){
			jQuery(this).parent().find('img:first').after(jQuery(this));
		});
		this.ters=!this.ters;
	}
	this.init=function() {
		this.container.html('<div style="z-index:2;position:absolute;width:25px;height:25px;left:5px;top:'+(this.yukseklik/2-13)+'px;background-image:url(\'resimler/prev.png\');cursor:pointer;display:none;" /><div style="z-index:2;position:absolute;width:25px;height:25px;right:5px;top:'+(this.yukseklik/2-13)+'px;background-image:url(\'resimler/next.png\');cursor:pointer;display:none;" />');
		this.container.find('div:first').click(function() {
			var a=jQuery(this).parent().get()[0].objesi;
			if (!a.ters) a.cevir();
			a.animate();
		}).end().find('div:last').click(function() {
			var a=jQuery(this).parent().get()[0].objesi;
			if (a.ters) a.cevir();
			a.animate();
		});
		for (i=0;i<this.resimler.length;i++) {
			jQuery('<img src="#"/>').appendTo(this.container).css('position','absolute').load(function(){
				$(this).removeAttr('width').removeAttr('height').css({ width: "", height: "" });
				if (this.height/jQuery(this).parent().height()>this.width/jQuery(this).parent().width()) jQuery(this).css('width',this.width*jQuery(this).parent().height()/this.height+'px').css('height',jQuery(this).parent().height()+'px').horizantalAlign().verticalAlign(); else jQuery(this).css('height',this.height*jQuery(this).parent().width()/this.width+'px').css('width',jQuery(this).parent().width()+'px').horizantalAlign().verticalAlign();
				jQuery(this).hide();
				this.parentNode.objesi.yuklenenler++;
				if (this.parentNode.objesi.yuklenenler==jQuery(this).parent().find('img').length) {
				    jQuery(this).parent().find('img').load().end().find('img:first').show().end().slideDown().get()[0].objesi.start();
				    eleman=this.parentNode.objesi;
				}
			});
		}
		for (i=0;i<this.resimler.length;i++) {
			this.container.find('img:eq('+i+')').attr('src',this.resimler[i]);
		}
		if (zoom) {
		    this.container.hover(function(event) {
		        yer=pos($('.magnify')[0]);
                $('<div id="buyutec" style="left:'+(yer.x+140)+'px;top:'+yer.y+'px;width:200px;height:200px;border:outline 2px #999999;background-color:#666666;position:absolute;background-repeat:no-repeat;border:solid 1px white;z-index:10;background-image:url('+$(this).find('img:first').attr('src')+');" />').appendTo($('body').find('#buyutec').remove().end());
                $('body').mousemove(function(event) {
                    pozisyon=pos(osman.container.find('img:first').get()[0]);
                    $('#buyutec').css({'background-position':((event.pageX?event.pageX:event.clientX)-pozisyon.x)*100/_genislik+'% '+((event.pageY?event.pageY:event.clientY)-pozisyon.y)*100/_yukseklik+'%'});
                });
            },function() {
                $('#buyutec').remove();
                $('body').unbind('mousemove');
            });
		}
	}
	this.start=function() {
	    if (this.resimler.length>1) {
		    clearTimeout(this.timer);
		    this.timer=setTimeout(this.isim+".tick();",this.bekleme);
		}
	}
	this.animate = function () {
	    $('#buyutec').remove();
	    if (!this.ters) {
	        this.container.find('img:first').yatayKay(this.genislik, this.hiz, function () {
	            jQuery(this).appendTo(jQuery(this).parent()).hide().horizantalAlign();
	        }).end().find('img:eq(1)').css('left', this.container.find('img:eq(1)').horizantalMerkez() - this.genislik + 'px').show().yatayKay(0, this.hiz, function () {
	            jQuery(this).horizantalAlign();
	        });
	    } else {
	        this.container.find('img:first').yatayKay(-this.genislik, this.hiz, function () {
	            jQuery(this).appendTo(jQuery(this).parent()).hide().horizantalAlign();
	        }).end().find('img:eq(1)').css('left', this.container.find('img:eq(1)').horizantalMerkez() + this.genislik + 'px').show().yatayKay(0, this.hiz, function () {
	            jQuery(this).horizantalAlign();
	        });
	    }
	}
	this.tick=function() {
		if (!this.ustunde) {
			this.animate();
			this.start();
		}
	}
}
jQuery.fn.yatayKay=function(miktar,hiz,callBack) {
	this.animate({left:this.horizantalMerkez()+miktar+'px'},hiz,callBack);
	return this;
}
jQuery.fn.dikeyKay=function(miktar,hiz,callBack) {
	this.animate({top:this.verticalMerkez()+miktar+'px'},hiz,callBack);
	return this;
}
jQuery.fn.horizantalMerkez=function() {
	return (this.parent().width()-parseFloat(this.css('width')))/2;
}
jQuery.fn.verticalMerkez=function() {
	return (this.parent().height()-parseFloat(this.css('height')))/2;
}
jQuery.fn.horizantalAlign=function() {
	this.css('left',this.horizantalMerkez()+'px');
	return this;
}
jQuery.fn.verticalAlign=function() {
	this.css('top',this.verticalMerkez()+'px');
	return this;
}
