
/***************************/
/******** Dropdowns ********/
/***************************/

$(document).ready(function(){  
	
	if(location.href.match(/e-digest\/post/))
	{
		$('h1.page').after('<div id="post"></div>');
		$('#post').load('/legacy/contacts/edigest/edigest-post.php form');
	}
	
	
	if($('.boxItem').length > 0)
	{
		$('#grid').masonry({
			columnWidth: 20,
			itemSelector: '.boxItem'
		});	
	}
	
	if($(".slidetabs a").length > 0)
	{
		$(".slidetabs").tabs(".images > div", 
		{
			effect: 'fade',
			fadeOutSpeed: "slow",
			autoplay: true,
			rotate: true
		}).slideshow({
			clickable: false
		});
	}

	$("#linkscategories ul").hide();
//	$("#linkscategories").tabs("#linkscategories ul", {tabs: 'h3', effect: 'slide', initialIndex: null});
	$('h3.category').click(function(){
		$(this).next().toggle('fast');
	});

	if($.browser.opera)
	{
		$('input.bookButton').val('');
	}
	
/*
	function show(target)
	{
		document.getElementById(target).style.display = 'block';
	}
	
	function hide(target)
	{
		document.getElementById(target).style.display = 'none';
	}*/


  //$("ul.dropdown").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)  
 
	/**
	 * NAVIGATION (Stay coloured)
	 */
	// Toynbee Studios
 	$('li.naviorange').mouseenter(function(){
		$('a.naviorange').css('color', '#ff6600');
	});
	
	$('li.naviorange').mouseleave(function(){
		if(!$('a.naviorange').hasClass('naviorangeactive'))
		{
			$('a.naviorange').css('color', '#000');
		}
	});
	
	// Artists & Projects
	$('li.navired').mouseenter(function(){
		$('a.navired').css('color', '#ce2337');
	});
	
	$('li.navired').mouseleave(function(){
		if(!$('a.navired').hasClass('naviredactive'))
		{
			$('a.navired').css('color', '#000');
		}
	});
	
	// Opportunities
	$('li.naviblue').mouseenter(function(){
		$('a.naviblue').css('color', '#037ebe');
	});
	
	$('li.naviblue').mouseleave(function(){
		if(!$('a.naviblue').hasClass('naviblueactive'))
		{
			$('a.naviblue').css('color', '#000');
		}
	});
	
	// Artsonline
	$('li.navigreen').mouseenter(function(){
		$('a.navigreen').css('color', '#209b56');
	});
	
	$('li.navigreen').mouseleave(function(){
		if(!$('a.navigreen').hasClass('navigreenactive'))
		{
			$('a.navigreen').css('color', '#000');
		}
	});
	
// Drop Down navigation
	$("ul.navi li").mouseenter(function() { //When trigger is clicked...  
		$(this).find("ul.dropdown").show(); //Drop down the subnav on click     
	}); 

	$("ul.navi li").mouseleave(function() { //When trigger is clicked...  
		$(this).find("ul.dropdown").hide(); //Drop down the subnav on click  
	});


/***************************/
/******** Captions *********/
/***************************/

	//To switch directions up/down and left/right just place a "-" in front of the top/left attribute
	//Vertical Sliding
	$('.box').hover(function(){
		$(".caption", this).stop().animate({top:'0px'},{queue:false,duration:300});
	}, function() {
		$(".caption", this).stop().animate({top:'-400px'},{queue:false,duration:300});
	});
	
	$('.boxPlain').hover(function(){
		$(".caption", this).stop().animate({top:'0px'},{queue:false,duration:300});
	}, function() {
		$(".caption", this).stop().animate({top:'-400px'},{queue:false,duration:300});
	});

	$('.boxPlain').hover(function(){
		$(".photocaption", this).stop().animate({top:'0px'},{queue:false,duration:300});
	}, function() {
		$(".photocaption", this).stop().animate({top:'-100px'},{queue:false,duration:300});
	});

/***************************/
/****** Result Hover *******/
/***************************/

	$('.result').hover(function(){
		var color = $(this).attr('class').replace('result result', '');
		$(this).addClass('resultHover'+color);
	}, function() {
		var color = $(this).attr('class').replace('result result', '');
		$(this).removeClass('resultHover'+color);
	});


/***************************/
/****** Shop Tooltip *******/
/***************************/



	$('.resultShop').hover(function(){
		if($(".resultShopInfo", this).css("display") == "none")
		{
			$(".resultShopInfo", this).css("display", "block");
		}
	}, function() {
		if($(".resultShopInfo", this).css("display") == "block")
		{
			$(".resultShopInfo", this).css("display", "none");
		}
	});
	
	/*****************************/
	/******* Grid/List Display ***/
	/*****************************/

	$("a.switchToList").click(function(){
        $(this).addClass("swap");
        $("div.results").fadeOut("fast", function() {
            $('.result', this).addClass("resultList");
            $('.result', this).removeClass("result");
			$(this).fadeIn("fast");
        });
    });


    $("a.switchToGrid").click(function(){
        $(this).addClass("swap");
        $("div.results").fadeOut("fast", function() {
            $('.resultList', this).addClass("result");
            $('.resultList', this).removeClass("resultList");
			$(this).fadeIn("fast");
        });
    });

    $("a.switchShopToList").click(function(){
        $("div.results").fadeOut("fast", function() {
            $('.resultShopBuy', this).addClass("resultListShopBuy");
            $('.resultShopBuy', this).removeClass("resultShopBuy");
            $('.resultShopInfo', this).addClass("resultListShopInfo");
            $('.resultShopInfo', this).removeClass("resultShopInfo");
            $('.resultShopThumb', this).addClass("resultListShopThumb");
            $('.resultShopThumb', this).removeClass("resultShopThumb");
            $('.resultShop', this).addClass("resultListShop");
            $('.resultListShop', this).removeClass("resultShop");
			$(this).fadeIn("fast");
        });
    });


    $("a.switchShopToGrid").click(function(){
        $("div.results").fadeOut("fast", function() {
            $('.resultListShopBuy', this).addClass("resultShopBuy");
            $('.resultListShopBuy', this).removeClass("resultListShopBuy");
            $('.resultListShopInfo', this).addClass("resultShopInfo");
            $('.resultListShopInfo', this).removeClass("resultListShopInfo");
            $('.resultListShopThumb', this).addClass("resultShopThumb");
            $('.resultListShopThumb', this).removeClass("resultListShopThumb");
            $('.resultListShop', this).addClass("resultShop");
            $('.resultListShop', this).removeClass("resultListShop");
			$(this).fadeIn("fast");
        });
    });

    $("a.switchCalendarToList").click(function(){
        $("div.results").fadeOut("fast", function() {
            $('.calendarItemOngoing', this).addClass("calendarItemListOngoing");
            $('.calendarItemOngoing', this).removeClass("calendarItemOngoing");
            $('.calendarItemText', this).addClass("calendarItemListText");
            $('.calendarItemText', this).removeClass("calendarItemText");
            $('.calendarItemThumb', this).addClass("calendarItemListThumb");
            $('.calendarItemThumb', this).removeClass("calendarItemThumb");
            $('.calendarItemLocation', this).addClass("calendarItemListLocation");
            $('.calendarItemLocation', this).removeClass("calendarItemLocation");
            $('.calendarItem', this).addClass("calendarItemList");
            $('.calendarItem', this).removeClass("calendarItem");
			$(this).fadeIn("fast");
        });
    });

    $("a.switchCalendarToGrid").click(function(){
        $("div.results").fadeOut("fast", function() {
            $('.calendarItemListOngoing', this).addClass("calendarItemOngoing");
            $('.calendarItemListOngoing', this).removeClass("calendarItemListOngoing");
            $('.calendarItemListText', this).addClass("calendarItemText");
            $('.calendarItemListText', this).removeClass("calendarItemListText");
            $('.calendarItemListThumb', this).addClass("calendarItemThumb");
            $('.calendarItemListThumb', this).removeClass("calendarItemListThumb");
            $('.calendarItemListLocation', this).addClass("calendarItemLocation");
            $('.calendarItemListLocation', this).removeClass("calendarItemListLocation");
            $('.calendarItemList', this).addClass("calendarItem");
            $('.calendarItemList', this).removeClass("calendarItemList");
			$(this).fadeIn("fast");
        });
    });

	/*****************************/
	/******* ARTIST Slideshow  ***/
	/*****************************/
	
	if($('.imagesArtist').length > 0)
	{
		$(".slidetabsSmall").tabs(".imagesArtist > div", 
		{
			effect: 'fade',
			fadeOutSpeed: "slow",
			autoplay: true,
			rotate: true
			
		}).slideshow({
			clickable: false
		});
	}
		
	/*****************************/
	/******* FILTERS           ***/
	/*****************************/
		
	if($('#bursaryScheme').is('select'))
	{
		$('#bursaryScheme').change(function(){
			if($(this).val() != 0)
			{
				location.href = '/artists/supported/scheme/' + $(this).val();		
			}
		});
	}

	$('select.filters').change(function(){
		if($(this).val() != 0)
		{
			location.href = $(this).val();
		}
	});
	
	$('div.captionLabel').click(function(){
		location.href = $(this).find('a').attr('href');
	});
	
	/*****************************/
	/******* IMG GALLERY       ***/
	/*****************************/
	
	$("a[rel=image_gallery]").fancybox({
		'transitionIn' : 'none',
		'transitionOut' : 'none',
		'titlePosition' : 'inside',
		'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
			return '<span id="fancybox-title-over">' + (currentIndex + 1) + ' / ' + currentArray.length + ' ' + title + '</span>';
		}
	});

	
	/*****************************/
	/******* ACCORDION'S *********/
	/*****************************/
	
		$('a.switch').next('dl').hide();
		$('a.switch').click(function(){
			$(this).next('dl').toggle('fast');
			return false;
		});
		
		$('a.archivePosts').next('ul').hide();
		$('a.archivePosts').click(function(){
			$(this).next('ul').toggle('fast');
			return false;
		});

});

