jQuery.noConflict();

(function($, window, document, undefined){


$(function(){

	
	if ($.fn.jCarouselLite)
	{
		var slideshow1 = $('#slideshow1');
		if (slideshow1.length)
		{
			var btns = '', ctrl = [];
			slideshow1.find('.slider li').each(function(i) {
				this.className = 'slide-' + i;
				btns += '<a href="#" class="btn-' + i + ((i == 0) ? ' active' : '') + '"></a>';
				ctrl[i] = '.btn-'+ i;
			});
			
			slideshow1.append('<p class="nav">'+ btns +'</p>');
			slideshow1.find('.slider').jCarouselLite({
				visible: 1,
				scroll: 1,
				speed: 600,
				auto: 5000,
				circular: true,
				btnGo: ctrl,
				afterEnd: function(li){
					var id = li[0].className.split('-')[1];
					slideshow1.find('.nav a').removeClass('active').filter('.btn-' + id).addClass('active');
				}
			});
		}
	}
	
	if ($.fn.tabs)
	{
		$('.tab-area').tabs();
	}
	
	if ($.fn.selects)
	{
		$('.select1').selects();
	}

	if ($.fn.jqTransform)
	{
		$('form .jqtransform').jqTransform();
	}


	if ($.fn.prettyPhoto)
	{
		$("a[rel^='prettyPhoto']").prettyPhoto({
			opacity: 0.50,
			show_title: false,
			allow_resize: true,
			default_width: 447,
			default_height: 230,
			overlay_gallery: false,
			theme: 'cc'
		});
	}


	if (window['DD_belatedPNG'] !== undefined)
		DD_belatedPNG.fix('img, #topLinks a, #list1 a span, #menu2 li a, #page, .slideshow .nav a, .slideshow .slider li a.more, #page #menu li li a');
});


$.fn.tabs = function(args)
{
	if (!this.length)
		return this;

	var options = $.extend({
		triggers: '.tabs a',
		tabs: '.tab'
	}, args);

	this.each(function(){
		var parent = $(this), triggers = parent.find(options.triggers), tabs = parent.find(options.tabs);

		triggers.click(function(){
			var id = this.hash.substr(1), tab = $('#' + id);
			if (!tab.length)
				return false;

			parent.trigger('tabsChange', [triggers, tabs, tab]);

			tabs.hide();
			tab.show();

			triggers.removeClass('active');
			$(this).addClass('active');

			return false;
		});
		tabs.hide();

		var active = (triggers.filter('.active').length) ? triggers.filter('.active') : triggers.eq(0);
		active.click();
	});
};

$.selects = {
	zIndex: 99,
	timer: null,
	cancelTimer: function()
	{
		if ($.selects.timer)
		{
			clearTimeout($.selects.timer);
			$.selects.timer = null;
		}
	},
	setTimer: function(parent, active)
	{
		$.selects.timer = setTimeout(function(){
			parent.removeClass(active);
		}, 150);
	},
	height: function(ul, max)
	{
		setTimeout(function(){
			if (ul.height() > max)
				ul.addClass('scroll').css('height', max);
		}, 10);
	}
};

$.fn.selects = function(args){
	if (!this.length)
		return this;

	var opts = $.extend({
			className: '',
			markup: '<a class="trigger" href="#"><span></span></a><div class="popup"><ul></ul></div>',
			skipFirst: false,
			maxHeight: 0
		}, args);

	return this.each(function(){
		var sel = $(this), 
			type = opts.className.length ? opts.className : this.className.split(' ')[0],
			actives = ['custom-select-active', type + '-active'],
			active = actives.join(' ');

		sel.hide().wrap('<div class="custom-select select-' + sel[0].name + ' ' + type + ' cf"></div>');

		var parent = sel.parent().css({ zIndex: $.selects.zIndex-- }).append(opts.markup),
			trigger = parent.find('.trigger'), popup = parent.find('.popup'), ul = parent.find('ul'),
			i = opts.skipFirst ? 1 : 0, s = '';

		for (; i < this.options.length; i++)
			s += '<li><a href="#" class="index-' + i + '">' + this.options[i].text + '</a></li>';
		ul.append(s);

		if (opts.maxHeight)
			$.selects.height(ul, opts.maxHeight);
		
		trigger
			.find('span').html(this.options[this.selectedIndex].text).end()
			.click(function(){
				$('.' + actives[0]).removeClass(active);
				var d = sel.triggerHandler('selectOpening', [sel, parent]);
				popup.css('width', trigger.outerWidth() - d);
				parent.toggleClass(active);
				return false;
			});

		popup.css('width', trigger.outerWidth());

		$(trigger).add(popup).hover(function(){
			if (parent.hasClass(actives[0]))
				$.selects.cancelTimer();
		}, function(){
			$.selects.setTimer(parent, active);
		});

		ul.find('a').click(function(){
			var i = parseInt(this.className.split('-')[1]);
			sel[0].selectedIndex = i;
			trigger.find('span').html(this.innerHTML).end().focus();
			parent.removeClass(active);
			sel.triggerHandler('selectClosed', [sel, parent, i]);
			return false;
		});

	});
};


})(jQuery, window, document);

