//video vid-yui.js
(function(a){a.fn.vid=function(){var b={type:"youtube",videoId:"4wGR4-SeuJ0",autoPlay:true,loop:false,hq:true,chromeless:false};if(arguments[0]){a.extend(b,arguments[0])}this.each(function(){var d="";var c={};switch(b.type){case"youtube":d+="youtube.com/v/"+b.videoId+"?enablejsapi=1&autoplay="+(b.autoPlay?"1":"0")+"&loop="+(b.loop?"1":"0")+(b.hq?"&hd=1":"")+(b.chromless?"&version=3":"");break;case"vimeo":d+="vimeo.com/moogaloop.swf?clip_id="+b.videoId+"&js_api=1"+(b.hq?"":"&hd_off=1");break;case"dailymotion":d+="ailymotion.com/swf/"+b.videoId+"?enablejsapi=1&autoplay="+(b.autoPlay?"1":"0");break;case"1click2fame":d+="1click2fame.com/flash/Player.swf?videoID="+b.videoId+"&autoPlay="+(b.autoPlay?"1":"0");break}a(this).flash({swf:"http://"+d,width:a(this).width(),height:a(this).height(),flashvars:c})});return this}})(jQuery);
// Including the jQuery SWFObject plugin by Jonathan Neal: http://jquery.thewikies.com/swfobject/
(function(e,b){var c=function(g){var f,h=[];for(f in g){h.push(f+'="'+g[f]+'"')}return h.join("")},d=function(h){var f,j,i=[],g;for(f in h){if(typeof h[f]=="object"){g=[];for(j in h[f]){g.push([j,"=",encodeURIComponent(h[f][j])].join(""))}h[f]=g.join("&amp;")}i.push(['<param name="',f,'" value="',h[f],'" />'].join(""))}return i.join("")},a=false;e[b]=(function(){var f="0,0,0",g=navigator.plugins["Shockwave Flash"]||ActiveXObject;f=g.description||(function(){try{return(new g("ShockwaveFlash.ShockwaveFlash")).GetVariable("$version")}catch(h){}}());f=f.match(/^[A-Za-z\s]*?(\d+)[\.|,](\d+)(?:\s+r|,)(\d+)/);return{available:f[1]>0,activeX:!g.name,version:{major:f[1]*1,minor:f[2]*1,release:f[3]*1},hasVersion:function(i){var l=this.version,j="major",k="minor",h="release";i=(/string|number/.test(typeof i))?i.toString().split("."):i||[0,0,0];i=[i[j]||i[0]||l[j],i[k]||i[1]||l[k],i[h]||i[2]||l[h]];return(i[0]<l[j])||(i[0]==l[j]&&i[1]<l[k])||(i[0]==l[j]&&i[1]==l[k]&&i[2]<=l[h])},expressInstall:"expressInstall.swf",create:function(h){if(!e[b].available||a||!typeof h=="object"||!h.swf){return false}if(h.hasVersion&&!e[b].hasVersion(h.hasVersion)){h={swf:h.expressInstall||e[b].expressInstall,attrs:{id:"SWFObjectExprInst",height:Math.max(h.height||137),width:Math.max(h.width||214)},params:{flashvars:{MMredirectURL:location.href,MMplayerType:(e[b].activeX)?"ActiveX":"PlugIn",MMdoctitle:document.title.slice(0,47)+" - Flash Player Installation"}}};a=true}else{h=e.extend(true,{attrs:{height:h.height||180,width:h.width||320},params:{wmode:h.wmode||"opaque",flashvars:h.flashvars}},h)}return"<object "+(c(h.attrs))+(e[b].activeX?' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="movie" value="'+h.swf+'" />':' type="application/x-shockwave-flash" data="'+h.swf+'">')+(d(h.params))+"</object>"}}}());e.fn[b]=function(f){if(typeof f=="object"){this.each(function(){var g=document.createElement(b);g.innerHTML=e[b].create(f);if(g.childNodes[0]){this.appendChild(g.childNodes[0])}})}else{if(typeof f=="function"){this.find("object").andSelf().filter("object").each(function(){var h=this,g="jsInteractionTimeoutMs";h[g]=h[g]||0;if(h[g]<660){if(h.clientWidth||h.clientHeight){f.call(this)}else{setTimeout(function(){e(h)[b](f)},h[g]+66)}}})}}return this}}(jQuery,"flash"));

