function fixpng(B){
    if (!jQuery.browser.msie) {
        return
    }
    for (var A = 0; A < B.length; A++) {
        if (B[A].complete) {
            jQuery(B[A]).ifixpng()
        }
        else {
            jQuery(B[A]).load(function(){
                jQuery(this).ifixpng()
            })
        }
    }
}

var Slideshow = {
    IMG_ID_PREFIX: "slide_",
    AUTOSLIDE_TIMEOUT: 4000,
    ANIMATION_DURATION: 900,
    source: null,
    container: null,
    currentSlide: 0,
    images: null,
    windowWidth: 0,
    windowHeight: 0,
    autoSlideTimer: null,
    sliding: false,
	randomNum: 0,
    init: function(D){
        Slideshow.source = new Array("slider_8202","slider_Default", "slider_Halo_Starry_Night", "slider_Halo_Wars", "slider_WB");
        Slideshow.container = jQuery('<div id="slides_container" style="position: absolute; top: 90px; left: 0; overflow: hidden; background: #000; z-index:-1;"/>').appendTo("body").click(Slideshow.stop);
        //Slideshow.container = document.getElementById("slides_container");
        Slideshow.images = new Array();
        for (var B = 0; B < Slideshow.source.length; B++) {
            var A = new Object();
            A.div = jQuery('<div class="slide"/>');
            A.img = jQuery('<img id="' + Slideshow.IMG_ID_PREFIX + B + '" style="position:absolute"/>');
            //A.info = jQuery('<div class="slideshowInfo"><img class="slideTypeImg"/><span class="slideTitle"/><br/><span class="slideDate"/></div>');
            A.height = 0;
            A.width = 0;
            A.loaded = false;
            A.div.append(A.img).append(A.info);
            A.img.load(Slideshow.loadCallback);
            Slideshow.images[B] = A;
            Slideshow.container.append(A.div);
            A.div.hide();
        }
        Slideshow.currentSlide = D;
        Slideshow.loadImage(D);
        Slideshow.loadImage(Slideshow.nextIndex(D));
        jQuery(window).bind("resize", function(){
            var E = null;
            if (E == null) {
                E = window.setTimeout(function(){
                    Slideshow.resize();
                    E = null
                }, 500)
            }
        });
        jQuery("#slides_container").bind("mousewheel", function(E, F){
            if (F < 0) {
                jQuery("#btnNext").click()
            }
            else {
                jQuery("#btnPrev").click()
            }
            return false
        });
        jQuery(window).keyup(function(E){
            if (E.keyCode == 37) {
                jQuery("#btnNext").click()
            }
            else {
                if (E.keyCode == 39) {
                    jQuery("#btnPrev").click()
                }
            }
            return false
        });
        Slideshow.resize();
        if (jQuery.browser.mozilla) {
            window.setInterval(function(){
                window.scrollTo(0, 0)
            }, 50)
        }
    },
    startSlideShow: function(){
        Slideshow.currentSlide = Math.ceil(Slideshow.source.length * Math.random()) - 1;
        Slideshow.start("next")
    },
    start: function(D, C){
        if (Slideshow.autoSlideTimer != null) {
            return
        }
        //var A = Slideshow.currentSlide;
        Slideshow.loadImage(0);
        Slideshow.loadImage(1);
        Slideshow.loadImage(2);
        Slideshow.loadImage(3);		Slideshow.loadImage(4);
        function B(){
            if (Slideshow.images[0].loaded) {
                //Slideshow.autoSlideTimer = window.setInterval(Slideshow[D], Slideshow.AUTOSLIDE_TIMEOUT);
                if (C) {
                    Slideshow.currentSlide = Slideshow.prevIndex(Slideshow.currentSlide)
                }
                Slideshow[D]()
            }
            else {
                window.setTimeout(B, 20)
            }
        }
        B()
    },
    stop: function(){
        if (Slideshow.autoSlideTimer != null) {
            window.clearInterval(Slideshow.autoSlideTimer);
            Slideshow.autoSlideTimer = null
        }
    },
    loadImage: function(A){
        var C = Slideshow.source[A];
        var B = Slideshow.images[A];
        if (!B.loaded) {
            B.img.attr("src", "images/Sliders/" + C + ".jpg");
        }
    },
    loadCallback: function(){
        var B = this.id.substring(Slideshow.IMG_ID_PREFIX.length);
        var A = new Image();
        A.onload = function(){
            Slideshow.images[B].height = A.height;
            Slideshow.images[B].width = A.width;
            Slideshow.images[B].loaded = true
        };
        A.src = this.src
    },
	generateRandomNum: function() {
		Slideshow.randomNum = Math.floor(Math.random() * 10000000);
	},
    slide: function(B, A){
        if (Slideshow.sliding || !Slideshow.images[B].loaded) {
            return
        }
        Slideshow.sliding = true;
        Slideshow.images[B].div.css("left", (Slideshow.windowWidth * (A ? 2 : 0)) + "px").css("z-index", 2).show();
        //Slideshow.images[B].div.css("left", "1440px").css("z-index", 2).show();
		Slideshow.resizeImage(B);
		//alert("Slideshow.windowWidth = " + Slideshow.windowWidth);
		//alert("image B width = " + parseInt(Slideshow.images[B].width));
		//alert("Slideshow.images[" + B + "].div.css('width') = " + Slideshow.images[B].div.css("width"));
		//alert("((Slideshow.windowWidth - 1440) / 2) : " + ((Slideshow.windowWidth - 1440) / 2) + "px");
        Slideshow.images[B].div.animate(
            {left: Slideshow.windowWidth + ((Slideshow.windowWidth - 1440) / 2)},
			Slideshow.ANIMATION_DURATION, "easeInOutQuint", function(){
			//alert("Slideshow.images[" + B + "].div.css('left') = " + Slideshow.images[B].div.css("left"));
            Slideshow.images[Slideshow.currentSlide].div.hide();
            Slideshow.images[B].div.css("z-index", 1);
            Slideshow.currentSlide = B;
            Slideshow.sliding = false;
            //var C = Slideshow.source[Slideshow.currentSlide];
			
			//if (C.slideType == -1) {
            //	jQuery("#currentslide").html('This is: <a href="' + C.slideUrl + '">' + C.slideTitle + "</a>").show()
            //}
            //else {
            //    jQuery("#currentslide").hide()
            //}
			
            //Slideshow.images[Slideshow.currentSlide].div.find(".slideTypeImg").ifixpng()
        })
    },
    prev: function(){
        var A = Slideshow.prevIndex(Slideshow.currentSlide);
        Slideshow.slide(A, true);
        Slideshow.loadImage(Slideshow.prevIndex(A))
    },
    prevIndex: function(A){
        return A == 0 ? Slideshow.source.length - 1 : A - 1
    },
    next: function(){
        var A = Slideshow.nextIndex(Slideshow.currentSlide);
        Slideshow.slide(A, true);
        Slideshow.loadImage(Slideshow.nextIndex(A))
    },
    specific: function(A){
        Slideshow.slide(A, true);
        //Slideshow.loadImage(Slideshow.nextIndex(A))
    },	
    nextIndex: function(A){
        return (A + 1) % Slideshow.source.length
    },
    resizeImage: function(A){
        var C = Slideshow.images[A];
		//alert("setting div width to: " + Slideshow.windowWidth);
        //C.div.css("width", (Slideshow.windowWidth * 3) + "px");
        C.div.css("width", "1440px");
        var B = Math.ceil(C.width / C.height * Slideshow.windowHeight);
        var D = Math.max(C.width, Slideshow.windowWidth);
        B = isNaN(B) ? 0 : B;
        D = isNaN(D) ? 0 : D;
        C.img.css("width", "1440px")
        C.img.css("left", "0px")
		//C.img.css("width", Math.max(B, D) + "px")
    },
    resize: function(){
        Slideshow.windowWidth = jQuery(window).innerWidth();
        Slideshow.windowHeight = jQuery.browser.mozilla ? window.innerHeight : jQuery(window).innerHeight();
        Slideshow.container.width(Slideshow.windowWidth * 2);
        Slideshow.container.height(Slideshow.windowHeight);
        Slideshow.container.css("left", "-" + Slideshow.windowWidth + "px");
        Slideshow.resizeImage(Slideshow.currentSlide);
        Slideshow.images[Slideshow.currentSlide].div.css("left", Slideshow.windowWidth + ((Slideshow.windowWidth - 1440) / 2) + "px")
    },
    formatDate: function(A){
        try {
            if (isNaN(Date.parse(A))) {
                throw "illegal argument"
            }
            currentDate = new Date();
            postedDate = new Date(Date.parse(A));
            offset = currentDate.getTime() - postedDate.getTime();
            if (offset < 2 * 24 * 60 * 60 * 1000 & offset > 1 * 24 * 60 * 60 * 1000) {
                return "yesterday"
            }
            days = Math.round(offset / (24 * 60 * 60 * 1000));
            return days + " day" + (days > 1 ? "s" : "") + " ago"
        } 
        catch (B) {
            return "recently"
        }
    }
};

function SwitchBackground(image_location)
{	

	switch (image_location) {
		case "slider_Default": Slideshow.specific(1); break;		case "slider_Halo_Starry_Night": Slideshow.specific(2); break;
		case "slider_Halo_Wars": Slideshow.specific(3); break;
		case "slider_WB": Slideshow.specific(4); break;
		default: Slideshow.specific(0); //"slider_8202"
	}

};