﻿
/* File "library.js" */

var COOKIE_NAME  = 'aubay';
var COOKIE_VALUE = 'flag';
var PUBLIC_EVENT_CALENDAR_URL = 'http://www.google.com/calendar/feeds/aolmo%40aubay.es/public/basic';

/**
 * [TODO]
 *
 * @author Antonio Olmo Titos <aolmo@aubay.es>
 */

$ (document).ready (function () {

	highlightMenuItems ();

	if ($.cookie (COOKIE_NAME))
		showElements ();
	else {	
		$.cookie (COOKIE_NAME, COOKIE_VALUE);
		animateElements ();
	}

/*	$ ('#eventcalendar').fullCalendar ({
		events:      $.fullCalendar.gcalFeed (PUBLIC_EVENT_CALENDAR_URL),
		firstDay:    1,
		weekends:    false,
		defaultView: 'month',
		header: {
			left:   'month,basicWeek title',
			center: '',
			right:  'prev,next'
		}
	}); */

	$ ('.tabs').tabs ();
	transformExternalLinks ();

});

/**
 * Function "transformExternalLinks".
 *
 * [TODO]
 *
 * @author Antonio Olmo Titos <aolmo@aubay.es>
 */

function transformExternalLinks () {

	$ ('a').each (function (i) {
		if ($ (this).attr ('rel') && $ (this).attr ('rel').indexOf ('external') > -1)
			$ (this).attr ('target', '_blank');
	});

}

/**
 * Function "highlightMenuItems".
 *
 * [TODO]
 *
 * @author Antonio Olmo Titos <aolmo@aubay.es>
 */

function highlightMenuItems () {

	var parents = ['.solidblockmenu', '.markermenu'];
	var url = document.location.href;

	for (var i in parents) {

		$ (parents [i] + ' a.menuitem').each (function (j) {
			if (url.indexOf ($ (this).attr ('href')) > -1)
				$ (this).addClass ('current');
		});

		if ($ (parents [i] + ' a.menuitem.current').length < 1 &&
		    url.indexOf ('map.asp') < 0 && url.indexOf ('legal.asp') < 0)
			$ (parents [i] + ' a.firstmenuitem').addClass ('current');

	}

}

/**
 * Function "animateElements".
 *
 * [TODO]
 *
 * @author Antonio Olmo Titos <aolmo@aubay.es>
 */

function animateElements () {

	if ($.support.opacity) {
		$ ('img#largeLogo').fadeIn (3000, function () {
			$ ('div#footer').slideDown (600);
		});
	} else {
		// IE doesn's support opacity (uses alpha filters instead) and because of that
		// the "fadeIn" effect for the logo doesn't work very well...
		$ ('img#largeLogo').show ();
		$ ('div#footer').slideDown (600);
	}

	dropFirstHiddenMenuElement ();

}

/**
 * Function "showElements".
 *
 * [TODO]
 *
 * @author Antonio Olmo Titos <aolmo@aubay.es>
 */

function showElements () {

	$ ('img#largeLogo').show ();
	$ ('div#top_nav > ul > li > a:hidden').show ();
	$ ('div#footer').show ();

}

/**
 * Function "dropFirstHiddenMenuElement".
 *
 * [TODO]
 *
 * @author Antonio Olmo Titos <aolmo@aubay.es>
 */

function dropFirstHiddenMenuElement () {

	var elements = $ ('div#top_nav > ul > li > a:hidden');

	if (elements && elements.length > 0)
		$ (elements [0]).slideDown (300, dropFirstHiddenMenuElement);

}

// EOF


