yepnope({
	load: 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js',
	complete: function () {
		if (!window.jQuery) {
			yepnope('/js/jquery-1.5.1.min.js');
		}
		$(function() {
			main();
		});
	}
});

if (typeof(scriptId) != 'undefined') {
	if (scriptId == 'news') {
		yepnope({
			load: ['/js/jquery.jtweetsanywhere-1.2.1.min.js'],
			complete: function(url, result, key) {
				$(function() {
					newsPage();
				});
			}
		});
	}
	else if (scriptId == 'social') {
		yepnope({
			load: ['/js/jquery.jtweetsanywhere-1.2.1.min.js'],
			complete: function(url, result, key) {
				$(function() {
					socialPage();
				});
			}
		});
	}
	else if (scriptId == 'gids') {
		yepnope({
			load: ['/js/jquery.iframe-auto-height.plugin.1.4.0.min.js'],
			complete: function(url, result, key) {
				$(function() {
					guidePage();
				});
			}
		});
	}
	else if (scriptId == 'photos') {
		yepnope({
			load: ['/js/jquery.colorbox-min.js'],
			complete: function(url, result, key) {
				$(function() {
					photoPage();
				});
			}
		});
	}
	else if (scriptId == 'contact') {
		yepnope({
			load: ['/js/jquery.validationEngine.js', '/js/jquery.validationEngine-nl.js', '/js/jquery.form.js'],
			complete: function(url, result, key) {
				$(function() {
					contactPage();
				});
			}
		});
	}
}

function main() {
	// Nothing yet.
}

function newsPage() {
	$('#jTweetsAnywhere').jTweetsAnywhere({
		username: ['DenBoschNL', 'SintMichielsNL', 'RegioDenBosch', 'Vught', 'VughtNL'],
		count: 10,
		showTweetFeed: {
			showProfileImages: false,
			showUserScreenNames: false,
			paging: {
				mode: 'more'
			},
			autorefresh: {
				mode: 'trigger-insert',
				interval: 300
			}
		},
		tweetTimestampDecorator: function(tweet, options){
		   var screenName =
			   tweet.user ? tweet.user.screen_name : false || tweet.from_user;
		   var date = new Date(formatDate(tweet.created_at));

		   var dateString =
			   (date.getMonth() + 1) + '/' +
			   date.getDate() + '/' +
			   date.getFullYear() + ' - ' +
			   date.getHours() + ':' +
			   (date.getMinutes() < 10 ? '0' : '') +
			   date.getMinutes();


			var html =
				'<span class="jta-tweet-timestamp"> ' +
				'<a class="jta-tweet-timestamp-link" href="http://twitter.com/' +
				screenName + '/status/' + tweet.id + '">' +
				dateString + '</a></span>';

		   return html;
		},
		tweetFeedControlsMoreBtnDecorator: function(tweet, options) {
			return '<span class="jta-tweet-list-controls-button jta-tweet-list-controls-button-more">' + 'Meer nieuws...' + '</span>';
		},
		loadingDecorator: function(tweet, options) {
			return '<li class="jta-loading">Bezig met ophalen van het nieuws ...</li>';
		}
	});
}

function guidePage() {
    $('#guide').iframeAutoHeight();
	$('#guide').attr('src', '/regio-gids.php');
}

function socialPage() {
	$('#jTweetsAnywhere').jTweetsAnywhere({
		searchParams: 'q=den+bosch+OR+empel+OR+rosmalen+OR+berlicum+OR+maaskantje+OR+michielsgestel+OR+gemonde+OR+vught+OR+cromvoirt+OR+vlijmen',
		count: 10,
		showTweetFeed: {
			paging: {
				mode: 'more'
			},
			autorefresh: {
				mode: 'trigger-insert',
				interval: 300
			}
		},
		tweetTimestampDecorator: function(tweet, options){
		   var screenName =
			   tweet.user ? tweet.user.screen_name : false || tweet.from_user;
		   var date = new Date(formatDate(tweet.created_at));

		   var dateString =
			   (date.getMonth() + 1) + '/' +
			   date.getDate() + '/' +
			   date.getFullYear() + ' - ' +
			   date.getHours() + ':' +
			   (date.getMinutes() < 10 ? '0' : '') +
			   date.getMinutes();


			var html =
				'<span class="jta-tweet-timestamp"> ' +
				'<a class="jta-tweet-timestamp-link" href="http://twitter.com/' +
				screenName + '/status/' + tweet.id + '">' +
				dateString + '</a></span>';

		   return html;
		},
		tweetFeedControlsMoreBtnDecorator: function(tweet, options) {
			return '<span class="jta-tweet-list-controls-button jta-tweet-list-controls-button-more">' + 'Meer berichten...' + '</span>';
		},
		loadingDecorator: function(tweet, options) {
			return '<li class="jta-loading">Bezig met ophalen van berichten ...</li>';
		}
	});
}

function photoPage() {
	$("a[rel='photos']").colorbox({
		speed: 500,
		initialWidth: 80,
		initialHeight: 80,
		width: 640,
		height: 520,
		current: 'Foto {current} van {total}',
		close: 'Sluiten',
		opacity: 0.7
	});
}

function contactPage() {
	$('#send-email').validationEngine();

	$('#submit-message').click(function(e) {
		e.preventDefault();
		if ($('#send-email').validationEngine('validate')) {
			$('#send-email').ajaxSubmit({
				success: function(responseText) {
					if (responseText == 'OK') {
						$('#send-email')[0].reset();
						$('#msgbox').html('Uw bericht is verzonden. Wij zullen u zo spoedig mogelijk beantwoorden.').addClass('messagebox-ok');
						$('#msgbox').fadeIn(1800);
					}
					else {
						$('#msgbox').html('Er is een fout opgetreden bij het versturen van het bericht. Probeer het aub nog een keer.').addClass('messagebox-error')
						$('#msgbox').fadeIn(1800);
					}
				}
			});
		}
	});
}

