/*
File Name: functions.js
Author: Stayko Dimitrov
Version: 1.0
*/

function create_dropdown(src, sbm, width, top, left) {
	var source = $('#'+src+'');
	var options = $('option', source);
	var selected = $('#'+src+' :selected');
	var image = '';
	var img = '';
	width = parseFloat(width);
	source.hide();

	$('#'+src+'').after('<dl id="target_'+src+'" class="dropdown" style="margin: '+top+'px 0 0 '+left+'px"></dl>');
	image = (selected.attr('title') != '') ? '<img class="flag" src="'+selected.attr('title')+'" alt="'+selected.text()+'" />' : '';
	$('#target_'+src+'').append('<dt><a href="javascript:void(0)">'+image+selected.text()+'<span class="value">'+selected.val()+'</span></a></dt>');
	$('#target_'+src+'').append('<dd><ul></ul></dd>');
	$('#target_'+src+' dt a').css({'width' : ''+width+'px'});
	$('#target_'+src+' dd ul').css({'width' : ''+(width+12)+'px'});
	$('#target_'+src+' dd ul li a').css({'width' : ''+width+'px'});
	options.each(function(){
		img = ($(this).attr('title') != '') ? '<img class="flag" src="'+$(this).attr('title')+'" alt="'+$(this).text()+'" />' : '';
		$('#target_'+src+' dd ul').append('<li><a href="javascript:void(0)">'+img+$(this).text()+'<span class="value">'+	$(this).val()+'</span></a></li>');
	});
	$('#target_'+src+' dt a').click(function() {
		$('#target_'+src+' dd ul').toggle(200);
	});
	$(document).bind('click', function(e) {
		var $clicked = $(e.target);
		if (!$clicked.parents().hasClass('dropdown')) $('#target_'+src+' dd ul').hide();
	});
	$('#target_'+src+' dd ul li a').click(function() {
		var text = $(this).html();
		var value = $(this).find('span.value').html();
		$('#target_'+src+' dt a').html(text);
		$('#target_'+src+' dd ul').hide();
		source.val(value);
		if (sbm) {
			source.parent().parent('form').trigger('submit');
		}
		return false;
	});
}

function menu(url) {
	$('#menu > li').hover(function(){
		$('#menu > li > ul').each(function() {
			$(this).css({'display': 'none'});
		});
		$('#menu > li > a').each(function() {
			$(this).css({'background': 'none'});
		});
		$('ul', this).css({'display': 'block'});
		$(this).css({'background': 'url('+url+'/images/rect.png) no-repeat 11px 34px'});
		if ($('ul', this).length > 0) {
			$('<div class="trg"></div>').prependTo($(this));
		}
	}, function(){
		$('ul', this).css({'display': 'none'});
		$(this).css({'background': 'none'});
		$('#menu > li.current_page_item a').css({'background': 'url('+url+'/images/rect.png) no-repeat 11px 34px'});
		$('#menu > li.current_page_ancestor a').css({'background': 'url('+url+'/images/rect.png) no-repeat 11px 34px'});
		$('.trg').remove();
	});
}

function show(did) {
	$('.sh').hide(0);
	$('#block_'+did+'').show(0);
}

function loca(loc) {
	$('.ad').hide(0);
	$('#'+loc+'').fadeIn(400);
}

function exp_col() {
	$(".exp_col").click(function(){
		$(this).next(".exp_col_cont").css("height", "auto");
		$(this).next(".exp_col_cont").slideToggle(300);
		$(this).next(".exp_col_cont").css("visibility", "visible");
		return false;
	});
}
