//===================================================================
// APPLICATION
//===================================================================
App = {
	// Application base path
	base: '',
	// Initialization
	init: function(options) {

		var defaults = {base: ''};
		$.extend(defaults, options);
		
		this.base = defaults.base;

		if ($.browser.msie) {
			App.msie.init();
		}
	}
};
//-------------------------------------------------------------------
// Internet Explorer Fixes
//-------------------------------------------------------------------
App.msie = {
	init: function() {
		// Fix PNG for IE6
		if ($.browser.version.slice(0,1) == 6) {
			this.pngFix();
		}
	},
	pngFix: function() {
		$('body *').each(function(i, node) {
			var element = $(node);
			if ((node.tagName == 'IMG' && element.attr('src').match(/\.png/i)) || element.css('background-image').match(/\.png/i)) {
				DD_belatedPNG.fixPng(node);
			}
		});
	}
};

//===================================================================
// USER INTERFACE
//===================================================================
App.ui = {};

//-------------------------------------------------------------------
// Header
//-------------------------------------------------------------------
App.ui.header = {
	slideshow: function() {
		$('#header .slideshow').cycle();
	}
};

//-------------------------------------------------------------------
// History
//-------------------------------------------------------------------
App.ui.history = {
	images: function(options) {

		var defaults = {
			translations: {
				language: 'en',
				of: 'of'
			}
		};
		$.extend(defaults, options);

		$('#view .history .images ul li a').lightBox({
			imageLoading: App.base + 'js/jquery.lightbox/images/lightbox-ico-loading.gif',
			imageBtnClose: App.base + 'js/jquery.lightbox/images/lightbox-btn-close.gif',
			imageBtnPrev: App.base + 'js/jquery.lightbox/images/lightbox-btn-prev.gif',
			imageBtnNext: App.base + 'js/jquery.lightbox/images/lightbox-btn-next.gif',
			imageBlank: App.base + 'js/jquery.lightbox/images/lightbox-blank.gif',
			txtOf: defaults.translations.of
		});
	}
};

//-------------------------------------------------------------------
// Vineyard
//-------------------------------------------------------------------
App.ui.vineyard = {
	description: function() {
		$('#view .slideshow').cycle();
	}
};

//-------------------------------------------------------------------
// Products
//-------------------------------------------------------------------
App.ui.products = {
	slideshow: {
		bxSlider: {},
		build: function() {
			this.bxSlider = $('#view .products .slideshow').bxSlider({
				auto: false,
				controls: Boolean($('#view .products .slideshow li').length - 1),
				prevSelector: '#view .products .navigation',
				prevText: '',
				nextSelector: '#view .products .navigation',
				nextText: '',
				pager: false,
				captions: false
			});
			if ($.gup('pid')) {
				var id = $.gup('pid');
				var _this = this;
				$('#view .products .slideshow li').each(function(i, e) {
					if ($(e).hasClass(id)) {
						return _this.slide(i-1);
					}
				});
			}
		},
		slide: function(index) {
			this.bxSlider.goToSlide(index, false);
		}
	}
};
