$(document).ready(function() {
    //if ($('body').css('background-color') == "#f8f8f8") $('#extra, .transparent, #main').css('opacity', 0.9);
    //fix IE pdf bug on cv page
    //if ($('body').css('background-color') == "#f8f8f8") $('#extra, .transparent, #main:not(:has(div.cv))').css('opacity', 0.9);

    var b = navigator.userAgent.toLowerCase();
    jQuery.browser = {
        safari: /webkit/.test(b),
        opera: /opera/.test(b),
        msie: /msie/.test(b) && !/opera/.test(b),
        msie6: /msie 6.0/.test(b) && !/opera/.test(b),
        mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b)
    };

    $('#topNav ul, #header .actions', this).css('opacity', 0.9);
    $('.actions').hide();
    $('.actions li').hide();
    $('#extra').append($('.toExtra'));
 
    //$('#header .siteMap').append($('.language'));

    if ($.browser.msie6) {
        $('#extra, #main, .transparent, .cols2 #main .col1, .cols2 #main .col2').css('background-image','url(../Image/transbg-ie6.png)');
        $(document).pngFix();
    }
    $('img[src$=.png]').css('visibility', 'visible');

    $('.icons>ul:first li').each(function() { $('.actions li.' + ($(this).attr("class"))).show(); });

    /* cols */
    //$('.content:empty').hide();
    //$('.hidden').hide();
    //$('.col1 a[HREF*=#]').click(function() {
    //    $('.col2').fadeIn(2000);
    //    $('#main').toggleClass("full");
    //});

    $('.icons>ul.actions').css('display', 'none');
    $('.icons>ul:not(.actions)').mouseenter(function() { $('ul.actions').stop().css('display', 'block').fadeTo('fast', 0.9); });
    $('.icons>ul.actions').mouseleave(function() { $('ul.actions').fadeTo('slow', 0.0, hideElement) });

    //if($.browser.msie6) $('input[type=checkbox]').checkbox({cls:'jquery-cs-checkbox', empty: '/Image/e.gif'});
    updateSelectedStyle();
    $('.options :checkbox').bind('focus blur change', updateSelectedStyle, updateSelectedStyle);
    $(':checkbox').addClass('checkbox');
    $('.textBox').autocomplete('/SearchData.aspx', { extraParams: { lang: lang} });

    /* iframes */

    // $.frameReady(function(){ alert('x'); },"top.iFrame", {load: [{type:"stylesheet", src:"/Layout/Default/Style/Print.css", id:"_ss"}]});

    /* sitemap */

    $('.smTree ul.level0').treeview();

    /* fav */


    $('.icon_bookmark').jFav();

    /* print */

    $('.icon_print').click(function() { window.print(); });

    });

$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover( 
			function() { $(this).addClass(c);  },
			function() { $(this).removeClass(c); }
		);
	});
};

function hideElement() {
    $(this).css('display','none');
};

function updateSelectedStyle() {
    $('.options :checkbox').removeClass('focused').parent().removeClass('focused');
    $('.options :checkbox:checked').addClass('focused').parent().addClass('focused');
};

function getLastChild(el) {
    return (el.lastChild && el.lastChild.nodeName != '#text') ? getLastChild(el.lastChild) : el;
};

//window.onbeforeprint = fixIE;

function fixIE() {
    $('.dynamicBackground').prepend('<div class="printIE">' + $('#main').html() + '</div>');
    $('#main').hide();
    setTimeout(function() { location.reload(); }, 500);
}
