$(document).ready(function(){
    if (document.body.filters) true;
    
	$('.menu>ul>li').each(function(){
		if ($(this).hasClass('active')){
			$('.menu li').removeClass('current_item_parent');
			//$('.menu ul li ul li').removeClass('active');
		}
	});
	
	$('.menu ul a.right').next('ul').css({
		left: 'auto',
		right: '40px'
	});
	
	$('.menu ul a.locations').next('ul').css({
		left: '-187px',
		width: '703px'
	});
	
	showSubnav();

	$('div.wpcf7-response-output').replaceWith('');
	$('.wpcf7').prepend('<div class="wpcf7-response-output wpcf7-display-none"></div>');
	
	setTimeout(function(){
		Cufon.replace('.header .menu ul li a', {hover: true})('.content .box .headline')('.content p.follow span')('.header .class-schedules>a')('.content .info-box p')
		('.content .sedona-info p')('.content .sedona-info h4')('.content h1')('blockquote');
	}, 200);

	doSlideshow('rotator', true, 10000);
	
	$('.workshops .description div:first').show();
	
	$('.workshops .list a').click(function(){
		var thisPostId = $(this).attr('rel');
		$('.workshops .description div').hide();
		$('.workshops .description div.post-content'+thisPostId).show();
	});
	
	/* Calender Styling */
	if ($('div.workshops').length > 0 ){
		$('.cat-key strong').text('');
		$('table.calendar-table td.day-with-date').each(function(){
			if ($(this).hasClass('no-events')){
			}else{
				var bgColor = $(this).find('a').css('background-color');
				$(this).css('background-color', bgColor);
				$(this).hover(function(){
					$(this).find('a').attr('href', 'javascript:;');
					$(this).children('span').hide();
					$(this).find('span.event').css('display', 'block');
				},function(){
					$(this).children('span').show();
					$(this).find('span.event').hide();
				});
			};
		});
	};
	
	/*Correct columns width in IE6*/
	if ($.browser.msie && $.browser.version == 6){
		correctWidth();
	};
	
	/*FAQ Roll*/
	$('.question a').click(function(){
		if ($(this).parent().hasClass('open')){
			$(this).parent().removeClass('open');
		}else{
			$('.question').removeClass('open');
			$(this).parent().addClass('open');
		}
	});
	
	/* Teachers Popup */
	$('.teachers-list a.teacher').click(function(){
        $('.teachers-list a.teacher.activ').removeClass('activ');
        $(this).addClass('activ');
        
        
        $('.overlay').height($(document).height());
        $('.overlay').width($(document).width());
		var popupLeft = (($(document).width()) - 801) / 2;
		$('.popup').css('left', popupLeft);
		$('.overlay, .popup').show();
        if ($.browser.msie && $.browser.version == 6){
            $('select').hide();
        }
        $('.overlay, .popup a.close').click(function(){
            $('.overlay, .popup').hide();
            $('select').show();
        });
        
        $('.popup a.prev, .popup a.next').unbind('click');
        $('.popup a.prev, .popup a.next').click(function(){
            $('.popup .loader').height($('.popup .text').height()).show();            
            var curr = $('.teachers-list a.teacher.activ');
            var nextEl = curr;
            if ($(this).hasClass('prev')){
                nextEl = curr.prev();
                if ($('.teachers-list a.teacher:first').hasClass('activ')){
                    nextEl = $('.teachers-list a.teacher:last');
                }
            } else {
                nextEl = curr.next();
                if ($('.teachers-list a.teacher:last').hasClass('activ')){
                    nextEl = $('.teachers-list a.teacher:first');
                }
            }
            curr.removeClass('activ');
            nextEl.addClass('activ');
            $('.popup .middle .text').load(nextEl.attr('href') + '&ajax=1', function(){
                $('.popup .loader').hide();           
            });           
            
        }); 
        
        $('.popup .loader').height($('.popup .text').height()).show();                    
		$('.popup .middle .text').load($(this).attr('href') + '&ajax=1', function(){
            $('.popup .loader').hide();           
        });
        
		return false;
	});
	
	/* Pricing Popup */
	$('.content .right-col #pricing a').click(function(){
        
        $('.overlay').height($(document).height());
        $('.overlay').width($(document).width());
		$('.popup .prev, .popup .next').hide();
		var popupLeft = (($(document).width()) - 607) / 2;
		$('.popup').css('left', popupLeft);
		$('.overlay, .popup').show();

        $('.overlay, .popup a.close').click(function(){
            $('.overlay, .popup').hide();
        });
        
        $('.popup .loader').height($('.popup .text').height()).show();
		$('.popup .middle .text').addClass('prices').load($(this).attr('href') + '?ajax=1', function(){
            $('.popup .loader').hide();
        });
        
		return false;
	});
	
	
	/* Search By Location */
	$('#loc-search').change(function(){
		var location = $(this).val();
		var str = window.location.href;
		var currAddr = str.split('?');
		if (location == 'All teachers'){
			window.location.href = currAddr[0];
		}else{
			window.location.href = currAddr[0]+'?loc='+location;
		}
	});

	$('#rotator .marker').click(function() {
		var index = $('#rotator .marker').index(this);
		doSlideshow('rotator', true, 10000, $($('#rotator li').get(index)));
	});
});

var slideshowTimer = null;
function doSlideshow(objid, start, time, nextObj){
	if(!$('#' + objid) || !isVisible($('#' + objid))){
		if(slideshowTimer != null){
			clearTimeout(slideshowTimer);
			slideshowTimer = null;
		}
		return;
	}
	
	if(start){
		clearTimeout(slideshowTimer);
		slideshowTimer = null;
	}
	
	var currObj = $('#' + objid + ' li.current');
	if(!nextObj) nextObj = currObj.next();
	if($('#' + objid + ' li:last').hasClass('current')){
		nextObj = $('#' + objid + ' li:first');
	}

	var index = $('#' + objid + ' li').index(nextObj);
	var marker = $('#' + objid + ' .marker').get(index);
	$('#' + objid + ' .marker').removeClass('current');
	$(marker).addClass('current');

	nextObj.addClass('current');
	nextObj.css('opacity', 0);
	currObj.removeClass('current');
	currObj.animate({opacity:0}, 2000);
	nextObj.animate({opacity:1}, 2000);
	

	slideshowTimer = setTimeout('doSlideshow("' + objid + '", false, ' + time + ');', time);
}

function isVisible(obj) { return (obj.css('display') == 'block'); }

function correctWidth(){
	$('.post_column_1').each(function(){
		var width = $(this)[0].style.width;
		var padd = $(this)[0].style.paddingRight;
		var correctWidth = parseInt(width)+parseInt(padd);
		$(this).css('width', correctWidth+'%');
	});
	
}

function showSubnav(){
	var addr = window.location.href;
	var inLoc = addr.split('locations');
	if (inLoc[1])
		$('.menu ul a.locations:first').next('ul').show();
}
