var VideoPlayer = {
	show: function (url) {
		$.blockUI({ css: {width: '700px', height:'458px', left: ($(window).width() - 700) /2 + 'px', top: ($(window).height() - 458) /2 + 'px'}, message: '<div id="close_box"><a href="#" onclick="VideoPlayer.hide(); return false;"><img src="images/lightbox_close.png" alt=""/></a></div><div id="video"></div>' });
		setTimeout(function() {
			var s1 = new SWFObject('flash/player.swf','player','700','458','9');
			s1.addParam('allowfullscreen','true');
			s1.addParam('allowscriptaccess','always');
			s1.addParam('wmode','transparent');
			s1.addParam('flashvars','file='+url+'&autostart=true');
			s1.write('video');
			$('.blockUI.blockOverlay').click(function () {
				VideoPlayer.hide();
			});
		}, 300);
	},
	
	hide: function() {
	    $.unblockUI();
	}
}

var ImageViewer = {
	show: function (url, width) {
		$.blockUI({ css:{width: width+'px'}, message: '<div id="close_box"><a href="#" onclick="ImageViewer.hide(); return false;"><img src="images/lightbox_close.png" alt=""/></a></div><div id="video"><img src="'+url+'"</div>' });
		$('.blockUI.blockOverlay').click(function () {
			VideoPlayer.hide();
		});
	},
	
	hide: function() {
	    $.unblockUI();
	}
}
function Slideshow(container, fadeOut) {
	this.fadeOut = fadeOut;

    this.startTimer = function(long_delay) {
        this.fading = false;
	var obj = this;
        this.timer = setTimeout(function() {
           obj.next(false);
        },
        (long_delay ? this.startdelay : this.delay));
    };

    this.prev = function() {
        if (this.fading) {
            return;
        }
        if (this.timer) {
            clearTimeout(this.timer);
            this.timer = null;
        }
        var next_pos = this.position - 1;

        this.fading = true;
		var obj = this;
        if (next_pos < 0) {
			if (this.fadeOut) {
				$(this.slides[0]).fadeOut('slow');
			}
            $(this.slides[this.count - 1]).fadeIn('slow',
            function() {
                for (var i = 1; i < Slideshow.count - 1; i++) {
                    $(obj.slides[i]).show();
                }
                obj.startTimer();
            });
            this.position = this.count - 1;
        } else {
			if (this.fadeOut) {
				$(this.slides[next_pos]).fadeIn('slow');
			} else {
				$(this.slides[next_pos]).show();
			}
            $(this.slides[this.position]).fadeOut('slow',
            function() {
                obj.startTimer(true);
            });
            this.position = next_pos;
        }
    };

    this.next = function(manual) {
        if (this.fading) {
            return;
        }
        if (this.timer) {
            clearTimeout(this.timer);
            this.timer = null;
        }

        var next_pos = this.position + 1;

        this.fading = true;
        if (next_pos == this.count) {
            for (var i = 1; i < this.count - 1; i++) {
                $(this.slides[i]).hide();
            }
			if (this.fadeOut) {
				$(this.slides[0]).fadeIn('slow');
			}
			var obj = this;
            $(this.slides[this.count - 1]).fadeOut('slow',
            function() {
                obj.startTimer(manual);
            });
            this.position = 0;
        } else {
	var obj = this;
            $(this.slides[next_pos]).fadeIn('slow',
            function() {
                obj.startTimer(manual);
            });
			if (this.fadeOut) {
            	$(this.slides[this.position]).fadeOut('slow');
			}
	        this.position = next_pos;
        }
    };


    this.position = 0;
    this.count = 0;
    this.container = container;
    this.slides = null;
	this.timer = null;
	this.delay = 5000;
	this.startdelay = 5000;
	this.fading = false;

    this.slides = container.children();
    this.count = this.slides.length;
    this.container.css('position', 'relative')
    for (var i = 0; i < this.count; i++) {

        $(this.slides[i]).css('position', 'absolute');
        $(this.slides[i]).css('z-index', i);
        if (i > 0)
        $(this.slides[i]).hide();
    }
  this.startTimer(true);
}

$(document).ready (function () {
    $('#navigation li').hover (function () {
        $(this).addClass('hover');
    }, function () {
        $(this).removeClass('hover');
    });
});
