// roy-hart-theatre.com js by Arno Peck 2010


jQuery(document).ready(function(){
    

browserOk = 1;

if ((jQuery.browser.msie) && (jQuery.browser.version <= 7)) {
	browserOk = -3;
	jQuery('.widget-area').css('float', 'right')
}

if ((jQuery.browser.msie) && (jQuery.browser.version >= 8)) {
	browserOk = 0;
}




// section label
jQuery("#subnav").append('<div id="section_label">WELCOME</div>');
if (jQuery('body').hasClass('search-results')) {
	jQuery('#subnav #section_label').text( 'SEARCH' );
}

jQuery('ul.menu > li > a').click( function() {
	//jQuery('ul.sub-menu').slideUp('fast');
	jQuery('ul.menu > li > a').removeClass('expanded');
	jQuery(this).addClass('expanded');
	//jQuery(this).parent().find('ul.sub-menu').slideToggle('slow');
	
	
	// main section menu get first subpage url on click except the home
	if ( jQuery(this).parent().find('ul.sub-menu').size() > 0 && jQuery(this).parent().attr('id') != 'menu-item-674') {
		location.href = jQuery(this).parent().find('ul.sub-menu > li > a').attr('href');
		return false;
	}	
	
});




// set section color
function setSectionPreferences() {
	
	jQuery('#menu-main-menu .current-menu-ancestor').addClass('expanded');
	jQuery('#menu-main-menu .current-menu-ancestor').find('ul.sub-menu').slideToggle('fast');
	
	if (jQuery('#menu-main-menu .current-menu-ancestor').length) {
		thisSection = jQuery('.current-menu-ancestor').attr('id');
		thisSectionTxt = jQuery('.current-menu-ancestor > a').text();
		jQuery('.current-menu-ancestor > a').addClass('expanded');
	}
	
	else if (jQuery('#menu-main-menu .current-post-ancestor').length) {
		thisSection = jQuery('.current-post-ancestor').parent().parent().attr('id');
		thisSectionTxt = jQuery('.current-post-ancestor').parent().parent().find('a:first').text();
		jQuery('.current-post-ancestor').parent().parent().find('a:first').addClass('expanded');
		if (thisSection == '') {
			thisSection = jQuery('#menu-main-menu > .current-post-ancestor').attr('id');
			thisSectionTxt = jQuery('#menu-main-menu > .current-post-ancestor').find('a:first').text();
			jQuery('#menu-main-menu > .current-post-ancestor').find('a:first').addClass('expanded');
			jQuery('#menu-main-menu > .current-post-ancestor').find('.sub-menu').slideToggle('slow');
		}
		else {
			jQuery('#menu-main-menu .current-post-ancestor').parent().parent().find('.sub-menu').slideToggle('slow');
		}
	}
	
	else {
		thisSection = jQuery('#menu-main-menu .current-menu-item').attr('id');
		thisSectionTxt = jQuery('#menu-main-menu .current-menu-item > a').text();
		jQuery('#menu-main-menu .current-menu-item > a').addClass('expanded');
	};
	
	if (thisSection) {
		thisSection = thisSection.replace(/menu-item/i, "section");
		jQuery('#subnav').removeClass();
		jQuery('#subnav').addClass( thisSection );
		jQuery('#subnav #section_label').text( thisSectionTxt );
	}


	// in home expand home submenu
	if (thisSection == 'section-674') {
		//alert('home section');
		jQuery('.menu-item-674 .sub-menu').slideDown();
	}
	
	jQuery('li li.current-menu-item a').css('color',jQuery('#subnav').css('background-color'));
	jQuery('li li.current-post-ancestor a').css('color',jQuery('#subnav').css('background-color'));

}


setSectionPreferences();

// expand article in category page
/* if (! jQuery('body').hasClass('search-results')) { */
jQuery('.entry-title a[class!="enroll"]').click( function exPost(){
	jQuery(this).parent().parent().find('.entry-content').slideToggle('fast'); 
	jQuery(this).parent().parent().toggleClass('entry-expanded');
	if(jQuery(this).parent().parent().hasClass('entry-expanded')){
		jQuery(this).parent().css('background-color', jQuery('#subnav').css('background-color'));
	}
	else {
		//jQuery(this).parent().css('background-color', '#fff');
		jQuery(this).parent().attr('style', '');
	}
	return false;
});
/* } */


// fix cfform select value bug...
jQuery('.wpcf7-submit').click(function() {
	jQuery('.course_selection1 input').val(jQuery('#course_list').val());
	jQuery('.course_selection2 input').val(jQuery('#course_list2').val());
});


// set target _blank on links in page links
jQuery('.linklist a').attr('target','_blank');


// download links in title bar if is found link with class "download"
	function rh_download() {
	var rhFiles = "";
	var rhDownloadInit = 0;
	jQuery('#content p a').each(function(){
		
		var downloadType = jQuery(this).attr("href").substr(-3);
		var downloadClass = jQuery(this).attr('class');
		var downloadIcon = 'icon_' + downloadType;
		jQuery(this).addClass(downloadIcon);
		
		if (jQuery(this).hasClass("download") ) {				
			var downloadTitle = jQuery(this).text();
			var downloadUrl = jQuery(this).attr("href");
			rhFiles = rhFiles+'<a href="' + downloadUrl + '" title="download ' + downloadTitle + '" class="' + downloadClass + ' ' + downloadIcon + '" target="_blank"><span>' + downloadTitle + '</span></a>';
			rhDownloadInit++;
		}
	});
		
	if (rhDownloadInit != 0) {
		
		jQuery('.taxonomy-description h1').append('<span class="rh_dowloadarea"><span class="rh_downloadlabel">Download:</span></span>');
		jQuery('.rh_dowloadarea').append(rhFiles);
		jQuery('.rh_dowloadarea a span').css('border-color', jQuery('#subnav').css('background-color'));
		jQuery('.rh_dowloadarea a').fadeIn(600);
		
	}
}

rh_download();


// open big picture on thumb click
jQuery('.category .post .post-image, .search .post .post-image').each(function(){
	jQuery(this).parent().addClass('thickbox');

	var bigImgUrl = jQuery(this).attr('src').replace('-150x150','');
	jQuery(this).parent().attr('href', bigImgUrl);

});
	
	


// append news
jQuery('.rh_news').appendTo('.entry-content');

//jQuery('.rh_news').after(jQuery('.addtoany_share_save_container'));
//jQuery().appendTo('.entry-content');



// add credits link
var creditLink = jQuery('#menu-main-menu').find('li:first > a').attr('href');
creditLink = creditLink + 'credits';
creditLink = '<span class="credits"><a href="' + creditLink + '">Credits</a></span>';
jQuery(creditLink).appendTo('.footer-widgeted-1');


// DEBUG 

// IE font replace
if (jQuery.browser.msie == true) {
	jQuery('#section_label').css('font-family', 'Georgia');

}


// Others functions
/*function updateText() {
	document.frm.os0.value = document.frm.rf_course.value;
	if (document.frm.nature.value != 0) document.frm.os0.value += " / " + document.frm.nature.value;
	if (document.frm.nature2.value != 0) document.frm.os0.value += " / " + document.frm.nature2.value;
	if (document.frm.nature3.value != 0) document.frm.os0.value += " / " + document.frm.nature3.value;
}*/

// populate info input for paypal 
jQuery('#frm select').change(function(){
	var info_label = jQuery('#course_list').val();
	if (jQuery('#nature').val() != 0 ) { info_label = info_label + ' / ' + jQuery('#nature').val(); }
	if (jQuery('#nature2').val() != 0 ) { info_label = info_label + ' / ' + jQuery('#nature2').val(); }
	if (jQuery('#nature3').val() != 0 ) { info_label = info_label + ' / ' + jQuery('#nature3').val(); }
	jQuery('#os0').attr('value', info_label);
});



// mostra pulsante edit nei post nelle pagine categorie
jQuery('.post').each(function(){
	postEl = jQuery(this);
	edBtn = postEl.find('.post-edit-link')
	edBtn = edBtn.css('margin-bottom','20px');
	edBtn= edBtn.appendTo(postEl.find('.entry-content'));
});





});

