var $j = jQuery;
////////////////////////////////
//dynamic color menu dropdown///
////////////////////////////////
$j(function(){
$j('ul#selectCat li').each(function(i, elem){
	//add arrows
	$j(this).append('<span class="arrow" />');
	$j('span.arrow').html('&raquo;');
	//switch index
	switch(i){
		case 0:
		$j(elem).addClass('show blueFirst all');
		break;

		case 1:
		$j(elem).addClass('hide purpl av');
		break;

		case 2:
		$j(elem).addClass('hide blue law');
		break;

		case 3:
		$j(elem).addClass('hide green tour');
		break;

		case 4:
		$j(elem).addClass('hide yellow common');
		break;

		case 5:
		$j(elem).addClass('hide pink concert');
		break;

		case 6:
		$j(elem).addClass('hide red events');
		break;				
	}
});


	//hide show color menu dropdown
	$j('ul#selectCat').hover(function(){
		if($j('ul#selectCat li').not('visible')){
			$j('ul#selectCat li').fadeIn('slow');
		}
	}, 
	function(){
		$j('ul#selectCat li.hide').fadeOut('slow');
	});

/////////////////////////////
///////TOP CATEGORYS/////////
////////////////////////////// 
//dynamic color category
$j('ul.cats li').each(function(i, elem){
	//add arrows
	$j(this).append('<div class="squre" />');
	$j('div.squre').css({
		'width':'21px', 
		'height':'21px',
		'margin-left':'-30px', 
		'margin-right':'10px', 
		'position':'relative',
		'margin-top':'-20px'		
	});
	
	//switch index
	switch(i){
		case 0:
		$j(elem).addClass('purpl');
		$j(elem).css('color', '#6e0fff');
		$j('div.squre, a', elem).addClass('purpl');
		break;

		case 1:
		$j(elem).addClass('blue');
		$j(elem).css('color', '#02a6af');
		$j('div.squre, a', elem).addClass('blue');
		break;

		case 2:
		$j(elem).addClass('green');
		$j(elem).css('color', '#29d373');
		$j('div.squre, a', elem).addClass('green');
		break;

		case 3:
		$j(elem).addClass('yellow');
		$j(elem).css('color', '#ffa901');
		$j('div.squre, a', elem).addClass('yellow');
		break;

		case 4:
		$j(elem).addClass('pink');
		$j(elem).css('color', '#ec29f1');
		$j('div.squre, a', elem).addClass('pink');
		break;

		case 5:
		$j(elem).addClass('red');
		$j(elem).css('color', '#ff002c');
		$j('div.squre, a', elem).addClass('red');
		break;				
	}
	
	
	//popup windows switch
	$j(this).click(function(e){
	e.preventDefault();
		var thisClass = $j(this).attr('class');
		
		switch(thisClass){
			case 'purpl':
			$j('div#purplBox').fadeIn('slow');
			break;
			
			case 'blue':
			$j('div#blueBox').fadeIn('slow');
			break;	

			case 'green':
			$j('div#greenBox').fadeIn('slow');
			break;	

			case 'yellow':
			$j('div#yellowBox').fadeIn('slow');
			break;	
			case 'pink':
			$j('div#pinkBox').fadeIn('slow');
			break;	

			case 'red':
			$j('div#redBox').fadeIn('slow');
			break;					
		}
	});
});

//close popup
$j('div#close').click(function(){
	$j(this).parent().fadeOut('slow');
});

		

/////////////////////////////////////////
//add dynamic colors to image event tag//
/////////////////////////////////////////
$j('div.image').each(function(){
	$j(this).append('<div class="evetTitleColor"></div><div class="eventColor">&nbsp;</div>');
	if($j(this).hasClass('imgPurpl')){
		$j('.evetTitleColor, .eventColor', this).css('background','#6e0fff');			
		$j('.evetTitleColor', this).append('<h4 class="center">American Voices</h4>').css('width','96px');
	}
	else if($j(this).hasClass('imgBlue')){
		$j('.evetTitleColor, .eventColor', this).css('background','#02a6af');	
		$j('.evetTitleColor', this).append('<h4 class="center">Shakespeare and the law</h4>').css('width','137px');
	}
	else if($j(this).hasClass('imgGreen')){
		$j('.evetTitleColor, .eventColor', this).css('background','#29d373');	
		$j('.evetTitleColor', this).append('<h4 class="center">Tour of the Parks</h4>').css('width','96px');		 
	}
	else if($j(this).hasClass('imgYellow')){
		$j('.evetTitleColor, .eventColor', this).css('background','#ffa901');	
		$j('.evetTitleColor', this).append('<h4 class="center">Shakespeare on the Common</h4>').css('width','158px');			 
	}
	 else if($j(this).hasClass('imgPink')){
		$j('.evetTitleColor, .eventColor', this).css('background','#ec29f1');	
		$j('.evetTitleColor', this).append('<h4 class="center">Commonwealth Concerts</h4>').css('width','136px');			 
	}
	 else if($j(this).hasClass('imgRed')){
		$j('.evetTitleColor, .eventColor', this).css('background','#ff002c');	
		$j('.evetTitleColor', this).append('<h4 class="center">Events</h4>').css('width','49px');			 
	}		 
});


////////////////////////////////////////////
////////add dynamic url to each image///////
////////////////////////////////////////////
$j('div.image').click(function(){
var sUrl = $j(this).attr('url');
window.open(sUrl, '_self');
});

/////////////////////////////////???////////
//add dynamic colors to imageLrg event tag//
////////////////////////////////////???/////
$j('div.imageLrg').each(function(){
	$j(this).append('<div class="evetTitleColor"></div><div class="buyEventColor"><h2><a href="#">Buy Tickets</a></h2></div>');
	if($j(this).hasClass('imgPurpl')){
		$j('.evetTitleColor, .buyEventColor', this).css('background','#6e0fff');			
		$j('.evetTitleColor', this).append('<h4 class="center">American Voices</h4>').css('width','96px');
	}
	else if($j(this).hasClass('imgBlue')){
		$j('.evetTitleColor, .buyEventColor', this).css('background','#02a6af');	
		$j('.evetTitleColor', this).append('<h4 class="center">Shakespeare and the law</h4>').css('width','137px');
	}
	else if($j(this).hasClass('imgGreen')){
		$j('.evetTitleColor, .buyEventColor', this).css('background','#29d373');	
		$j('.evetTitleColor', this).append('<h4 class="center">Tour of the Parks</h4>').css('width','96px');		 
	}
	else if($j(this).hasClass('imgYellow')){
		$j('.evetTitleColor, .buyEventColor', this).css('background','#ffa901');	
		$j('.evetTitleColor', this).append('<h4 class="center">Shakespeare on the Common</h4>').css('width','158px');			 
	}
	 else if($j(this).hasClass('imgPink')){
		$j('.evetTitleColor, .buyEventColor', this).css('background','#ec29f1');	
		$j('.evetTitleColor', this).append('<h4 class="center">Commonwealth Concerts</h4>').css('width','136px');			 
	}
	 else if($j(this).hasClass('imgRed')){
		$j('.evetTitleColor, .buyEventColor', this).css('background','#ff002c');	
		$j('.evetTitleColor', this).append('<h4 class="center">Events</h4>').css('width','49px');			 
	}		 
});


///////////////////////////////
/////////TWITTER FEED//////////
///////////////////////////////

if($j("#twitter").is(':visible')){
	$j('#twitter').twitterSearch({ 
		term:   'commshakes', 
		// no fade 
		animOut: { opacity: 0 }, 
		avatar:  false, 
		anchors: false, 
		bird:    false, 
		colorExterior: 'transparent', 
		colorInterior: 'transparent', 
		pause:   true, 
		time:    true,
		title:   false, 			
		timeout: 7090

	});
};

/////////////////////////
//////CYCLE PLUGIN///////
/////////////////////////

jQuery('div#carousel').cycle({		
	fx: 'scrollHorz',		
	timeout: 800000,		
	cleartypeNoBg: true,		
	next: 'a.next',		
	prev: 'a.prev',		
	pager:  '.controls',		
	pagerAnchorBuilder: function(i, el) {				
	return '<a href="#" class="bull"></a>'; 		
	} 	
});	


//////////////////////////
//////FAQS SECTION////////
//////////////////////////
$j('#faqs').click(function(){//slide down
	$j('div.faqSliderWrap').slideDown('slow').css('display','block'); 	
});

$j('div#faqSliderClose').click(function(){ //slide up
	$j('div.faqSliderWrap').slideUp('slow');
});


///////////////////////////
/////SIBLINGS FADEOUT//////
///////////////////////////
////objGD360.siblingsFadeOnHover('ul#shareFooter li', 0.6, 1.0, 300);
			// SIBLING FADER
			jQuery.fn.fadingSiblings = function() {
				return this.each(function(i) {
					jQuery(this).children().hover(function () {
						jQuery(this).siblings(":visible").stop().fadeTo(400, 0.55);
					},
					function () {
						jQuery(this).siblings(":visible").stop().fadeTo(400, 0.99);
					});
				})
			};
			jQuery(function(){
			   jQuery('#homeIntro, ul#shareFooter').fadingSiblings();
			});
////////////////////////////
/////RUNDOM BACKGROUND//////
////////////////////////////

var number = Math.floor(Math.random() * 10);

switch(number){
	case 2:
	$j('body').addClass('two');
	break;

	case 3:
	$j('body').addClass('three');
	break;

	case 4:
	$j('body').addClass('four');
	break;

	case 5:
	$j('body').addClass('five');
	break;

	case 6:
	$j('body').addClass('six');
	break;	
	
	default:
	$j('body').addClass('one');
};

////////////////////////////
////////POUP WINDOW/////////
//////////COLORBOX//////////

$j("a.artistImg").colorbox({width:'600px'});





////////////////////////////
//////EVENT LIST SLIDE//////
////////////////////////////
$j('ul.eventList li ul.eventListDetail').hide();

$j('ul.eventList li').click(function(){	
	if($j(this).children('ul.eventListDetail').is(':visible')){
		$j(this).children('ul.eventListDetail').hide('slow');
		$j('div.slideArrow').removeClass('selected');
	} 
	else if(! $j('ul.eventListDetail').is(':visible')) {
		$j(this).children('ul.eventListDetail').show('slow');
		$j('div.slideArrow').removeClass('selected');
	    $j('div.slideArrow', this).addClass('selected');		
	}
	else if($j('ul.eventListDetail').is(':visible')){
		$j('ul.eventList li ul.eventListDetail').hide();
		$j(this).children('ul.eventListDetail').show('slow');
	    $j('div.slideArrow').removeClass('selected');
		$j('div.slideArrow', this).addClass('selected');					
	}
});

////////////////////////////
////////MISC STYLES/////////
////////////////////////////
//style categorys top page
$j('ul.cats li:last').css({'padding-right':'0', 'margin-right':'0'});

//even + odd li bgcolor
$j('div#rightColumnHome .eventList li').css('border','0');
$j('div#rightColumnHome .eventList li:odd').css('background','#111010');
$j('div#rightColumnHome .eventList li:last, div#rightColumnHome .eventList li a:last').css({'background':'transparent', 'color':'#707070'});


$j('div#rightColumnHome .eventList li').hover(function(){
	    $j(this).append('<div class="more" />');
		$j('h2 a', this).css('color', '#231F20');
		$j('p.title a', this).css('color', '#00a6b1');
	},
function(){
	$j('div.more', this).remove();
	$j('h2 a', this).css('color', '#fff');
	$j('p.title a', this).css('color', '#00a6b1');
});


//change color top menu
$j('ul.menu li ul li').hover(function(){
	$j(this).parent().parent().children('a').css('color','#6b2c94');
}, function(){
	$j(this).parent().parent().children('a').css('color','#fff');
});

//add facebook and twt icons to buttons

function showHideElem(hoverOn, elem){
	$j(hoverOn).hover(function(){
	$j(elem, this).show('slow');
},
function(){
	$j(elem).hide('slow');
});
}


/////////////////////////
/////EDIT STYLE HOME/////
/////////////////////////

var url = window.location.href;
if(url.length <= 34){//home page url
$j('div#wrapper .brLine:first').css('border-bottom', '0');
$j('div.content-here').css('margin', '0 auto');
};


if(url.indexOf('/performance/') != -1){
$j('div#cat').prev('.brLine').remove();
$j('div.colorBox').css('margin-top', '87px');
}


if(url.indexOf('/news') != -1){
var br = '<div class=\"brLine\"></div>';
$j(br).insertAfter('div#titleShare');
}


if(url.indexOf('/news-item') != -1){
//var br = '<div class=\"brLine\"></div>';
var ptext = $j('p.contents').next('p').text();
$j('p.contents').next('p').hide();
$j('p.contents').append(ptext);
//$j(br).insertAfter('div#titleShare');

}

//move performances to faq section
var cont = $j('#faqPar').html();
$j('#faqPar').remove();
$j('div.titleSlidHead').eq(0).append(cont);
$j('div.titleSlidHead p.title a').css({'color':'#02A6AF', 'text-decoration':'none'});

/////////////////////////
///////ADD THIS//////////
/////////////////////////
var addThisDiv = $j('.addthis_toolbox');
$j(addThisDiv).each(function(){
    var pageTitle  = $j('.title h1').text();
    var url		   = window.location.href;
	var url        = $j(this).attr('addthis:url', url);
	var title      = $j(this).attr('addthis:title', 'Commonwealth Shakespeare Company');
});


////////////////////////////
////FORM EMAIL VALIDATE/////
////////////////////////////
$.validator.messages.required = "";
	$("#sponsorForm form").validate({
		invalidHandler: function(e, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
				var message = errors == 1
					? 'You missed 1 field.'
					: 'You missed ' + errors + ' fields.';
				alert(message);
			}
		}, 
		onkeyup: false,
		submitHandler: function() {
			$("div.error").hide();
			$(this).submit();
		},
		messages: {
			firstname: {
				required: " "
			},
			
			lastname: {
				required: " "
			},
			email: {
				required: " ",
				email: "Email address not valid"
			},
			textarea: {
				required: " "
			}			
			
		},
		debug:true
	});

//special positioning for textare label
var label = $j('#entry_16_company_desc').next('laber.error');
label.css('top','358px');

//positioning search
$j('#searchBox input[type=submit]').attr('value', '').addClass('subQry');
$j('#searchBox input[type=text]').addClass('q');
var html = $j('#searchBox').html();
var replaced = html.replace('Search:','');  
//alert(replaced)
$j('#searchBox').remove();
$j('div.formWrap').empty();
$j('div.formWrap').append(replaced);

//positioning footer sponsors
var sponrListFoot = $j('div#sponsorFooter').html();
$j('div#sponsorFooter').remove();
$j('div#logos').append(sponrListFoot);


//////////////////////////////
////////ANIMATE LABELS////////
//////////////////////////////
objGD360.inputWrap();
objGD360.animateFields();

///////////////////////////////
////////DYNAMIC SPONSORS///////
///////////////////////////////

var length = $j('ul#supList li').length;//total
var count = 18 - length; //required - length

var elemLi = $j('ul#supList');
var elemThis = '<li>&nbsp;</li>';

for(i = 0; i < count; i++){ //append to count
	elemLi.append(elemThis);
};

var lastLi = $j('ul#supList li:last');
lastLi.click(function(){window.open('/support-us/become-a-sponsor', '_self')})
lastLi.css({'background':'#530FA4', 'cursor':'pointer'});
lastLi.html('<div id="pointer">&nbsp;</div><h1 style="font-size: 23px; padding-left: 22px">Become a Sponsor</h1>')
 

/////////////////////////
//style fixes for ie 7///
/////////////////////////
var ie7 = (document.all && !window.opera && window.XMLHttpRequest) ? true : false;
if(ie7){
//$j('div#wrapper div.brLine:last').css('margin-bottom', '0px');

$j('div#rightColumnHome .eventList li').hover(function(){
	    $j(this).append('<div class="more" />');
		$j('h2 a', this).css('color', '#231F20');
		$j('p.title a', this).css('color', '#00a6b1');
	},
function(){
	$j('div.more', this).remove();
	$j('h2 a', this).css('color', '#fff');
	$j('p.title a', this).css('color', '#00a6b1');
});
}

//overwrite p with h3 home gallery
$j('h3.imageText').each(function(){
var imageText = $j('p', this).text();
$j('p', this).remove();
$j(this).append(imageText);
});
});

