hanken = {
    init: function() {
	    //this.banner.init();
		if($('#content-default-banner').length) {
		    hanken.startInnerFade();
		}
		if($('#secondary-form-container').length) {		
		$('#secondary-form-container').dialog({
			autoOpen: false,
			height: 300,
			width: 550,
			modal: true,
			buttons: {
				'Save': function() {
					$('#secondary-form').submit();
				},
				Cancel: function() {
					$(this).dialog('close');
				}
			},
			close: function() {
			}
		});
		}
		
		$('#edit-secondary').click(function(event) {
			event.preventDefault();
			$('#secondary-form-container').dialog('open');
		});

	
    },
    
    startInnerFade: function() {
		$('#content-default-banner').innerfade({
			speed: 2000,
			timeout: 8000,
			type: 'random_start',
			containerheight: '200px'
		});
	},
	
	banner: {
		showTimer: 5, // in seconds
		fadeTimer: 1, // in seconds
		
		firstrun: true,
		data: null,
		count: 0,
		banner: null,
		
		init: function() {
			this.banner = $('#content-default-banner');
			this.count = this.getRandom();
			this.showBanner();
		},

		showBanner: function() {
			var self = this;
		
			if (!this.firstrun) {
				if(this.count==this.data.length) {
					this.count = 0;
				};
			
				this.banner.fadeOut(self.fadeTimer*1000, function() {
					self.setBannerHTML('image', self.count);
					self.banner.fadeIn(self.fadeTimer*1000, function() {
						self.count++;
						
						window.setTimeout(function() {
							self.showBanner();
						}, self.showTimer*1000);
					});
				});
				
				this.firstrun = false;
			}
			else {				
				this.setBannerHTML('image', self.count);
				this.count++;
				this.firstrun = false;
				
				window.setTimeout(function() {
					self.showBanner();
				}, self.showTimer*1000);
			};
		},
		
		setBannerHTML: function(type, count) {
			var dataEntry = this.data[count];
			var imageUrl = dataEntry[0];
			var linkUrl = dataEntry[1];
			
			this.banner
			.html('<img src="'+imageUrl+'" />')
			.unbind('click');
			
			if (linkUrl) {
				this.banner.click(function() {
					document.location = linkUrl;
				});
			};
		},
		
		getRandom: function() {
			return Math.floor(Math.random()*this.data.length);
		}
	}
};

jQuery(document).ready(function() {
    hanken.init();
});