// video function
(function($)
{
	$.fn.vid 		= function() 
	{
    	var c 		= {
			// required
			type			: 'youtube',			// String 		- defines the service, possible values are: youtube, vimeo, dailymotion, 1click2fame; for anymore, just fork the project or email me.
			videoId			: '4wGR4-SeuJ0',		// String		- defines the unique video identifier
			// optional
			autoPlay		: true,					// Boolean		- defines whether to autoplay the video or not
			loop			: false,				// Boolean		- defines whether to loop the video or not
			hq				: true,					// Boolean		- defines whether to play the highest quality version, so HD or HQ, rather than SD
			chromeless		: true					// Boolean		- defines whether to use the chromless player for youtube only
		};
	
		if ( arguments[ 0 ] )
		{
			$.extend( c, arguments[ 0 ] );
		}

		this.each( function() 
		{
			var h	= '';
			var v	= { };
			
			switch ( c.type )
			{
				case 'youtube':
				h	+= 'youtube.com/v/' + c.videoId + '?enablejsapi=1&autoplay=' + ( c.autoPlay ? '1' : '0' ) + '&loop=' + ( c.loop ? '1' : '0' ) + ( c.hq ? '&hd=1' : '' ) + ( c.chromless ? '&version=3' : '' );
				
				break;
				
				case 'vimeo':
				h	+= 'vimeo.com/moogaloop.swf?clip_id=' + c.videoId + '&js_api=1' + ( c.hq ? '' : '&hd_off=1' );
				
				break;
				
				case 'dailymotion':
				h	+= 'ailymotion.com/swf/' + c.videoId + '?enablejsapi=1&autoplay=' + ( c.autoPlay ? '1' : '0' );
				
				break;
				
				case '1click2fame':
				h	+= '1click2fame.com/flash/Player.swf?videoID=' + c.videoId + '&autoPlay=' + ( c.autoPlay ? '1' : '0' );
				
				break;
			}
			
			$( this ).flash({
				swf			: 'http://' + h,
				width		: $( this ).width(),
				height		: $( this ).height(),
				flashvars	: v
			});
		});
		
		return this;
	};
})(jQuery);

// Including the jQuery SWFObject plugin by Jonathan Neal: http://jquery.thewikies.com/swfobject/
(function ($, flash) {
	var createAttrs = function (obj) {
		var aEach,
		aArray = [];

		for (aEach in obj) {
			aArray.push(aEach + '="' + obj[aEach] + '"');
		}

		return aArray.join('');
	},
	createParams = function (obj) {
		var aEach,
		bEach,
		aArray = [],
		bArray;

		for (aEach in obj) {
			if (typeof obj[aEach] == 'object') {
				bArray = [];

				for (bEach in obj[aEach]) {
					bArray.push([bEach, '=', encodeURIComponent(obj[aEach][bEach])].join(''));
				}

				obj[aEach] = bArray.join('&amp;');
			}

			aArray.push(['<param name="', aEach, '" value="', obj[aEach], '" />'].join(''));
		}

		return aArray.join('');
	},
	expressInstallIsActive = false;

	$[flash] = (function () {
		var flashVersion = '0,0,0',
		Plugin = navigator.plugins['Shockwave Flash'] || ActiveXObject;

		flashVersion = Plugin.description || (function () {
			try {
				return (new Plugin('ShockwaveFlash.ShockwaveFlash')).GetVariable('$version');
			}
			catch (eIE) {}
		}());

		flashVersion = flashVersion.match(/^[A-Za-z\s]*?(\d+)[\.|,](\d+)(?:\s+r|,)(\d+)/);

		return {
			available: flashVersion[1] > 0,

			activeX: !Plugin.name,

			version: {
				major: flashVersion[1] * 1,
				minor: flashVersion[2] * 1, 
				release: flashVersion[3] * 1
			},

			hasVersion: function (version) {
				var versionCompare = this.version,
				major = 'major',
				minor = 'minor',
				release = 'release';

				version = (/string|number/.test(typeof version)) ? version.toString().split('.') : version || [0, 0, 0];

				version = [
					version[major] || version[0] || versionCompare[major],
					version[minor] || version[1] || versionCompare[minor],
					version[release] || version[2] || versionCompare[release]
				];

				return (version[0] < versionCompare[major]) || (version[0] == versionCompare[major] && version[1] < versionCompare[minor]) || (version[0] == versionCompare[major] && version[1] == versionCompare[minor] && version[2] <= versionCompare[release]);
			},

			expressInstall: 'expressInstall.swf',

			create: function (obj) {
				if (!$[flash].available || expressInstallIsActive || !typeof obj == 'object' || !obj.swf) {
					return false;
				}

				if (obj.hasVersion && !$[flash].hasVersion(obj.hasVersion)) {
					obj = {
						swf: obj.expressInstall || $[flash].expressInstall,
						attrs: {
							id: 'SWFObjectExprInst',
							height: Math.max(obj.height || 137),
							width: Math.max(obj.width || 214)
						},
						params: {
							flashvars: {
								MMredirectURL: location.href,
								MMplayerType: ($[flash].activeX) ? 'ActiveX': 'PlugIn',
								MMdoctitle: document.title.slice(0, 47) + ' - Flash Player Installation'
							}
						}
					};

					expressInstallIsActive = true;
				}
				else {
					obj = $.extend(
						true,
						{
							attrs: {
								height: obj.height || 180,
								width: obj.width || 320
							},
							params: {
								wmode: obj.wmode || 'opaque',
								flashvars: obj.flashvars
							}
						},
						obj
					);
				}

				return '<object ' + (
					createAttrs(obj.attrs)
				) + (
					$[flash].activeX ? ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">' + '<param name="movie" value="' + obj.swf + '" />' : ' type="application/x-shockwave-flash" data="' + obj.swf + '">'
				) + (
					createParams(obj.params)
				) + '</object>';
			}
		};
	}());

	$.fn[flash] = function (args) {
		if (typeof args == 'object') { 
			this.each(
				function () {
					var test = document.createElement(flash);

					test.innerHTML = $[flash].create(args);

					if (test.childNodes[0]) {
						this.appendChild(test.childNodes[0]);
					}
				}
			);
		}
		else if (typeof args == 'function') {
			this.find('object').andSelf().filter('object').each(
				function () {
					var elem = this,
					jsInteractionTimeoutMs = 'jsInteractionTimeoutMs';

					elem[jsInteractionTimeoutMs] = elem[jsInteractionTimeoutMs] || 0;

					if (elem[jsInteractionTimeoutMs] < 660) {
						if (elem.clientWidth || elem.clientHeight) {
							args.call(this);
						}
						else {
							setTimeout(
								function () {
									$(elem)[flash](args);
								},
								elem[jsInteractionTimeoutMs] + 66
							);
						}
					}
				}
			);
		}

		return this;
	};
}(jQuery, 'flash'));

