$(function(){
		   
	var urls = new Array('images/home/homepage-bkgd-1.jpg','images/home/homepage-bkgd-2.jpg','images/home/homepage-bkgd-3.jpg');

	function getRandomImage(){
		
		if (document.images){
				
		var imgs = new Array(urls.length);
	
			for(var i=0; i<imgs.length; i++){
		
			var img = new Image();
			img.src = urls[i];
			imgs[i] = img;
			}
	
		var rn = Math.floor(Math.random()*urls.length);
	
		$("#contentTop.home").css({background:'url(' + imgs[rn].src + ')'});
		}
}

getRandomImage();		   
		   
	
	(function ($) {
    $.fn.jCarouselLite = function (o) {
        o = $.extend({
          	btnNext: ".next",
        	btnPrev: ".prev",
        	visible: 5,
            btnGo: null,
            mouseWheel: false,
            auto: null,
            speed: 750,
            easing: null,
            vertical: false,
            circular: true,
            start: 0,
            scroll: 1,
            beforeStart: null,
            afterEnd: null
        }, o || {});
        return this.each(function () {
            var b = false,
                animCss = o.vertical ? "top" : "left",
                sizeCss = o.vertical ? "height" : "width";
            var c = $(this),
                ul = $("ul", c),
                tLi = $("li", ul),
                tl = tLi.size(),
                v = o.visible;
            if (o.circular) {
                ul.prepend(tLi.slice(tl - v - 1 + 1).clone()).append(tLi.slice(0, v).clone());
                o.start += v
            }
            var f = $("li", ul),
                itemLength = f.size(),
                curr = o.start;
            c.css("visibility", "visible");
            f.css({
                overflow: "hidden",
                float: o.vertical ? "none" : "left"
            });
            ul.css({
                margin: "0",
                padding: "0",
                position: "relative",
                "list-style-type": "none",
                "z-index": "1"
            });
            c.css({
                overflow: "hidden",
                position: "relative",
                "z-index": "2",
                left: "0px"
            });
            var g = o.vertical ? height(f) : width(f);
            var h = g * itemLength;
            var j = g * v;
            f.css({
                width: f.width(),
                height: f.height()
            });
            ul.css(sizeCss, h + "px").css(animCss, -(curr * g));
            c.css(sizeCss, j + "px");
			
		
			// Mods
			
			$(document).keydown(function(e){
			if (e.keyCode == 37){
			return go(curr - o.scroll)	}
			});
			
			$(document).keydown(function(e){
			if (e.keyCode == 39){
			return go(curr + o.scroll)	}
			});
					
			/*	Amendment made 14.09.11		
			
			$('.slider ul li a span.capOverlay').fadeTo(1,'0.8');
										   
			$('.slider ul li a').hover(function(){
			
				var title = $(this).attr("title");
				this.tip = this.title;
				this.title = "";	
			
				$('span.capOverlay', this).stop().animate({marginTop:'0px'},250);
				$('span.con', this).stop().animate({marginTop:'0px'},250);
				},function(){
					
				this.title = this.tip;
				
				$('span.capOverlay', this).stop().animate({marginTop:'80px'},250);
				$('span.con', this).stop().animate({marginTop:'80px'},250);
			});
			*/
			
			$('.slider ul li a').hover(function(){
			
				var title = $(this).attr("title");
				this.tip = this.title;
				this.title = "";	
			
				$('span.capOverlay', this).css({backgroundColor:'#009933'});
				$('img', this).css({border:'1px solid #009933'});
				},function(){
					
				this.title = this.tip;
				
				$('span.capOverlay', this).css({backgroundColor:'#000000'});
				$('img', this).css({border:'1px solid #000000'});
			});
			
			// End of Mods
			
            if (o.btnPrev) $(o.btnPrev).click(function () {
                return go(curr - o.scroll)
            });
            if (o.btnNext) $(o.btnNext).click(function () {
                return go(curr + o.scroll)
            });
            if (o.btnGo) $.each(o.btnGo, function (i, a) {
                $(a).click(function () {
                    return go(o.circular ? o.visible + i : i)
                })
            });
            if (o.mouseWheel && c.mousewheel) c.mousewheel(function (e, d) {
                return d > 0 ? go(curr - o.scroll) : go(curr + o.scroll)
            });
            if (o.auto) setInterval(function () {
                go(curr + o.scroll)
            }, o.auto + o.speed);

            function vis() {
                return f.slice(curr).slice(0, v)
            };

            function go(a) {
                if (!b) {
                    if (o.beforeStart) o.beforeStart.call(this, vis());
                    if (o.circular) {
                        if (a <= o.start - v - 1) {
                            ul.css(animCss, -((itemLength - (v * 2)) * g) + "px");
                            curr = a == o.start - v - 1 ? itemLength - (v * 2) - 1 : itemLength - (v * 2) - o.scroll
                        } else if (a >= itemLength - v + 1) {
                            ul.css(animCss, -((v) * g) + "px");
                            curr = a == itemLength - v + 1 ? v + 1 : v + o.scroll
                        } else curr = a
                    } else {
                        if (a < 0 || a > itemLength - v) return;
                        else curr = a
                    }
                    b = true;
                    ul.animate(animCss == "left" ? {
                        left: -(curr * g)
                    } : {
                        top: -(curr * g)
                    }, o.speed, o.easing, function () {
                        if (o.afterEnd) o.afterEnd.call(this, vis());
                        b = false
                    });
                    if (!o.circular) {
                        $(o.btnPrev + "," + o.btnNext).removeClass("disabled");
                        $((curr - o.scroll < 0 && o.btnPrev) || (curr + o.scroll > itemLength - v && o.btnNext) || []).addClass("disabled")
                    }
                }
                return false
            }
        })
    };

    function css(a, b) {
        return parseInt($.css(a[0], b)) || 0
    };

    function width(a) {
        return a[0].offsetWidth + css(a, 'marginLeft') + css(a, 'marginRight')
    };

    function height(a) {
        return a[0].offsetHeight + css(a, 'marginTop') + css(a, 'marginBottom')
    }
})(jQuery);

	/* Amendment made 14.09.11
	
	$('.slider ul li a span.con:eq(2)').css({paddingTop:'32px'});
	
	$('.slider ul li a span.con:eq(5)').css({paddingTop:'38px'});
    
	*/
	
	$(".slider").jCarouselLite({});

	
	jQuery.preLoadImages("images/home/prev_hover.png", "images/home/next_hover.png");


});
