/**
 * @author: Stefan Heckler
 **/

registerNamespace = function(space) {

    var parts = space.split('.');
    var root = window;

    for (var i = 0; i < parts.length; ++i) {

        if (typeof root[parts[i]] == 'undefined') {
        	root[parts[i]] = new Object();
        }

        root = root[parts[i]];

    }

    return root;
};


$.ajaxSetup({
    async: true/*,
    beforeSend: overlay,
    complete: overlay
*/
});



jQuery.fn.modifyLinksForStudentPreview = function(){

	$(this).tooltip({

      	track: true,
        delay: 0,
        showURL: false,
        bodyHandler: function() {

            $(this).css('cursor', 'help');

            return student_preview_not_available_text;
        }
    });
    

    $(this).click(function(){
        return false;
    });
	
};

jQuery.fn.modifyLinksForPreview = function(){
	
	$(this).attr('href', '#');
	
	$("div.hoverError.hidden").removeClass('hidden');
	
	setTimeout(function(){
		$("div.hoverError").fadeOut("Slow", function(){
			$(this).addClass('hidden').attr('style', '');
		});
	}, 3000);
};


$(document).ready(function(){

	
	$("a.closeHoverError").click(function(){
		$(this).parent().fadeOut("fast", function(){
			$(this).addClass('hidden').attr('style', '')
		});
	});

    // ie submit-button fix
    $("input[type='submit']").focus(function(){
        this.blur;
        return false;
    });


    // iconbox fading
    $("div.iconbox a").hover(function () {

		$(this).prevAll().dequeue().fadeTo(400,0.4);

		$(this).nextAll().dequeue().fadeTo(400,0.4);

    },function() {

		$(this).prevAll().dequeue().fadeTo(400,1,function(){if ($.browser.msie) this.style.removeAttribute('filter')});

		$(this).nextAll().dequeue().fadeTo(400,1,function(){if ($.browser.msie) this.style.removeAttribute('filter')});

	});


    // bookmarkBar
    $("a.bookmark_bar").click(
        function(){
            if($("ul.bookmark_bar").hasClass("hidden"))
            {
                $("ul.bookmark_bar").fadeIn(75);
                $("ul.bookmark_bar").removeClass("hidden");
                $("a.bookmark_bar").css("background-image", "url('/media/img/site/arrow_up.gif')");
            }
            else
            {
                $("ul.bookmark_bar").fadeOut(75);
                $("ul.bookmark_bar").addClass("hidden");
                $("a.bookmark_bar").css("background-image", "url('/media/img/site/arrow_down.gif')");
            }

            return false;
        }
    );




	// remove links to home/error and add tooltip

    $("a[href='"+baseurl+"home/error.html']").tooltip({

      	track: true,
        delay: 0,
        showURL: false,
        bodyHandler: function() {

            $(this).css('cursor', 'default');

            return under_construction_text;
            /*return "Diese Seite befindet sich momentan noch im Aufbau.";*/
        }
    });


    $("a[href='"+baseurl+"home/error.html']").click(function(event){
		event.preventDefault();

        //return false;
    });
	
	
	
	
	// student preview for companies
	if(student_preview)
	{
		$("a.link_disabled_in_preview").modifyLinksForStudentPreview();
		$("a[href^='/applications']").modifyLinksForStudentPreview();
		$("a[href^='/home/promotion_form']").modifyLinksForStudentPreview();
		$("a[href^='"+baseurl+"jobs/apply']").modifyLinksForStudentPreview();	
	}
	



    $("img.kununu_rating_bar").tooltip({

       track: true,
        delay: 0,
        showURL: false,
        bodyHandler: function() {

            return rating_description_text;

        }
    });


    $("form[name='cvgen'] a.jNiceCheckbox").click(function(){
        JZ.form.toggleDateToSelectVisibility($(this));
    });
	
		

	$('.email').mailto();

});