$(document).ready(function() {
	
	$("a[rel='eksempel']").colorbox({photo:"true", current:"Bilde {current} av {total}", previous:"Forrige", next:"Neste", close:"Lukk"});
	

    $('form#jobber select').change(function() {


        var employeeVal = $('#ansatt').val();
        var categoryVal = $('#type').val();
        var clientVal = $('#kunde').val();


        if (employeeVal == '' && categoryVal == '' && clientVal == '') {
            jQuery.each($('div.jobb'),
            function() {
                $(this).fadeIn('slow').removeClass('hidden');
            });
        } else if (employeeVal != '' && categoryVal == '' && clientVal == '') {
            jQuery.each($('div.jobb'),
            function() {
                if ($(this).hasClass(employeeVal)) {
                    $(this).fadeIn('slow').removeClass('hidden');
                } else {
                    $(this).fadeOut('slow').addClass('hidden');
                }
            });
        } else if (employeeVal == '' && categoryVal != '' && clientVal == '') {
            jQuery.each($('div.jobb'),
            function() {
                if ($(this).hasClass(categoryVal)) {
                    $(this).fadeIn('slow').removeClass('hidden');
                } else {
                    $(this).fadeOut('slow').addClass('hidden');
                }
            });
        } else if (employeeVal == '' && categoryVal == '' && clientVal != '') {
            jQuery.each($('div.jobb'),
            function() {
                if ($(this).hasClass(clientVal)) {
                    $(this).fadeIn('slow').removeClass('hidden');
                } else {
                    $(this).fadeOut('slow').addClass('hidden');
                }
            });
        } else if (employeeVal == '' && categoryVal != '' && clientVal != '') {
            jQuery.each($('div.jobb'),
            function() {
                if ($(this).hasClass(clientVal) && $(this).hasClass(categoryVal)) {
                    $(this).fadeIn('slow').removeClass('hidden');
                } else {
                    $(this).fadeOut('slow').addClass('hidden');
                }
            });
        } else if (employeeVal != '' && categoryVal != '' && clientVal == '') {
            jQuery.each($('div.jobb'),
            function() {
                if ($(this).hasClass(employeeVal) && $(this).hasClass(categoryVal)) {
                    $(this).fadeIn('slow').removeClass('hidden');
                } else {
                    $(this).fadeOut('slow').addClass('hidden');
                }
            });
        } else if (employeeVal != '' && categoryVal == '' && clientVal != '') {
            jQuery.each($('div.jobb'),
            function() {
                if ($(this).hasClass(employeeVal) && $(this).hasClass(clientVal)) {
                    $(this).fadeIn('slow').removeClass('hidden');
                } else {
                    $(this).fadeOut('slow').addClass('hidden');
                }
            });
        } else if (employeeVal != '' && categoryVal != '' && clientVal != '') {
            jQuery.each($('div.jobb'),
            function() {
                if ($(this).hasClass(employeeVal) && $(this).hasClass(categoryVal) && $(this).hasClass(clientVal)) {
                    $(this).fadeIn('slow').removeClass('hidden');
                } else {
                    $(this).fadeOut('slow').addClass('hidden');
                }
            });
        }

    });
//visning og fjerning av storbildebokser på mouseover / out
	/*if ($("div").hasClass("storbildeboks")) {
		$('body').append('<div id="tooltip">kkk</div>');
		$("#coltwo div.bildeboks a img").mouseover(function(){
			alert($(this).parent().find("div.storbildeboks").html());
			//$(this).parent().find("div.storbildeboks").show(); 
		});
	}*/
	/*$("div.storbildeboks>a>img").mouseout(function(){
		$("div.storbildeboks").hide();
	});
	$("div.storbildeboks").mouseout(function(){
		$("div.storbildeboks").hide();
	});
	$("div.bildeboks>img").mouseover(function(){
		$(this).parent().find("div.storbildeboks").show(); 
	});*/
	$("div.bildeboks>a>img").hover(tooltip,tooltip);
	
});
function tooltip (e) {
	if (e.type == 'mouseenter') {
		$(this).parent().parent().addClass('active');
		var values = $(this).attr('alt').split('||');
		var pos = $(this).parent().parent().offset();
		$('#tooltip').html('<h2>'+values[0]+'</h2><p>'+values[1]+'</p>').css({left: (pos.left + 54), top: (pos.top)}).show();
	} else {
		$(this).parent().parent().removeClass('active');
		$('#tooltip').hide();
	}
}

