var featuredcontentslider = {
    ajaxloadingmsg: '<div style="margin: 20px 0 0 20px"><img src="loading.gif" /> Fetching slider Contents. Please wait...</div>',
    bustajaxcache: true,
    enablepersist: false,
    settingcaches: {},
    jumpTo: function (b, a) {
        this.turnpage(this.settingcaches[b], a)
    },
    ajaxconnect: function (c) {
        var f = false;
        if (window.ActiveXObject) {
            try {
                f = new ActiveXObject("Msxml2.XMLHTTP")
            } catch (d) {
                try {
                    f = new ActiveXObject("Microsoft.XMLHTTP")
                } catch (d) {}
            }
        } else {
            if (window.XMLHttpRequest) {
                f = new XMLHttpRequest()
            } else {
                return false
            }
        }
        var a = c.contentsource[1];
        f.onreadystatechange = function () {
            featuredcontentslider.ajaxpopulate(f, c)
        };
        document.getElementById(c.id).innerHTML = this.ajaxloadingmsg;
        var b = (!this.bustajaxcache) ? "" : (a.indexOf("?") != -1) ? "&" + new Date().getTime() : "?" + new Date().getTime();
        f.open("GET", a + b, true);
        f.send(null)
    },
    ajaxpopulate: function (b, a) {
        if (b.readyState == 4 && (b.status == 200 || window.location.href.indexOf("http") == -1)) {
            document.getElementById(a.id).innerHTML = b.responseText;
            this.buildpaginate(a)
        }
    },
    buildcontentdivs: function (b) {
        var c = document.getElementById(b.id).getElementsByTagName("div");
				
				var thisWidth = c[0].offsetWidth;
				var i = 0;
        for (var a = 0; a < c.length; a++) {
						if(c[a].className == "contentdiv")
						{
							c[a].style.left = ((thisWidth * i++)/11).toFixed(4) + "em";
							
							if (this.css(c[a], "contentdiv", "check")) {
									b.contentdivs.push(c[a]);
									//c[a].style.display = "none";
							}
						}
        }
				document.getElementById(b.cid).style.width = 100*i + 100 + "%";
				document.getElementById(b.cid).style.left = "0em";
    },
    buildpaginate: function (j) {
        this.buildcontentdivs(j);
        var e = document.getElementById(j.id);
        var h = document.getElementById("paginate-" + j.id);
        var g = "";
        var b = j.toc;
        var a = j.nextprev;
        if (typeof b == "string" && b != "markup" || typeof b == "object") {
            for (var c = 1; c <= j.contentdivs.length; c++) {
                g += '<a href="#' + c + '" class="toc">' + (typeof b == "string" ? b.replace(/#increment/, c) : b[c - 1]) + "</a> "
            }
            g = (a[0] != "" ? '<a href="#prev" class="prev">' + a[0] + "</a> " : "") + g + (a[1] != "" ? '<a href="#next" class="next">' + a[1] + "</a>" : "");
            h.innerHTML = g
        }
        var d = h.getElementsByTagName("a");
        var f = 0;
        for (var c = 0; c < d.length; c++) {
            if (this.css(d[c], "toc", "check")) {
                if (f > j.contentdivs.length - 1) {
                    //d[c].style.display = "none";
                    continue
                }
                d[c].setAttribute("rel", ++f);
                d[c][j.revealtype] = function () {
                    featuredcontentslider.turnpage(j, this.getAttribute("rel"));
                    return false
                };
                j.toclinks.push(d[c])
            } else {
                if (this.css(d[c], "prev", "check") || this.css(d[c], "next", "check")) {
                    d[c].onclick = function () {
                        featuredcontentslider.turnpage(j, this.className);
                        return false
                    }
                }
            }
        }
        this.turnpage(j, j.currentpage, true);
        if (j.autorotate[0]) {
            h[j.revealtype] = function () {
                featuredcontentslider.cleartimer(j, window["fcsautorun" + j.id])
            };
            e.onclick = function () {
                featuredcontentslider.cleartimer(j, window["fcsautorun" + j.id])
            };
            j.autorotate[1] = j.autorotate[1] + (1 / j.enablefade[1] * 10);
            this.autorotate(j)
        }
    },
	
    urlparamselect: function (b) {
        var a = window.location.search.match(new RegExp(b + "=(\\d+)", "i"));
        return (a == null) ? null : parseInt(RegExp.$1)
    },
    turnpage: function (d, b, c) {

        var f = d.currentpage;
        var a = d.contentdivs.length;
        var e = (/prev/i.test(b)) ? f - 1 : (/next/i.test(b)) ? f + 1 : parseInt(b);
        e = (e < 1) ? a : (e > a) ? 1 : e;
        if (e == d.currentpage && typeof c == "undefined") {
            return
        }
        d.currentpage = e;
        //d.contentdivs[e - 1].style.zIndex = ++d.topzindex;
        this.cleartimer(d, window["fcsfade" + d.id]);
        d.cacheprevpage = d.prevpage;
        if (d.enablefade[0] == true) {
            d.curopacity = 0;
            this.fadeup(d);
        }
        if (d.enablefade[0] == false) {
            //d.contentdivs[d.prevpage - 1].style.display = "none";
						//document.getElementById(d.cid).style.left = "-"+d.contentdivs[e-1].style.left;
            d.onChange(d.prevpage, d.currentpage);
						this.animate(d);
        }
        //d.contentdivs[e - 1].style.visibility = "visible";
        //d.contentdivs[e - 1].style.display = "block";
        if (d.prevpage <= d.toclinks.length) {
            this.css(d.toclinks[d.prevpage - 1], "active", "remove")
        }
        if (e <= d.toclinks.length) {
            this.css(d.toclinks[e - 1], "active", "add")
        }
        d.prevpage = e;
        if (this.enablepersist) {
            this.setCookie("fcspersist" + d.id, e)
        }
    },
    setopacity: function (a, c) {
        var b = a.contentdivs[a.currentpage - 1];
        if (b.filters && b.filters[0]) {
            if (typeof b.filters[0].opacity == "number") {
                b.filters[0].opacity = c * 50
            } else {
                b.style.filter = "alpha(opacity=" + c * 50 + ")"
            }
        } else {
            if (typeof b.style.MozOpacity != "undefined") {
                b.style.MozOpacity = c
            } else {
                if (typeof b.style.opacity != "undefined") {
                    b.style.opacity = c
                }
            }
        }
        a.curopacity = c
    },
    fadeup: function (a) {
        if (a.curopacity < 1) {
            this.setopacity(a, a.curopacity + a.enablefade[1]);
            window["fcsfade" + a.id] = setTimeout(function () {
                featuredcontentslider.fadeup(a);
            }, 50)
        } else {
            if (a.cacheprevpage != a.currentpage) {
                //a.contentdivs[a.cacheprevpage - 1].style.display = "none"
            }
            a.onChange(a.cacheprevpage, a.currentpage)
        }
    },
		animate: function (a) {
				var thisLeft = (a.contentdivs[a.currentpage-1].style.left).replace('em','');
				if(thisLeft == 0)
				{
					thisLeft = '.01';
				}
				$('#'+a.cid+':not(:animated)').animate({ left: '-' + thisLeft + 'em' }, 500);
				$(a.contentdivs[a.prevpage-1]).removeClass('current');
				$(a.contentdivs[a.currentpage-1]).addClass('current');
    },
    cleartimer: function (a, b) {
        if (typeof b != "undefined") {
            clearTimeout(b);
            clearInterval(b);
            if (a.cacheprevpage != a.currentpage) {
                //a.contentdivs[a.cacheprevpage - 1].style.display = "none"
            }
        }
    },
    css: function (b, a, c) {
        var d = new RegExp("(^|\\s+)" + a + "($|\\s+)", "ig");
        if (c == "check") {
            return d.test(b.className)
        } else {
            if (c == "remove") {
                b.className = b.className.replace(d, "")
            } else {
                if (c == "add") {
                    b.className += " " + a
                }
            }
        }
    },
    autorotate: function (a) {
        window["fcsautorun" + a.id] = setInterval(function () {
            featuredcontentslider.turnpage(a, "next")
        }, a.autorotate[1])
    },
    getCookie: function (a) {
        var b = new RegExp(a + "=[^;]+", "i");
        if (document.cookie.match(b)) {
            return document.cookie.match(b)[0].split("=")[1]
        }
        return null
    },
    setCookie: function (a, b) {
        document.cookie = a + "=" + b
    },
    init: function (a) {
        var c = this.getCookie("fcspersist" + a.id) || 1;
        var b = this.urlparamselect(a.id);
        this.settingcaches[a.id] = a;
        a.contentdivs = [];
        a.toclinks = [];
        a.topzindex = 0;
        a.currentpage = b || ((this.enablepersist) ? c : 1);
        a.prevpage = a.currentpage;
        a.revealtype = "on" + (a.revealtype || "click");
        a.curopacity = 0;
        a.onChange = a.onChange ||
        function () {};
        if (a.contentsource[0] == "inline") {
            this.buildpaginate(a)
        }
        if (a.contentsource[0] == "ajax") {
            this.ajaxconnect(a)
        }
    }
};
