$(document).ready(function()
{
	$(".tr-table").hover(function () {
		var tr = this;
		$(this).children().each(function (i) {
			this.style.backgroundColor = $(tr).attr('rollOverColor');
		});
    }, function () { 
    	var tr = this;
		$(this).children().each(function (i) {
			this.style.backgroundColor = $(tr).attr('rollOutColor');
		});
    });
    
    $(".tr-table").click(function () { 
		var id = this.id.split('td-table-').join('');
		window.location.replace('index.php?id=' + id);
    });
    
    $(".header-table-div > img").click(function () 
    {
    	var nr = $(this).attr('src').split('images/a').join('').split('images/b').join('').split('.jpg').join('');
    	var array = 'ASC';
    	if(nr == '2') array = 'DESC';
    	$('#interface-array').val(array);
    	$('#interface-col').val($(this).parent().attr('id'));
		$('#interface-table').submit();
    });
    
    $(".tr-table").click(function () 
    { 
		var id = this.id.split('td-table-').join('');
		$('#interface-id').val(id);
		$('#interface-table').submit();
    });
    
    $("#kontakt-ikona").click(function () 
    { 
		var item = $(this).attr('id').split('-ikona').join('');

		if(!$("#" + item + "-opis").hasClass('select'))
		{
			$("#" + item + "-opis").addClass('select');
			$("#" + item + "-opis").show();
		}
		else
		{
			$("#" + item + "-opis").removeClass('select');
			$("#" + item + "-opis").hide();
			}
    });

	 $("#link-ikona").click(function () 
    { 
		var item = $(this).attr('id').split('-ikona').join('');
    
		if(!$("#" + item + "-opis").hasClass('select'))
		{
			$("#" + item + "-opis").addClass('select');
			$("#" + item + "-opis").show();
		}
		else
		{
			$("#" + item + "-opis").hide();
			$("#" + item + "-opis").removeClass('select');
			}
			

		$("#" + item + "-opis *").selText().addClass("selected");

    });
    
    $("#print-ikona").click(function () 
    { 
		window.print()
	});
    
     $(function() {
       $('#gallery a').lightBox();
	});
    
});

jQuery.fn.selText = function() {
    var obj = this[0];
    if ($.browser.msie) {
        var range = obj.offsetParent.createTextRange();
        range.moveToElementText(obj);
        range.select();
    } else if ($.browser.mozilla || $.browser.opera) {
        var selection = obj.ownerDocument.defaultView.getSelection();
        var range = obj.ownerDocument.createRange();
        range.selectNodeContents(obj);
        selection.removeAllRanges();
        selection.addRange(range);
    } else if ($.browser.safari) {
        var selection = obj.ownerDocument.defaultView.getSelection();
        selection.setBaseAndExtent(obj, 0, obj, 1);
    }
    return this;
}
