
/*
 * Swf object
 */
var Swf = function() {

	var defaults = {
		'id': '',
		'name': '',
		'flashvars': '',
		'allowscriptaccess': 'always',
		'allowfullscreen': 'true',
		'quality': 'high',
		'bgcolor': '',
		'style': '',
		'width': 100,
		'height': 100,
		'src': '',
		'type': 'application/x-shockwave-flash'
	};

	var options = arguments[0] || {};
	this.options = {};

	for(key in defaults) {
		this.options[key] = (typeof options[key] != 'undefined') ? options[key] : defaults[key] ;
	}

	this.version = function getFlashVersion(){
		// ie
		try {
			try {
				// avoid fp6 minor version lookup issues
				// see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
				var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
				try {
					axo.AllowScriptAccess = 'always';
				}
				catch(e) {
					return '6,0,0';
				}
			} catch(e) {

			}
			return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];

		// other browsers
		} catch(e) {
			try {
				if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
					return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
				}
			} catch(e) {

			}
		}
		return '0,0,0';
	};

	this.set = function(key, value) {
		this.options[key] = value;
	};

	this.get = function(key) {
		return (typeof this.options[key] != 'undefined') ? this.options[key] : null ;
	};

	this.write = function() {

		if(!this.version()) {
			return;
		}

		var embed = '<embed ';
		for(key in this.options) {
			if(this.options[key] != '') {
				embed += key + '="' + this.options[key] + '" ';
			}
		}
		embed += '></embed>';

		document.write(embed);
	};

};

/*
 * Product label popups
 */
var Labels = function() {

	var offset = arguments[0] ? arguments[0] : {'x': 0, 'y': 0};

	// create label append to body hidden
	this.label = $('<div>').attr({'id': 'product_label'}).hide();
	$('body').append(this.label);

	// bind events to matched elements
	this.bind = function(match) {

		var that = this;
		$(match).bind('mouseover', function() {
			var text = $(this).attr('rel');
			var position = $(this).position();
			that.label.html(text).css({
				'top': position.top + offset.y,
				'left': position.left + offset.x
			}).show();
		}).bind('mouseout', function() {
			that.label.hide();
		});

	};

};

/*
 * Category 'mood' images
 */
 var Mood = function(preload, hidden) {

	this.img = $(preload);
	this.hidden = hidden;
	this.duration = 4000;

	// binding
	var that = this;

	// preload
 	this.img.preload({
		onComplete: function() {
			that.loaded();
		}
	});

	// show hidden element
	this.loaded = function() {
		var that = this;
		this.img.fadeOut(this.duration, function() {
			$(that.hidden).show();
		});
	};
 };

 /*
  * Product images
  */
 var Images = function(options) {
	 
	this.cur = 0;

	// all images
	this.images = $(options.match);
	
	if(this.images.length <= 1) {
		return;
	}

	// hide all
	this.images.hide();

	// show first
	$(this.images[0]).show();

	// events
	var that = this;

	$(options.next).bind('click', function() {
		var next = that.cur + 1;
		if(!that.images[next]) {
			next = 0;
		}
		that.set(next);
		return false;
	});

	$(options.prev).bind('click', function() {
		var prev = that.cur - 1;
		if(!that.images[prev]) {
			prev = (that.images.length - 1);
		}
		that.set(prev);
		return false;
	});

	this.set = function(index) {
		var that = this;
		$(this.images[this.cur]).fadeOut(500, function() {
			$(that.images[index]).fadeIn(500);
			that.cur = index;
		});
	};
 };
 