$(document).ready(function() {
    
    //on click in search input make it gray
    $("#s").focus(function() {
        $(this).val("").css("color","gray");
    });

    $("#header").click(function() {
        top.location.href = "http://briiC.lv/";
    });

    $("#rssTrainHolder").hover(
    function(){ 
           $(".rss-choices a").fadeIn(500);
    }
    ,
    function() {
           $(".rss-choices a").fadeOut(500);
    });

  //Auto-style on thinkdraw from http://briiC.lv/uzzime/
   $(".entrybody img[src*='uzzime/thinkdraws/']").parents("p").each(function() {
		var imgAttrAlt = $(this).find("img[src*='uzzime/thinkdraws/']").attr("alt");

        if(imgAttrAlt.match('::') == null) {
                  $(this).wrapInner('<a href="http://briiC.lv/uzzime/" title="Uzzīmē!" class="uzzime"></a>')
                                        .append('<center><code class="uzzime">no "<a href="http://briiC.lv/uzzime/" title="Uzzīmē!">uzzīmē!</a>" krājumiem.</code></center>');
        }
        else {
                  var tmp = imgAttrAlt.split('::');
                  var ideof = tmp[0];
                  
                  $(this).wrapInner('<a href="http://briiC.lv/uzzime/" title="Uzzīmē!"  class="uzzime"></a>')
                                        .append('<center><code class="uzzime">no "<a href="http://briiC.lv/uzzime/" title="Uzzīmē!">uzzīmē!</a>" krājumiem. Ieteica: <b>'+ideof+'</b></code></center>');
        }    
    });

    //Add "#noheader" to some link ends
    $(".arrow > a > img[alt=lpp]").parents('a').each(function(){
        var ahref = $(this).attr('href') + "#noheader";
        $(this).attr("href",ahref);
    });
    //Add "#uz-1" to some 'jumper' links if user come from 'jumper' navigation
    $(".arrow > a > img[alt=<lpp]").parents('a').each(function(){
        var ahref = $(this).attr('href') + "#uz-5";
        $(this).attr("href",ahref);
    });
    $(".arrow > a > img[alt=>lpp]").parents('a').each(function(){
        var ahref = $(this).attr('href') + "#uz-1";
        $(this).attr("href",ahref);
    });

    //styling google reader widget
    //better get from google no styled widget and put in box <div></div> with your own styling
    //this is temp
    $(".f > a").html("Lasīt vairāk &#187;");
    $(".reader-publisher-module > ul").css("background","url(http://briic.lv/uzzime/uzzime-back.gif) bottom right no-repeat white");

    //valodnieks
    $(".valod_lang > b > img").click(function() {
        var vid = $(this).parents('b').attr('class');
        var vformid = '#valodnieks_add_new_language_'+vid;
        var lcode = $(this).attr('alt');
        $(vformid+' > .lcode').attr('value',lcode);
        $(vformid+' > textarea').css("background-image","url("+$(this).attr('src')+")");
        $(vformid).slideDown("fast");
    });

    $('.valod_lang').tooltip({ 
        //track: true, 
        delay: 0, 
        bodyHandler: function() { 
            return $(this).find('span').html(); 
        }, 
        track: true, 
        showURL: false, 
        opacity: 1, 
        showBody: " - ", 
        left:-440,
        top:-15,
        extraClass: "valod_tooltip"
    });
    

//end of ready function in jquery
});




//Third part
function DraugiemSay( title, url, titlePrefix ){
 window.open(
  'http://www.draugiem.lv/say/ext/add.php?title=' + encodeURIComponent( title ) +
  '&link=' + encodeURIComponent( url ) +
  ( titlePrefix ? '&titlePrefix=' + encodeURIComponent( titlePrefix ) : '' ),
  '',
  'location=1,status=1,scrollbars=0,resizable=0,width=530,height=400'
 );
 return false;
}  