/*
 * Potager City
 *  Tous droits reserves
 */

$(document).ready(function() {
	// Init menu fade
	$('#ptcy-bgheader').innerfade({
		animationtype: 'fade',
		speed: 4000,
		timeout: 6000,
		type: 'random_start',
		containerheight: '181px'
	});

	// Init IE 6 PNG transparency fix
	if (typeof(loadPNGFix) != 'undefined') {
		DD_belatedPNG.fix('.transparentpng');
	}

	// Init registration map JS file
	if (typeof(loadRegistrationMap) != 'undefined') {
		init_maps();
	}

	// Init home page elements
	if (typeof(loadHomePage) != 'undefined') {
		// Scrollable
		$(".scrollable").scrollable({
			size: 1,
			interval: 8000,
			clickable: false,
			loop: true,
			speed: 600,
			navi: 'ul.navi'
		});


		// Partners tooltips
		$(".fp-partners-tooltip-link").tooltip({
			position: ['top', 'center']
		});
	}

	// Init videos
	var initVideosObj = $('a.video');
	if (initVideosObj.length > 0) {
		initVideosObj.flowplayer('http://static.potagercity.com/swf/flowplayer-3.1.2.swf');
	}

	// Init popups
	var initPopupObj = $('a.innerpopup-link');
	if (initPopupObj.length > 0) {
		initPopupObj.overlay({
			expose: {
				color: '#333',
				opacity: 0.7,
				closeSpeed: 1000
			},
			finish: {
				top: 'center',
				left: 'center'
			},
			onLoad: function(content) {
				this.videosObj = this.getContent().find('a.video');

				if (this.videosObj.length > 0) {
					this.videosObj.flowplayer(0).load();
				}
			},

			onClose: function(content) {
				if (typeof(this.videosObj) != 'undefined' && this.videosObj.length > 0) {
					this.videosObj.flowplayer(0).unload();
					delete this.videosObj;
				}
			}
		});
	}

	// Init help tooltips
	var initHelpTooltipsObj = $('.help-tooltip-link');
	if (initHelpTooltipsObj.length > 0) {
		initHelpTooltipsObj.tooltip({
			position: ['center', 'right'],
			effect: 'toggle',
			offset: [0, 10],
			tip: '.help-tooltip'
		});
	}
});

// Change quantity in a form
function changeQuantity(id, valueToAdd, minValue)
{
	var inputForm	= $(id);

	if (inputForm.length == 1) {
		if (isNaN(inputForm[0].value)) {
			inputForm[0].value	= 1;
		} else if (parseInt(inputForm[0].value) + valueToAdd >= minValue) {
			inputForm[0].value	= parseInt(inputForm[0].value) + valueToAdd;
		}
	}
}

// Open popup
function openPopup(url, args, height, width)
{
	var winPopup	= window.open(url + "/popup/1?" + args, "potagercity", "resizable,scrollbars=yes,height=" + height + ",width=" + width);
}

// Workaround to call init_form only when the page is REALLY loaded
//window.onload = function() { window.setTimeout('init_page()', 0); };

