$().ready(function(){
	/*  DEFAULT IMAGE */
	$('.products img, #pic img').error(function()
	{
		$(this).attr('src', '/medias/products/default.jpg');
	});
	
	/*  IMAGE PADDING */
	if($('.products div .img').length > 0)
	{
		$('.products div .img').each(function(i)
		{
			$('.products div .img img').load(function()
			{
				$maxHeight = 120;
				$imgHeight = $(this).height();
				
				if($imgHeight < $maxHeight)
				{
					$imgPadding = ($maxHeight - $imgHeight)/2;				
					$(this).css({paddingTop:(Math.round($imgPadding*10)/10), 
								paddingBottom:(Math.round($imgPadding*10)/10)
								});
				}
			});
		});
	};
	
	/* SLIDER */
	if($('#slider').length > 0)
	{
		$('#slider').cycle();
	}

	/* DROPDOWNLISTS */
	if($('form').length > 0)
	{
		// Build products dropdown and set css properties
		$('#category, .select').msDropDown();
		$('#menu .dd').css('width', 95);
		$('.contact .dd').css('width', 231);
		$('#category_msdd .ddTitle').css('width','auto');
		$('#category_msdd .ddChild').css('width','auto');

		// Build title dropdown and set css properties
		$('#title').msDropDown();
		$('#title_msdd, #title_msdd .ddTitle').css('width','auto');
		$('#title_msdd .ddChild').css({width: 'auto', height: 'auto'});
	}
	
	if($('#linked').length > 0)
	{
		$(".scrollable").scrollable({next: '.next', prev: '.prev'});
		
		if($('.items').children('div').length < 2)
		{
			$('.browse').addClass('disabled');
		}
	}
	
	if($('.tree').length > 0)
	{
		$('.tree li ul').hide();
		
		$('.opened', $('.tree')).parent('ul').show();
		$('.opened', $('.tree')).children('ul').show();
		
		
		$('li', $('.tree')).each(function(i)
		{
			if($(this).children('ul').length > 0)
			{
				$(this).prepend('<span class="arrow"></span>');
				$(this).addClass('parent');
			}
			else
			{
				$(this).css('padding-left', '10px');
			}
		});
		
		/*
		$('.parent', $('.tree')).children('a').click(function(e)
		{
			e.preventDefault();
			
			$(this).parent().parent().children('li').each(function(i)
			{
				if($(this).children('ul').is(':visible'))
				{
					$(this).children('ul').slideUp();
				}
			});

			if(!$(this).nextAll('ul').is(':visible'))
			{
				$(this).nextAll('ul').slideDown();
				$(this).toggleClass('opened');
			}
			else
			{
				$(this).nextAll('ul').slideUp();
				$(this).toggleClass('opened');
			}
		});
		*/
	}
	
	if($('ul.tabs').length > 0)
	{
		$("ul.tabs").tabs("div.panes > div");
	}
	
	/* DATE PICKER */
	
	if($('.date').length > 0)
	{
		$(".date").datepicker({
			inline: true
		});
	}
})

