// JavaScript Document

$(document).ready(function(){
	
	/* --- CURRENT DATE - BEGIN --- */
	var today = new Date();
	var fullDate = today.getCalendarMonth() + " " + today.getDate() + ", " + today.getFullYear();
	$('#date .content').text(fullDate);
	/* --- CURRENT DATE - END --- */
	
	/* --- IE 6 CSS MENU FIX - BEGIN --- */
	$('#primary-nav li.menuparent').hover(
		function() {
			$(this).addClass('over');
		},function(){
			$(this).removeClass('over');
		}
	);
	/* --- IE 6 CSS MENU FIX - END --- */
	
	/* --- REDIRECT - BEGIN --- */
	if ($('a.redirectUser').length != 0) {
		document.location.href = $('a.redirectUser:first').attr('href');
	}
	/* --- REDIRECT - END --- */
	
	/* --- SUB-SUB-NAVIGATION HIGHLIGHTING - BEGIN --- */
	if (typeof(js_subsubsection)!="undefined") {
		$('#side-nav ul li').eq(js_subsubsection-1).addClass('selected');
	}
	/* --- SUB-SUB-NAVIGATION HIGHLIGHTING - END --- */
	
	/* --- COLLAPSEABLE BOXES - BEGIN --- */
	var boxsets_array = new Array();
	var page = document.location.href;
	page = page.substring(page.length - 16,page.length-4).replace("/","").replace(".","");
	$('.dynamic-boxes').each(function(z){
		$('.dynamic-box',this).each(function(i){
			boxsets_array[z] = i;
			if (i==0) { // open first box always
				$(this).addClass('open');	
			}
			$(this).addClass('boxset-'+z);
		});
	});
	for (z=0;z<boxsets_array.length;z++) {
		for (i=0;i<=boxsets_array[z];i++) {
			if ($.cookie(page+'-boxset-'+z+'-box-'+i)=='open') {
				$('.dynamic-box.boxset-'+z+'.box-'+i).addClass('open');
			}
		}
	}
	$('.dynamic-box:not(.open) > .content').hide();
	$('.title-row',$('.content:visible').parents('.dynamic-box')).addClass('open');
	$('.dynamic-boxes:not(.stayopen) .dynamic-box .title-row').click(function(){
		if ($('.content').is(':animated')) {return;} // Prevent over clicking
		$('.content:visible',$(this).parents('.dynamic-box').siblings('.dynamic-box'))
			.animate({
				height: 'hide'
			},'fast');
		$('.title-row.open',$(this).parents('.dynamic-box').siblings('.dynamic-box')).removeClass('open');
		$(this).addClass('open');
		$('.content',$(this).parents('.dynamic-box'))
			.animate({
				height: 'show'
			},'fast');
	});
	$('.dynamic-boxes.stayopen .dynamic-box .title-row').click(function(){
		if ($('.content').is(':animated')) {return;} // Prevent over clicking
		var thisclass = $(this).parents('.dynamic-box').attr('class');
		var boxsetNumber = thisclass.substring(thisclass.indexOf('boxset-'),thisclass.indexOf('boxset-')+8);
		var boxNumber = thisclass.substring(thisclass.lastIndexOf('box-'),thisclass.lastIndexOf('box-')+5);
		if ($('.content',$(this).parents('.dynamic-box')).is(':visible')) {
			$('.content:visible',$(this).parents('.dynamic-box'))
				.animate({
					height: 'hide'
				},'fast');
			$.cookie(page+"-"+boxsetNumber+'-'+boxNumber,null);
			$(this).removeClass('open');
		} else {
			$('.content',$(this).parents('.dynamic-box'))
				.animate({
					height: 'show'
				},'fast');
			$.cookie(page+"-"+boxsetNumber+'-'+boxNumber,'open');
			$(this).addClass('open');
		}
	});
	/* --- COLLAPSEABLE BOXES - END --- */
	
	/* --- SIDE GALLERY ZOOMING - BEGIN --- */
	if ($('.gallery-artwork-image a img').length != 0) {
		$('.columnInfo .gallery').before('<div class="enlargeText">Click images to enlarge</div>');
		if ($('.event.gallery').length != 0) {
			$('.gallery-artwork-0').prepend('<div class="enlargeText">Click images to enlarge</div>');
		}
	}
	$('.gallery-artwork-image a').each(function(i){
		var thisTitle = $('.gallery-artwork-info',$(this).parents('.gallery-artwork')).text();
		$(this).attr('dtitle',thisTitle);
	});
	$('.gallery-artwork-image a').lightBox();
	/* --- SIDE GALLERY ZOOMING - END --- */
	
	/* --- THUMB GALLERY ZOOMING - BEGIN --- */
	$('.thumbnail-image a').each(function(i){
		var thisTitle = $('.thumbnail-description',$(this).parents('.thumbnail')).text();
		$(this).attr('dtitle',thisTitle);
	});
	$('.thumbnail-image a').lightBox();
	/* --- THUMB GALLERY ZOOMING - END --- */
	
	$('.noRightClick').each(function(i){ // A few artists have requested we disable right clicking on pages with their images
		$(document).bind("contextmenu",function(e){
			return false;
		});
	});
	
	$('a.popupwindow').click(function(event){
		event.preventDefault();
		newwindow=window.open($(this).attr('href'),'Privacy','height=420,width=600,scrollbars=yes,resizable=yes');
		if (window.focus) {newwindow.focus()}
	});
});
