
	/*----------------------------------------------------------------------

		Young Person's Guide to East London
		http://www.ypg2el.com/

		Developed by Designition Ltd - www.designition.co.uk

		Copyright 2009

	----------------------------------------------------------------------*/


	var Ypg =  {

		init : function() {
			Ypg.multi_images();
			Ypg.search_form();
			Ypg.sites_filter();
			Ypg.tweaks();
		},	//	init : function()


		multi_images : function() {
			if ($('.multi_single').get(0)) {
				post_id = $('img.multi_single').attr('id').split('_')[1];

				$.ajax({
					data:     'ajax=true&id=' + post_id,
					dataType: 'html',
					method:   'get',
					success:  function(response) {
						$('img.multi_single').remove();

						$(response).insertBefore('.multi_thumbs_wrapper');

						multi_thumbs = $('.multi_thumbs');

						$('ul.multi_master').cycle({
							speed:   250,
							timeout: 5000,
							pager:   multi_thumbs,
							pagerAnchorBuilder: function(idx) {
								return '.multi_thumbs li:eq(' + idx + ') a';
							}
						});
					},
					url: '/incs/actions/multi_images.php'
				});
			}
		},


		search_form : function() {
			examples = ['Arts and Culture', 'Communications', 'Community', 'Eating', 'Great Views', 'Hanging Out', 'History', 'Shopping', 'Music', 'Sport', 'Transport'];

			default_value = 'eg: ' + examples[Math.floor(Math.random() * examples.length)];

			$('#search_terms')
				.val(default_value)
				.focus(function() {
					if ($(this).val() == default_value) $(this).removeAttr('value');
				})
				.blur(function() {
					if ($(this).val() == '') $(this).val(default_value);
				});
		},	//	search_form : function()


		sites_filter : function() {
			if ($('.alphabet').get(0)) {
				//	Smooth scrolling on internal links
				$.each([$('ul.alphabet_list li a'), $('p.to_alpha_top a')], function() {
					$(this).click(function() {
						target = $(this.hash);
						var targetOffset = target.offset().top;
						$('html, body').animate({scrollTop: targetOffset}, 1000, 'swing');

						return false;
					});
				});
			}

			if ($('.quicksearch').get(0)) {
				//	Quick Search
				$.ajax({
					url      : '/incs/actions/sites_quicksearch.php',
					dataType : 'html',
					success  : function(response) {
						$(response).appendTo('.quicksearch');
						$('.quicksearch_form input').liveUpdate('.quicksearch_list');
						$('.quicksearch_list').css({ paddingBottom : 0});
						$('.quicksearch_list li').css({ display: 'none' });
					}
				});
			}
		},	//	sites_filter : function()


		tweaks : function () {
			$('body').addClass('js');

			if ($('.sites_list').get(0)) {
				$('.sites_list li').click(function() {
					window.location = $(this).find('a[rel=destination]').attr('href');
				})
			}

			if ($('.themes_list').get(0)) {
				$('.themes_list li').click(function() {
					window.location = $(this).find('a[rel=destination]').attr('href');
				})
			}

			$('a[rel=ext]').click(function() { $(this).attr('target', '_blank'); });
		}	//	tweaks : function ()
	}; //	//	var Ypg = Ypg || {}



	//	That's the anthem - get your damn hands up!
	$(function() {

		$( 'body' ).addClass( 'js' );

		Ypg.init();

		//	Select curry mix strength
		$.fn.commentRating = function() {

			var form, fieldset, rating_val, rating_el, ratings_html,
				ratings, selected_rating;

			form       = this;
			fieldset   = form.find( '.rating' );
			rating_val = fieldset.find( 'input:checked' ).val();

			fieldset.empty();

			$( '<input type="hidden" name="rating" value="'+rating_val+'" />' ).appendTo( fieldset );
			rating_el = fieldset.find( 'input[name=rating]' );

			ratings_html = '<p>Rate this site:</p>';
			ratings_html+= '<div>';
				ratings_html+= '<span rel="rating_1">1 Star</span>';
				ratings_html+= '<span rel="rating_2">2 Stars</span>';
				ratings_html+= '<span rel="rating_3">3 Stars</span>';
				ratings_html+= '<span rel="rating_4">4 Stars</span>';
				ratings_html+= '<span rel="rating_5">5 Stars</span>';
			ratings_html+= '</div>';

			$( ratings_html ).appendTo( fieldset );

			ratings = fieldset.find( 'span' );

			fieldset.find( 'span[rel=rating_' + rating_val + ']' ).addClass( 'active' )
				.prevAll().addClass( 'active' );

			ratings.bind({
				mouseenter: function() {
					ratings.removeClass( 'active current' );

					$( this ).prevAll().andSelf().addClass( 'active' );
				},

				mouseleave: function() {
					ratings.removeClass( 'active current' );

					fieldset.find( 'span[rel=rating_' + rating_val + ']' )
						.addClass( 'current' ).prevAll().andSelf().addClass( 'active' );
				},

				click: function() {
					ratings.removeClass( 'active current' );

					selected_rating = $( this );

					selected_rating.addClass( 'current' )
						.prevAll().andSelf().addClass( 'active' );

					rating_val = selected_rating.attr( 'rel' ).split( '_' )[1];
					rating_el.val( rating_val );
				}
			});

			return this;

		};

		$(' #comment_form ').commentRating();

	});



