/* jQuery elementReady plugin
 * Version 0.6
 * Copyright (C) 2007-08 Bennett McElwee.
 * Licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License (http://creativecommons.org/licenses/by-sa/3.0/)
 * Permissions beyond the scope of this license may be available at http://www.thunderguy.com/semicolon/.
 * Documentacao: http://www.thunderguy.com/semicolon/plaintext/jquery.elementReady.js
 */

(function($) {

var interval = null;
var checklist = [];

$.elementReady = function(id, fn) {
	checklist.push({id: id, fn: fn});
	if (!interval) {
		interval = setInterval(check, $.elementReady.interval_ms);
	}
	return this;
};

// Plugin settings
$.elementReady.interval_ms = 100; // polling interval in ms

// Private function
function check() {
	var docReady = $.isReady; // check doc ready first; thus ensure that check is made at least once _after_ doc is ready
	for (var i = checklist.length - 1; 0 <= i; --i) {
		var el = document.getElementById(checklist[i].id);
		if (el) {
			var fn = checklist[i].fn; // first remove from checklist, then call function
			checklist[i] = checklist[checklist.length - 1];
			checklist.pop();
			fn.apply(el, [$]);
		}
	}
	if (docReady) {
		clearInterval(interval);
		interval = null;
	}
};

})(jQuery);








// implementacao dos slides
(function($) {

$.fn.slides = function( )
{ // slides nos banners

	var tgt = $( this );
	var srcs = '';
	var links = '';

	var lis = tgt.find( 'li' );
	if( lis.length<=1 ) {
		$('ul', this).css( 'height', 'auto' );
		$('ul li', this).css(
			{
				'position': 'static',
				'visibility': 'visible'
			}
		);

		return false;
	}

	lis.each(
		function() {
			var img = $(this).find('img:first');
			if( img ) img = img.attr('src');
			else {
				img = $(this).find('object:first');
				img = img.attr('data');
			}
			srcs += img +',';

			var a = $(this).find('a:first');
			a = a.attr('href');
			if( a==undefined ) a='';
			links += a +',';
		}
	);

	var vars = {
		'imgs' : srcs.substring( 0 , srcs.length-1 ),
		'links' : links.substring( 0 , links.length-1 )
	};


	tgt.flash(
		{
		src: './swf/destaques.swf',
		width: 800,
		height: 200,
		wmode: 'transparent',
		flashvars: vars
		}
	);

	var ul = tgt.find('ul');

	ul.css('display', 'none');

	//bodyLoad.add( function() { DOM.rem( ul ); } );
	$(document).ready(function(){ ul.remove(); });

}

})(jQuery);


//$.elementReady( 'movie', $.fn.slides );
$(document).ready( function(){ $('#movie').slides(); } );
