$(document).ready(function(){
	$("#faq-accordion").accordion({collapsible: true, autoHeight: false, active: 1 });					   
						   
	var isOldIE = $.browser.msie && $.browser.version < 7;
	if(isOldIE){
	}
	
	/********BEGIN Sub menu **********/
	var _timerSearch;
	var _flagSearch = true; 
	$(".header-bottom .menu-top li#item-submenu").hover(
		function(){
			$(this).addClass('hover'); clearTimeout(_timerSearch);
		},function(){
			if(_flagSearch) beginTimerSearch();
		}
	);
	$('.header-bottom .menu-top li#item-submenu .submenu .textbox').focusin(function(){
			_flagSearch = false;
			clearTimeout(_timerSearch);
	});
	$('.header-bottom .menu-top li#item-submenu .submenu .textbox').focusout(function(){
			beginTimerSearch();
	});
	function beginTimerSearch(){
		_timerSearch = setTimeout(function(){$(".header-bottom .menu-top li#item-submenu").removeClass('hover');},1500);
	}
	/******** END Sub menu **********/
	
	var album_id = $("meta[name='album_id']").attr('content');//'72157624150654379'
	$.getJSON("http://api.flickr.com/services/feeds/photoset.gne?set="+album_id+"&nsid=27050332@N02&lang=es-us&format=json&jsoncallback=?",
		function(data){
			var li = $("<li></li>");
			var count = 1;
			
			$.each(data.items, function(i,item){
				var _pic = "<a href='"+item.link+"' target='_blank'><img width='75' height='75' alt='' src='"+item.media.m.replace("_m","_s")+"' /></a>";
				li.append(_pic);
				if(count == 3){
					$('#carousel-flickr ul').append(li);
					li = $("<li></li>");
					count = 0;
				}
				count++;
			});
			if( li.length > 0 )	{
				$('#carousel-flickr ul').append(li);
			}
			$('#carousel-flickr').jCarouselLite({
				btnNext: ".box-flickr .next",
				btnPrev: ".box-flickr .prev",
				visible: 2,
				scroll:1,
				speed:1000,
				vertical: true
			});
			$("#accordion").accordion();
		}
	);		

	$('.list-nav a').click(
		function(){
			var _this = $(this);
			var _container = _this.parents('.box-banner-large');			
			_container.find('.list-nav').find('li').removeClass();
			_this.parent().addClass('selected');
			
			_container.find('.list-content').find('li').fadeOut();
			_container.find('.list-content').find(_this.attr('href')).fadeIn();
			
			return false;
		}
	);

$('#carousel').jCarouselLite({
        auto: 5000,
        btnNext: ".box-carousel .next",
        btnPrev: ".box-carousel .prev",
		visible: 6,
		scroll:1,
		speed:1000
    });

    $("box-carousel #carousel").jCarouselLite({
        auto: 5000,
        speed: 1000,
        btnNext: ".box-news-content .next",
        btnPrev: ".box-news-content .prev"
    });
	
	$('label.overlabel').overlabel();
	//$("#accordion").accordion();
	$("#accordion-right").accordion();
	$("#accordion-about-president").accordion({active:1});
	$("#tabs-upcoming").tabs();
	
	/*Drop Down*/
	$('#combo > li').bind('mouseover', jsddm_open);
	$('#combo > li').bind('mouseout',  jsddm_timer);
	/*Drop Down*/
	
	$('div.jtab-control').each(function(){
                var _jcontrol = $(this);
                var _jcontent = $('.jtab-content>.jtab-content-box',_jcontrol);
                _jcontrol.attr('actioninprogress','false');
                _jcontrol.find('>ul.jtab-items>li>a').click(function(){
                    if( _jcontrol.attr('actionInProgress')!='true' )
                    {
                        _jcontrol.attr('actioninprogress','true');
                        var _this = $(this);
                        var _target = _this.attr('href');
                        _jcontrol.find('>ul.jtab-items>li').removeClass('jtab-items-selected');
                        _this.parent().addClass('jtab-items-selected');
                        //_jcontent.filter('.jtab-content-box-selected').removeClass('jtab-content-box-selected');
                        _jcontent.filter('.jtab-content-box-selected').fadeOut(function(){
                            _jcontent.filter('.jtab-content-box-selected').removeClass('jtab-content-box-selected');
                            $(_target, _jcontrol).fadeIn(function(){
                                $(_target, _jcontrol).addClass('jtab-content-box-selected');
                                _jcontrol.attr('actioninprogress','false');
                            });
                        });
                        //$(_target, _jcontrol).addClass('jtab-content-box-selected');
                    }
                    return false;
                });
            });
	
			/*BEGIN DIALOG PAST EVETN LOCATION*/
			try{		
				$("#dialog-pasteventsdetails").dialog({
					autoOpen: false,
					bgiframe: true,
					width: 600,
					height: 356,
					modal: true
				});
			} catch(e){}
			
			/*END DIALOG PAST EVETN LOCATION*/
			
			/*BEGIN DIALOG SIGN UP EMAIL*/
			$("a[onclick*='dialog-signupemail']").ready(function(){
			   var sHTML = '<div class="hid"><div id="dialog-signupemail"><iframe height="349" frameborder="0" width="365" src="/popups/signup-newsletter.aspx" allowtransparency="true"></iframe></div></div>'
			   $('body').append(sHTML);
			});
			try{		
				$("#dialog-signupemail").dialog({
					autoOpen: false,
					bgiframe: true,
					width: 365,
					height: 349,
					modal: true
				});
			} catch(e){}
			
			/*END DIALOG SIGN UP EMAIL*/	
		
});
function closeDialog( cid ){
		$('#'+cid).dialog('close');
		return false;		
	}
