/* ------------------------------------------------- */
/* ON DOM READY
/* ------------------------------------------------- */
jQuery(document).ready(function($) {
	/* ------------------------------------------------- */
	/* COLORBOX SHIT
	/* ------------------------------------------------- */
		$("a.colorbox").colorbox();
	/* ------------------------------------------------- */
	/* INIT SCROLLABLE
	/* ------------------------------------------------- */
		$('div.scrollable').scrollable({size:1,clickable:false});
		$('a.nav').click(function(e) { e.preventDefault(); });
	/* ------------------------------------------------- */
	/* SLIDESHOW BEHAVIORS
	/* When you rollover the slideshow, the title slides
	/* away. On rollout the title appears again 
	/* ------------------------------------------------- */
		if($('#content-header').size() > 0)
		{
			var show = $('#content-header');
			var title = $('#content-header').find('h1');
			show.hover(function() {
				title.animate({left:0 - (title.width() + 15)}, 500);
			}, function() {
				title.animate({left:0}, 500);
			});
			// INIT SLIDE SHOW
			$('div.slideshow').cycle(
				{fx:'scrollRight',
				 before:function() {
					if(this.title != '') {
						var title = this.title.split('|');
						$('h1 #caption').html('<strong>' + title[0] + '</strong><br />' + title[1]);
					}
				}
			});
		}
	/* ------------------------------------------------- */
	/* ITEM MEDIA TAB BEHAVIORS
	/* By clicking on the subnav (lis) we show/hide
	/* the content (tabs)
	/* ------------------------------------------------- */
		$('div.tabs-content').each(function() {
			var content	= $(this);
			var tabs	= content.find('div.tab');
			var lis		= content.find('ul.tabs li');
			
			tabs.hide();
			content.find('div.tab:first').show();
			content.find('ul.tabs li:first').addClass('current');
			
			lis.live('click', function() {
				lis.removeClass("current");
				$(this).addClass("current");
				tabs.hide();
				var activeTab = $(this).find("a").attr("href");
				$(activeTab).fadeIn();
				return false;
			});
		});
	/* ------------------------------------------------- */
	/* EXTENDED BODY BEHAVIORS FOR NEWS
	/* ------------------------------------------------- */
		$('a.read-more').each(function() {
			var a = $(this);
			var div = $($(this).attr('href'));
			var intro = $(this).parent().parent().find('div.item-intro');
			div.hide();
			a.click(function(e) {
				e.preventDefault();
				var id = div.attr('id');
				var old = $('div.item-extended:visible');
				// CLOSE OPEN ONES, BUT JUST TOGGLE CLOSE IF WE CLICK ON THE SAME DIV
				if(id != old.attr('id')) {
					old.slideToggle()
					old.parent().toggleClass('open');
					old.parent().find('div.item-intro').slideToggle();
				}
				div.slideToggle()
				div.parent().toggleClass('open');
				intro.slideToggle();
			});
		});
	/* ------------------------------------------------- */
	/* EXTENDED BODY BEHAVIORS FOR AGENDA
	/* ------------------------------------------------- */
		$('div.agenda div.item').each(function() {
			var div = $(this).find('div.item-extended');
			if(!$(this).hasClass('open')) div.hide();
			$(this).hover(function() { $(this).toggleClass('hover') }, function() { $(this).toggleClass('hover') });
			$(this).click(function() {
				var old = $('div.item div.item-extended:visible');
				
				if($(this).attr('id') != old.parent().parent().attr('id')) {
					old.slideToggle()
					old.parent().parent().toggleClass('open');
					
					div.slideToggle()
					$(this).toggleClass('open');
				}
			});
		});
        /* ------------------------------------------------- */
        /* VALIDATION FORM
        /* ------------------------------------------------- */
        if($('#form-subscribe').size() > 0) {
            $("#form-subscribe").validate({
                submitHandler: function(form) {
                    jQuery(form).ajaxSubmit({
                        target: "#subscribe"
                    });
                }
            });
        }
        /* ------------------------------------------------- */
        /* EMPTY FIELDS ON FOCUS
        /* ------------------------------------------------- */
        if($('#form-subscribe').size() > 0) {
            $('#form-subscribe input').each(function() {
                $(this).focus(function() {
                    if( this.value == this.defaultValue ) {
                        this.value = "";
                    }
                }).blur(function() {
                    if( !this.value.length ) {
                        this.value = this.defaultValue;
                    }
                });
            });
        }
	/* ------------------------------------------------- */
	/* STOP CLICKING ON A IN THE EXTENDED AREA FROM
	/* PROGATING IT TO IT'S PARENTS
	/* ------------------------------------------------- */
		//$('div.item div.item-extended a').not('ul.tabs li a').not('a.colorbox').click(function(e) { e.stopPropagation(); });

});
