/* Author: 

*/

jQuery(function($) {
	$('.slides').cycle({
		speed:	0
	});

	
	$('#Map.lightbox area').colorbox();
	
	var flashvars = {}, params = { wmode: 'transparent', allowScriptAccess: 'always', menu: 'false' }, attributes = {};
	if ($('body.homepage').length) {
		updateShoutout();
		swfobject.embedSWF('/tech_fun/swf/header.swf', 'flashheader', '1190', '613', '10.0.0','swf/expressInstall.swf', flashvars, params, attributes);
	}
	
	swfobject.embedSWF('/tech_fun/swf/quiz02.swf', 'quiz', '666', '421', '10.0.0','swf/expressInstall.swf', flashvars, params, attributes);
	swfobject.embedSWF('/tech_fun/swf/game06.swf', 'game', '666', '421', '10.0.0','swf/expressInstall.swf', flashvars, params, attributes);
	
	$('.wallpapers.gallery .slides').cycle({
		pager: '.wallpapers.gallery .pager ul',
		pagerAnchorBuilder: function(index, slide) {
			return '.wallpapers.gallery .thumbnails.pager li:eq(' + (index) + ') a';
		},
		timeout: 0
	});
	
	
	
	var galleryPager = $('.photo.gallery .thumbnails.pager .items').jcarousel({
		scroll: 3,
		visible: 6
	});
	
	$('.photo.gallery .slides .items').cycle({
		next: '.photo.gallery .pager .next',
		prev: '.photo.gallery .pager .prev',
		pager: '.photo.gallery .pager ul.jcarousel-list',
		pagerAnchorBuilder: function(index, slide) {
			return '.photo.gallery .thumbnails.pager li:eq(' + (index) + ') a';
		},
		before: function(currSlideElement, nextSlideElement, options, forwardFlag) {
			galleryPager.jcarousel('scroll', options.nextSlide);
		},
		pause: true
	});
	
	$('.signup').colorbox({
		href: '/member/signup/',
		iframe: true,
		width:640,
		height:'90%'
	});
	
	$('.shoutlightbox').colorbox({
		iframe: true,
		width:640,
		height:500,
		href: '/shoutout/send/',
		onClosed: updateShoutout
	});
	
	$('a.post-shoutout[href*=login]').click(function() {
		alert('Please login first before posting your shoutout!');
		return true;
	});
});

function updateShoutout() {
	$.ajax('/shoutout/list', {
		dataType: 'json',
		success: function(data, textStatus, jqXHR) {
			console.log(data);
			var html = '<ul>';
			
			$.each(data, function(index, item) {
				html += '<li>';
				html += '<h6>'+item.username+'</h6>';
				html += '<p>'+item.message+'</p>';
				html += '</li>';
			});
			
			html += '</ul>';
			$('#shoutoutlist').html(html);
		}
	});
}























