var libJS = {

	initDoc: function() {

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

		$('#nav').hover(function(e) { libJS.navRaise(e); },function(e) { libJS.navLower(e); });
		$('#nav ul').css({top:'35px'});
		$('#content').css('top','550px');
		$('#nav a').focus(function(e) { libJS.navRaise(e); }).click(function(e) { libJS.contentLower(e); });

		$('a.profile-don-link').hover(function(e) { libJS.toggleProfile(e,'don'); },function(e) { }).click(function(e){ e.preventDefault(); });
		$('a.profile-jan-link').hover(function(e) { libJS.toggleProfile(e,'jan'); },function(e) { }).click(function(e){ e.preventDefault(); });

		$('#profile-don').hide();
		$('#profile-jan').hide();

		$('p.delete_link a').click(function(e) {
			var r = confirm('Are you sure you want to delete this item?')
			if (r == true) {
				return true;
			} else {
				return false;
			}
			});

		},

	initWindow: function() {

		if ($('#user_name').length > 0) { $('#user_name').focus(); }
	
		},

	navRaise: function(e) {

		$('#nav ul').stop().animate({top:'10px'},1000,'easeOutElastic');
		$('#nav').stop().animate({height:'70px'});

		},

	navLower: function(e) {

		$('#nav ul').stop().animate({top: '35px'},'fast','jswing');
		$('#nav').stop().animate({height: '60px'});

		},

	contentRaise: function(e) {
		
		$('#content').animate({top: '360px'},500,'easeOutQuad');

		},

	contentLower: function(e) {
		
		e.preventDefault();
		obj = $(e.target);
		libJS.navLower();
		$('#content').animate({top: '550px'},500,'jswing',function(){ window.location.href = obj.attr('href'); });

		},

	toggleProfile: function(e,person) {

		e.preventDefault();
		obj = $(e.target);

		$('#profile-don').fadeOut();
		$('#profile-jan').fadeOut();

		if (person == 'don') {
			$('#profile-don').fadeIn();
		} else {
			$('#profile-jan').fadeIn();
		}		

		},

	charCountAndTrim: function() {

		var charLimit = 150;

		var val = document.getElementById('details');

		if (val.value.length > charLimit) {
			//	alert('Sorry, you are over the limit of ' + charLimit + ' characters');
			val.value = val.value.substring(0,charLimit);
			val.focus();
		}

		var currentCount = val.value.length;
		$('#counter').html(''+currentCount+'');

		},

	clubLogoImages: '<img src="/media/content/club-logo-1.gif" alt="Guards Polo Club" /><img src="/media/content/club-logo-3.gif" alt="Cowdray Park Polo Club" /><img src="/media/content/club-logo-4.gif" alt="Royal County of Berkshire Polo Club" /><img src="/media/content/club-logo-6.gif" alt="Hurtwood Polo Club" />',

	screensLogoImages: '<img src="/media/content/screens-logo-1.png" alt="Porsche" /><img src="/media/content/screens-logo-2.png" alt="Berluti Shoes" />',

	sponsorshipLogoImages: '<img src="/media/content/sponsorship-logo-1.gif" alt="Polo Masters Tournament" /><img src="/media/content/sponsorship-logo-2.gif" alt="Guards Polo Club" /><img src="/media/content/sponsorship-logo-3.gif" alt="Cowdray Park Polo Club" />',

	partnersLogoImages: '<a href="http://www.themaineventintl.com/"><img src="/media/content/partner-logo-1.gif" alt="The Main Event" /></a><a href="http://www.youknow.uk.com/"><img src="/media/content/partner-logo-2.gif" alt="You Know. Video Design &amp; Production" /></a><a href="http://www.cubavision.co.uk/"><img src="/media/content/partner-logo-3.gif" alt="Blue Tuna" /></a><a href="http://www.polotimes.co.uk/"><img src="/media/content/partner-logo-4.gif" alt="Polo Times" /></a><img src="/media/content/partner-logo-5.gif" alt="Apre&eacute;s Polo" /><a href="http://www.mercadoargentino.com/"><img src="/media/content/partner-logo-6.gif" alt="Mercado Argentino" /></a><a href="http://www.polonetworks.com/"><img src="/media/content/partner-logo-7.gif" alt="PoloNetworks.com" /></a><a href="http://www.theadigroup.com/"><img src="/media/content/partner-logo-8.gif" alt="The ADI Group" /></a><a href="http://www.jmpmedia.co.uk/"><img src="/media/content/partner-logo-9.gif" alt="JMP Media" /></a><a href="http://www.thepolomagazine.com/"><img src="/media/content/partner-logo-10.gif" alt="Polo Magazine" /></a><a href="http://www.silverchair.co.uk/"><img src="/media/content/partner-logo-11.gif" alt="Silver Chair" /></a>',

	swapInClubLogos: function() {

		$('body.about #cycle-gallery').html(libJS.clubLogoImages);

		},

	swapInSponsorshipLogos: function() {

		$('body.sponsorship #cycle-gallery').html(libJS.sponsorshipLogoImages);

		},

	swapInPartnersLogos: function() {

		$('body.partners #cycle-gallery').html(libJS.partnersLogoImages);

		}

}

$('body.about #cycle-gallery').ready( function() { libJS.swapInClubLogos() } );

$('body.sponsorship #cycle-gallery').ready( function() { libJS.swapInSponsorshipLogos() } );

$('body.partners #cycle-gallery').ready( function() { libJS.swapInPartnersLogos() } );

$(document).ready(libJS.initDoc);

$(window).ready(function() {
	libJS.contentRaise();
//	libJS.initWindow();

	$('#cycle-gallery').cycle({ 
	    fx:    'fade', 
		pause:  2, 
	    speed:  0
	 });

	});

$(document).ready(function() {

    var options = {
		loadingImage: '/scripts/shadowbox-1.0-code/images/loading.gif',
		displayNav: true,
		continuous: true,
		flvPlayer: '/media/flvplayer.swf',
		overlayBgImage: '/scripts/shadowbox-1.0-code/images/overlay-85.png'
    };

    Shadowbox.init(options);});