$(document).ready(function(){
	$.fx.speeds._default = 500;
	
	//flash messages
	var klasa = $('#flashMessage').attr('class');
	$('#flashMessage').dialog({
		hide: 'puff',
		draggable: false,
		modal: true,
		resizable: false,
		dialogClass: klasa
	});
	
	var time = $('#flashMessage').attr('rel') !== undefined ? $('#flashMessage').attr('rel') : 1500;	
	setTimeout(function(){$('#flashMessage').dialog("close") }, time);
	
	//banners
	$('#banner-layer').dialog({
		hide: 'puff',
		draggable: false,
		modal: true,
		resizable: false,
		width: 600,
		height: 400
	});
	
	//menu
	$('#menu a').first().css({'border-right' : 'none', 'padding-right' : '0'});
	
	//dropdown
	$(".dropdown dt a").click(function(e) {
        $(this).parent().parent().find("dd ul").toggle();
		e.preventDefault();
	});
	
	$(".dropdown dd ul li a").click(function(e) {
		var text = $(this).html();
		var value = $(this).find('.value').html();
		var mainParent = $(this).parent().parent().parent().parent()
		
		mainParent.find("dt a span").html(text);
		$(".dropdown dd ul").hide();
		
		var id = mainParent.attr('id').replace('To', '');
		$('#'+id).val(value);
		
		e.preventDefault();
	});
	
	//left menu
	$('#leftMenu a.category').click(function(e){
		$(this).parent().find('ul').slideToggle();
		
		e.preventDefault();
	});
	
	$('#leftMenu li.active').parent().show();
	
	$('.form-input').click(function(){
		$(this).val('');
	});
});

$(document).bind('click', function(e) {
    var $clicked = $(e.target);
    if (! $clicked.parents().hasClass("dropdown")){
        $(".dropdown dd ul").hide();
	}
});
