$(document).ready(function(){
	
	$("body").each(function(){
		lng = this.className;
	});
	
	selectReplace();
	pgJobs();
	corners();
	lightboxes();
});

// *****************************************************************************
// replaces select with div, must be style via CSS
this.selectReplace = function() {
	
	$(".selectReplace").each(function(){
			
		oid = this.id;
		oti = this.title;
 		opts = "";
		$(this).children("option").each(function(){
			if(this.value != "") {
				opts += '<li class="rep_item"><a href="' + this.value + '" title="' + ($(this).text()) + '">' + ($(this).text()) + '</a></li>';
			}
		});
		$(this).replaceWith('<div id="rep_' + oid + '" class="rep_holder">'
			+ '<div class="rep_select"><a class="rep_empty" href="javascript:void(0);" title="' + oti + '"><span>' + oti + '</span></a>'
			+ '<div class="rep_list"><ul>' + opts + '</ul></div></div></div>');
		$("#rep_" + oid + " .rep_empty").hover(function() {
			$(this).parents(".rep_holder").addClass("rep_active");
			$(this).parents(".rep_holder").hover(function(){
				$(this).children(".rep_list").hover(
					function() {
						$(this).parents(".rep_holder").addClass("rep_active");
					},
					function() {
						$(this).parents(".rep_holder").removeClass("rep_active");
					}
				);
			}, function(){
				$(this).removeClass("rep_active");
			});
			
		},function(){});
		
	});

}

// *****************************************************************************
// contracts filter lists
this.pgJobs = function() {
	
	$("#filter dd").hide();
	$("#filter dt").click(function(){
		$(this).toggleClass("active");
		$(this).next().toggle().toggleClass("active");
	});

}

this.corners = function() {
	radius = "5px";
	$(".alert, .grayblock").corner(radius);

}

// *****************************************************************************
// lightboxes
this.lightboxes = function() {
	
	// lb musi byt <a rel="lightbox-galerie"..
	
	str = '';
	$('a[rel^=lightbox]').each(function(){
		uq = $(this).attr("rel").substr(9);
		if(str.indexOf("<" + uq + ">") == -1) {
			str += "<" + uq + ">";
		}
	});
	gals = str.substr(1, str.length-2).split("><");
	for(i = 0; i < gals.length; i++) {
		$("a[rel=lightbox-" + gals[i] + "]").lightBox({
			containerResizeSpeed: 400,
			txtImage: "Obrázek / Image :",
			txtOf: "/",
			imageLoading: "/img/lb-loading.gif",
			imageBtnClose: "/img/lb-btn-close.gif",
			imageBtnPrev: "/img/lb-btn-prev.gif",
			imageBtnNext: "/img/lb-btn-next.gif"
		});
	}

}

