$(document).ready(function() {

////////////////////////////////////////////////////////////////////////////////
// Menu

	function menuIn(){


		$('.menu li').html(function(){
			var htmlStr = $(this).closest("li").child().html();
			$(this).closest("li").child().html(htmlStr);
		});

		$(this).closest("li").addClass("menu-lightmenu");
		$(this).closest("li").removeClass("menu-norm");

	}

	function menuOut(){

		$(this).closest("li").removeClass("menu-lightmenu");
		$(this).closest("li").addClass("menu-norm");

	}

	$('.menu li').append('<div class="hovers"></div>');
	$('.hovers').width(function(){
		var plats = $(this).closest("li").width();
		return plats+30;
	});

	$('.menu li').hover(
		function() {
			if ($(this).hasClass ("menu-darkmenu")==false)
				$(this).children('div').fadeIn('1000');
		},   
		function() {  
			if ($(this).hasClass ("menu-darkmenu")==false) {
				$(this).children('div').fadeOut('1000');   
				$(this).addClass("menu-norm");
				$(this).removeClass("menu-lightmenu"); 
			}
	}).click (function(){
		$(".menu li").removeClass("menu-darkmenu");
		$(".menu li").addClass("menu-norm");
		$(this).addClass("menu-darkmenu");
		$(this).removeClass("menu-norm");
		$(this).children('div').hide(); 
	});  

////////////////////////////////////////////////////////////////////////////////
// Meklētājs
	var fadeMin=0.5
	var fadeMax=0.8

	$('#searcher').fadeTo(2000, fadeMin);
	$('#searcher').hover(
	function() {
		if(searchActive==0)
			$(this).fadeTo("fast", fadeMax);
	},
	function() {
		if(searchActive==0)
			$(this).delay(600).fadeTo("fast", fadeMin);
	}).click (function () {  
		$(this).fadeTo("fast", 1);
	});

	$('#search-text').val();

	var searchActive=0;
	var searchVal=$('#search-text').val();
	var searchDef="enter your text...";
	
	$('#search-text').val(searchDef);
	$('#search-text').blur(function(){
		$('input').removeClass("search-focus");
		$('#searcher').delay(1000).fadeTo("slow", fadeMin); 
		searchActive=0;
		searchVal=$('#search-text').val();
		if(searchVal=="")
			$('#search-text').val(searchDef)

	})
	.focus(function() {
		searchActive=1;
		$(this).addClass("search-focus");
		searchVal=$('#search-text').val();
		if(searchVal==searchDef)
			$('#search-text').val("")
	});

////////////////////////////////////////////////////////////////////////////////
// Images


	// Use this example, or...
	//$('a[@rel*=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel
	// This, or...
	//$('#gallery a').lightBox(); // Select all links in object with gallery ID
	// This, or...
	//$('a.lightbox').lightBox(); // Select all links with lightbox class
	// This, or...
	//$('a').lightBox(); // Select all links in the page
	// ... The possibility are many. Use your creative or choose one in the examples above



	$("div#preloader").hide();
 
	var skaits=1;
	preload_on = function(){
	$("html").addClass("curs-loading");
	if ($("div#preloader").is(":hidden")){
	skaits=0;
	$("div#preloader").html("Ielādē...");
	$("div#preloader").fadeIn("fast");
	}else{
	skaits=skaits+1;
	var skaits2=skaits+1;
	$("div#preloader").html("Ielādē... ("+skaits2+")");
	$("div#preloader").fadeIn("fast");
	}
	}
 
	preload_off = function(){

	if(skaits==0){
		$("html").removeClass("curs-loading");
	$("div#preloader").html("Gatavs...");
	$("div#preloader").fadeOut("fast");
	}else{
	skaits=skaits-1;
	var skaits2=skaits+1;
	if(skaits2==1){
		$("html").removeClass("curs-loading");
	$("div#preloader").html("Gatavs...");
	$("div#preloader").fadeOut("fast");
	}else{
	$("div#preloader").html("Ielādē... ("+skaits2+")");
	}
	}
	}

$("#s1c").show();
$("#s1ct").show();
$("#specials").show();
////////////////////////////////////////////////////////////////////////////////
$('pre.code').each(function(index, element){
    var sis=$(this);

    var code=$(this).html();
    var lines = code.split("\n");
    var linesLen = lines.length;

    var pre='';
    var bg='';
    var nums='';
    $.each(lines, function(key, value){
        pre+='<pre class="prereal">'+(value=='' ? '&nbsp;' : value)+"</pre>\n";
        bg+='<pre class="'+(key%2==0 ? 'pre1' : 'pre2')+"\">&nbsp;</pre>\n";
        nums+='<pre class="prenum">'+(key+1)+".</pre>\n";
    });

    $(this).wrap('<div class="pre_real" />');
    $(this).closest('.pre_real').wrap('<div class="pre_cont" />');
    $(this).closest('.pre_cont').wrap('<div class="pre_table" />');
    $(this).closest('.pre_table').wrap('<div class="pre_size pre_max" />');
    $(this).closest('.pre_cont').append(bg);
   // $(this).closest('.pre_real').append(pre);
    $(this).closest('.pre_table').append('<div class="pre_num">\n'+nums+'<\/div>');
    $(this).html('<code class="code">'+$(this).text()+'</code>');
	$(this).closest('.pre_size').prepend("<div class='togglen'><a href='#' class='toggle'>Toggle size</a></div>");
    //$(this).remove();

});

$('a.toggle').click (function(){
	$(this).parent('div.togglen').parent('div.pre_size').toggleClass('pre_max');
return false;
});
hljs.initHighlightingOnLoad();

/////////////////////////////////////////////////////////////////////

});

