﻿(function($) {
	$.fn.customFadeIn = function(speed, callback) {
		$(this).fadeIn(speed, function() {
			if(!$.support.opacity)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeOut = function(speed, callback) {
		$(this).fadeOut(speed, function() {
			if(!$.support.opacity)
				$(this).get(0).style.removeAttribute('filter');
			if(callback != undefined)
				callback();
		});
	};
	$.fn.customFadeTo = 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);

function imageGallery(){
	if($(".imageGalleryContainer ul li").length <= 0){
		$(".nextBtn").hide();
	};
	$(".imageGalleryContainer ul li:eq(0)").customFadeIn(1000);

	var imageList = [$(".imageGalleryContainer ul li").length];
	var imageCount = 0;
	var currentImage = $(".imageGalleryContainer ul li:eq(0)");
    if (imageList <= 1)
    {
        $(".nextBtn").hide();
        $(".prevBtn").hide();
    }
		
	$('.nextBtn').click(function() {
		$(currentImage).hide();
		$(".prevBtn").show();
		imageCount++;
		if(imageCount >= imageList){
		    imageCount = 0;		   
		} 
		$(".imageGalleryContainer ul li:eq(" + imageCount + ")").customFadeIn(1000);
		currentImage = $(".imageGalleryContainer ul li:eq(" + imageCount + ")");
		if (typeof sIFR == "function") {
		    sIFR.replaceElement(named({ sSelector: ".galleryCaption", sFlashSrc: "/web/design/sifr/baskesbi.swf", sColor: "#ffffff", sWmode: "transparent", sFlashVars: "offsetTop=0", sFlashVars: "offsetBottom=0" }));
		};
	});

	$('.prevBtn').click(function() {
		$(currentImage).hide();		
		if(imageCount <= 0){
		    imageCount = (imageList-1);
		}
		else
		{
		    imageCount--;
		}
		$(".imageGalleryContainer ul li:eq(" + imageCount + ")").customFadeIn(1000);
		currentImage = $(".imageGalleryContainer ul li:eq(" + imageCount + ")");
		if (typeof sIFR == "function") {
		    sIFR.replaceElement(named({ sSelector: ".galleryCaption", sFlashSrc: "/web/design/sifr/baskesbi.swf", sColor: "#ffffff", sWmode: "transparent", sFlashVars: "offsetTop=0", sFlashVars: "offsetBottom=0" }));
		};
	});
	
	
	$(".prevBtn, .nextBtn, .imageGalleryContainer").hover(function () {
          $(".imageGalleryContainer ul li div").addClass("captionHover");
        }, function () {
          $(".imageGalleryContainer ul li div").removeClass("captionHover");
        });
}