// center function
jQuery.fn.center = function (absolute) {
	return this.each(function () {
		var t = jQuery(this);

		t.css({
			position:    absolute ? 'absolute' : 'fixed', 
			left:        '50%', 
			top:        '50%', 
			zIndex:        '9010'
		}).css({
			marginLeft:    '-' + (t.outerWidth() / 2) + 'px', 
			marginTop:    '-' + (t.outerHeight() / 2) + 'px'
		});

		if (absolute) {
			t.css({
				marginTop:    parseInt(t.css('marginTop'), 10) + jQuery(window).scrollTop(), 
				marginLeft:    parseInt(t.css('marginLeft'), 10) + jQuery(window).scrollLeft()
			});
		}
	});
};

$(function() { // When DOM is ready
	
	// fade out with button
	$('#close').click(function(){
		$('#popup-bg').fadeOut("slow", function() { 
			$("#popup-bg").empty();
		});
		$('#popup-container').fadeOut("slow", function() { 
			$("#popup-main").empty();
			$('#popup-container').css('width','auto');
		});
	});
	
	// fade out with bg
	$('#popup-bg').click(function(){
		$('#popup-bg').fadeOut("slow", function() { 
			$("#popup-bg").empty();
		});
		$('#popup-container').fadeOut("slow", function() { 
			$("#popup-main").empty();
			$('#popup-container').css('width','auto');
		});
	});
	
	// add to basket
	$("a.add_to_cart").click(function() {
		var url = $(this).attr("href");
		$.ajax({
			type: "GET",
			url: url,
			success: function(data) {
				$('#popup-main').html(data);						
				$('#popup-bg').fadeIn('slow');						
				$('#popup-container').center().fadeIn('slow');
			},
			error: function() {
				window.location(url);
			}
		});
		return false;
	});
	
	Shadowbox.init();
	
});

function showImageMedium(name, path){
			var folder = name.substr(0,1);
			document.getElementById('medium-picture').innerHTML = '<img src="/pictures/' + path + '/' + folder + '/' + name + '_180.jpg" alt="medium" class="middle" />';
}

// video
function showVideo(videoID){
	
	$('#popup-main').css("width","640px");
	$('#popup-main').css("height","505px");
	
	$('#popup-bg').fadeIn('slow', function() {
						$('#popup-main').vid({
							type	: 'youtube',
							videoId	: videoID
						});
	});
	
	$('#popup-container').center().fadeIn('slow');
	
}


function videoLinkLook(element, id, mode){
	if( (element == 'link' || element == 'image') && mode == 'on'){
		$('#video_image_' + id).css({
			"opacity": "1",
			"filter": "alpha(opacity=100)"
		});
		$('#video_link_' + id).css({
			"color": "#f00",
			"text-decoration": "underline"
		});
	} else
	
	if( (element == 'link' || element == 'image') && mode == 'off'){
		$('#video_image_' + id).css({
			"opacity": "0.4",
			"filter": "alpha(opacity=40)"
		});
		$('#video_link_' + id).css({
			"color": "#666",
			"text-decoration": "none"
		});
	} 
}

function number_format (number, decimals, dec_point, thousands_sep) {
	number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
	var n = !isFinite(+number) ? 0 : +number,
		prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
		sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
		dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
		s = '',
		toFixedFix = function (n, prec) {
			var k = Math.pow(10, prec);
			return '' + Math.round(n * k) / k;
		};
	// Fix for IE parseFloat(0.55).toFixed(0) = 0;
	s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
	if (s[0].length > 3) { 
		s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
	}
	if ((s[1] || '').length < prec) {
		s[1] = s[1] || '';
		s[1] += new Array(prec - s[1].length + 1).join('0');
	}
	return s.join(dec);
}
