jQuery(document).ready(function(){
// ---- START ----
var $j = jQuery;
// Accordion 

	// build the accordion
	// and hide all the sliders except the first
	$j('.accordion .BoxHeadline ').click(function() {
		$j(this).find('span').toggleClass('ui-icon-triangle-1-e  ui-icon-triangle-1-s');
		$j(this).toggleClass('ui-state-hover  ui-state-active');
		var options = {}; 
		$j(this).next().toggle('blind', options, 500 );
		return false;
	}).not(':first').next().hide();

	// set the first accordion to active state
	$j('.accordion .BoxHeadline:first ').find('span').toggleClass('ui-icon-triangle-1-e  ui-icon-triangle-1-s');
	$j('.accordion .BoxHeadline:first ').toggleClass('ui-state-hover  ui-state-active');

	// toggle mouseover state
	$j(".accordion .BoxHeadline, .fakeaccordion .BoxHeadline").hover(
	  function () {
		$j(this).addClass("ui-state-hover");
		return false;
	  },
	  function () {
		$j(this).removeClass("ui-state-hover");
		return false;
	  }
	);


// PagerAnchorBuilder fns
function dotit(i, el) {
      var img = $j(el).children().eq(0).attr("src");
      return '<a href="#">&bull;</a>';
    }
    
function nameit(i, el) {
      var img = $j(el).children().eq(0).attr("src");
      var imgtitle = $(el).eq(0).attr("title");
      return '<a href="#" class="namepager">' + imgtitle + '</a>';
    }
    
// build gallery slideshows
// --- 

$(window).load(function () {
	if ($j('#ItemGallery-start').length > 0) { // implies *not* zero // Homepage
			$j('#ItemGallery-start').after('<div id="pagerstart" class="pager" style="display:none">').cycle({ 
				fx:     'scrollLeft', 
				pause:  1,
				pager:  '#pagerstart',
				containerResize: 0,
				fit: 1,
				fastOnEvent: 300,
				pagerAnchorBuilder: nameit
			});
	} else {
		$j('.ItemGallerySel').each(function(index) { // Gallerypages
			var $this = $j(this);
			$this.after('<div id="pager-' + index + '" class="pager" style="display:none">').cycle({
				fx:     'scrollLeft', 
				pause:  1,
				pager:  '#pager-' + index,
				containerResize: 0,
				fit: 0,
				fastOnEvent: 300,
				pagerAnchorBuilder: dotit
			});
		});
	}
});


// show pager    
$j("div.ImageContainer").mouseover(function () {
	$j(this).find(".pager").show();
    }).mouseout(function(){
    $j(this).find(".pager").hide();
});    




// ---- EOF ----
});

