jQuery.noConflict();
(function($, window, document, undefined){

$(function(){


	if ($.fn.equalHeights)
	{
		$('#content .page, #menuPage').equalHeights();
	}

	if ($.fn.slideshowFade)
	{
		$('#slideshow1').slideshowFade({
			speed: 1400,
			auto: 8000
		});
	}

	if ($.fn.boxLinks)
	{
		$('#menuPage li').boxLinks();
	}


	var title = $('.page-header h2');
	if (title.length)
	{
		if (title.has('span').length || (title.html().length > 18))
			title.addClass('lines');
	}


	if ($.browser.msie)
	{
		if ($.browser.version <= 6)
		{
			try {document.execCommand("BackgroundImageCache", false, true);} catch(err){};
			if (window['DD_belatedPNG'] !== undefined)
				DD_belatedPNG.fix('img, #side1 h3');
		}
	}

});


$.fn.equalHeights = function(add)
{
	if (this.length < 2) return;
	var m = 0;
	this.each(function(){
		m = Math.max(m, $(this).outerHeight());
	});
	return this.each(function(){
		var t = $(this), p = 0;
		$.each(['borderTopWidth', 'paddingTop', 'paddingBottom', 'borderBottomWidth'], function(i,n){
			var v = parseInt(t.css(n));
			p += (isNaN(v) ? 0 : v);
		});
		var h = m - p;
		if (add && add[this.id])
			h += add[this.id];
		if ($.browser.msie && $.browser.version <= 6) 
			t.css('height', h);
		t.css('min-height', h); 
	});
};



// slideshowFade - jQuery plugin - creates a fading slideshow
$.fn.slideshowFade = function(args)
{
	if (!this.length)
		return this;

	var opts = $.extend({
		slides: '> ul > li',	// slides selector
		buttons: true,			// show buttons
		speed: 600,				// speed of transition
		auto: 5000				// speed of auto transition
	}, args);

	this.each(function(){
		var parent = $(this), slides = parent.find(opts.slides), buttons = $(), timer = null, n = 0, s = '';

		slides.each(function(){
			this.id = parent[0].id + '-' + (++n);
			s += '<a href="#' + this.id + '">' + n + '</a>';
		});

		if (opts.buttons)
		{
			buttons = parent.append('<div class="nav">' + s + '</div>').
				find('.nav a').click(function(){
					var hash = this.hash.substr(1);
					parent.triggerHandler('slideChange', [slides.filter('#' + hash)]);
					return false;
				});
		}

		if (!slides.filter('.active').length)
		{
			slides.eq(0).addClass('active');
			buttons.eq(0).addClass('active');
		}

		function change(next)
		{
			var active = slides.filter('.active');
			if (!next || !next.jquery)
				next = active.next();
			if (!next.length)
				next = slides.eq(0);

			parent.trigger('slideChanging', [parent, slides, active, next]);

			next.addClass('next');
			active.fadeOut(opts.speed, function(){
				next.addClass('active').removeClass('next');
				active.removeClass('active').show();
				buttons.removeClass('active').filter('[href="#' + next[0].id + '"]').addClass('active');
			});

			parent.trigger('slideChanged', [parent, slides, active, next]);
		}

		function auto()
		{
			if (opts.auto)
				timer = setInterval(change, opts.speed + opts.auto);
		}

		parent.bind('slideChange', function(ev, slide){
			clearInterval(timer);
			change(slide);
			auto();
		});

		auto();
	});

	return this;
};



// boxLinks - jQuery plugin - transforms block elements into clickable items
$.fn.boxLinks = function(settings)
{
	if (!this.length) return this;

	var opts = $.extend({
		trigger: 'a',
		classHover: 'hover',
		classFocus: 'focus',
		onEnter: null,
		onLeave: null
	}, settings || {});

	this.has(opts.trigger)
		.each(function(){
			var self = $(this), t = self.css('cursor', 'pointer').find(opts.trigger);
			$.data(this, 'trigger', t);		
			$.data(t[0], 'parent', self);
		}).bind('mouseenter', function(){
			var t = $.data(this, 'trigger'), self = $(this).addClass(opts.classHover);
			opts.onEnter && opts.onEnter(self);
			window.status = t.attr('href');
		}).bind('mouseleave', function(){
			var self = $(this).removeClass(opts.classHover);
			opts.onLeave && opts.onLeave(self);
			window.status = '';
		}).bind('click', function(ev){
			var t = $.data(this, 'trigger');
			t.trigger('click');
			ev.stopPropagation();
			return false;
		});

	this.find(opts.trigger)
		.bind('focus', function(){
			var p = $.data(this, 'parent');
			p.addClass(opts.classFocus);
		}).bind('blur', function(){
			var p = $.data(this, 'parent');
			p.removeClass(opts.classFocus);
		}).click(function(ev){
			window.location = $(this).attr('href');
			ev.stopPropagation();
			return false;
		});

	this.find('a').not(opts.trigger).click(function(ev){
		ev.stopPropagation();
	});

	return this;
};



})(jQuery, window, document);