function openDialog( cid ){
	$('#'+cid).dialog('open');
	return false;		
}
/*BEGIN drop down funcctions*/
var timeout         = 500;
var closetimer		= 0;
var ddmenuitem      = 0;

function jsddm_open()
{	jsddm_canceltimer();
	jsddm_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');}

function jsddm_close()
{	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{	closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{	if(closetimer)
	{	window.clearTimeout(closetimer);
		closetimer = null;}}
		document.onclick = jsddm_close;	
/*END drop down funcctions*/

(function($){
/* = plug-in : overlabel */
	$.fn.overlabel = function(options){
		var opts = $.extend( {},$.fn.overlabel.defaults, options );
		var selection = this.filter('label[for]').map(function(){
				var label = $(this);
				var id = label.attr('for');
				var field = $('#'+id);
				if(!field) return;
				var o = $.meta ? $.extend( {}, opts, label.data() ) : opts;
				label.addClass(o.label_class);
				var hide_label = function(){ label.css(o.hide_css) };
				var show_label = function(){ this.value || label.css(o.show_css) };
				$(field)
					.parent().addClass(o.wrapper_class).end()
					.focus(hide_label).blur(show_label).each(hide_label).each(show_label);
				return this;
		});
		return opts.filter ? selection : selection.end();
	};
	$.fn.overlabel.defaults = {
		label_class: 'overlabel-apply',
		wrapper_class: 'overlabel-wrapper',
		hide_css: { 'display': 'none' },
		show_css: { 'display': 'block' },
		filter: false
	};

	/* =plug-in : equal-heights */
	$.fn.equalizeCols = function(){
		var height = 0,
			reset = $.browser.msie ? "1%" : "auto";
  
		return this
			.css("height", reset)
			.each(function() {
				height = Math.max(height, $(this).outerHeight(true));
			})
			.css("height", height)
			.each(function() {
				var h = $(this).outerHeight(true);
				if (h > height) {
					$(this).css("height", height - (h - height));
				};
			});
			
	};
	
			
})(jQuery);
