    /* Prettyphoto
	------------------------------------------------------------------------------------------------*/
	
	  $(document).ready(function(){
		$("a[rel^='prettyPhoto']").prettyPhoto();
	  });

    /* Gallery fade in
	------------------------------------------------------------------------------------------------*/

	  $(function() {
		  $(".gallery li img").hover(function () {
			$(".gallery li img").stop().animate({opacity: "0.3"});
	   
		  	$(this).stop().animate({
			  opacity: 1.0
			  }, "normal");
			  
			  }, function () {
			  	$(".gallery li img").stop().animate({opacity: "1"});
		  	});
	  });

	  /* Tabs
	  ------------------------------------------------------------------------------------------------*/

    $(document).ready(function(){
        //  When user clicks on tab, this code will be executed
        $("#tabs li").click(function() {
            //  First remove class "active" from currently active tab
            $("#tabs li").removeClass('active');
 
            //  Now add class "active" to the selected/clicked tab
            $(this).addClass("active");
 
            //  Hide all tab content
            $(".tab_content").hide();
 
            //  Here we get the href value of the selected tab
            var selected_tab = $(this).find("a").attr("href");
 
            //  Show the selected tab content
            $(selected_tab).show();
 
            //  At the end, we add return false so that the click on the link is not executed
            return false;
        });
	});
	
    /* Equal heights
	------------------------------------------------------------------------------------------------*/
    
	$(document).ready(function() {
	    $(".box, ul.glossary li, .numericList li").equalHeights();
    });

    /* Loginbox
    ------------------------------------------------------------------------------------------------*/

	var LoginBox = new function () {

	    //this.mouse_is_inside = false;

        this.toggle = function () {
            var form = $(".loginform");
            if (form.css("display") == "none") {
                LoginBox.show();
            } else {
                LoginBox.hide();
            }
        };

        this.show = function () {
            $(".loginform").fadeIn("fast");

            $("<div id=\"loginFormBackground\"></div>")
            .css({
                top: 0,
                left: 0,
                zIndex: 140,
                position: 'absolute',
                width: $(document).width(),
                height: $(document).height()
            })
            .prependTo("body")
            .bind("click", function() {
                LoginBox.hide();
            });

            
        };

        this.hide = function () {
            $(".loginform").fadeOut("fast", function () {
                $("#loginFormBackground").remove();
            });
        };
    }


    var notificationWindow
    var Notification = new function () {
        this.show = function (content) {

            if (notificationWindow != undefined && $(".notification-window-content").html() != "" && $(".notification-window-content").html() != null) {
                notificationWindow.closewindow();
            }

            notificationWindow = $.fn.modalWindow({
                id: "notification-window",
                theme: "notification-window",
                html: content
            });
        };

        this.hide = function (box, background, fill) {
            if (notificationWindow != undefined && $(".notification-window-content").html() != "" && $(".notification-window-content").html() != null) {
                notificationWindow.closewindow();
            }
        };
    }

    /* Hash navigation
    ------------------------------------------------------------------------------------------------*/
    function navigation(hash) {
        switch (hash) {
            case "#login":
                LoginBox.show();
            break;
        }
    }


	/* Tooltip
	------------------------------------------------------------------------------------------------*/
	this.tooltip = function () {
	    /* CONFIG */
	    xOffset = 70;
	    yOffset = -125;
	    // these 2 variable determine popup's distance from the cursor
	    // you might want to adjust to get the right result		
	    /* END CONFIG */
	    $("a.tooltip").hover(function (e) {
	        this.t = this.title;
	        this.title = "";
	        $("body").append("<p id='tooltip'>" + this.t + "</p>");
	        $("#tooltip")
				.css("top", (e.pageY - xOffset) + "px")
				.css("left", (e.pageX + yOffset) + "px")
				.fadeIn("fast");
	    },
		function () {
		    this.title = this.t;
		    $("#tooltip").remove();
		});
	    $("a.tooltip").mousemove(function (e) {
	        $("#tooltip")
				.css("top", (e.pageY - xOffset) + "px")
				.css("left", (e.pageX + yOffset) + "px");
	    });
	};

	$(document).ready(function () {
	    $.fn.slideShow = function (options) {
	        var defaults = {
	            interval: 8
	        }

	        options = $.extend(defaults, options)

	        var slideShow = options.holder;
	        var slides = [];
	        var current = -1;
	        var total = slideShow.children(".slide").length;
	        var navigationHolder;
	        var timer;

	        var init = function () {

	            if (total > 1)
	                createNavigation();

	            nextSlide();

	            if (total > 1) {
	                slideShow.hover(
                        function () {
                            stopTimer();
                        },
                        function () {
                            startTimer();
                        }
                    );
	            }
	        }

	        var createNavigation = function () {
	            navigationHolder = $("<div class=\"ballNavigation\"></div>").appendTo(slideShow);

	            var count = 0;

	            slideShow.children(".slide").each(function () {
	                var link = $("<a class=\"ball\" href=\"#\"></a>")
                                .css({
                                    opacity: 0.5
                                })
                                .unbind()
                                .bind("click", function () {
                                    showSlide(parseInt($(this).data("ballId")))
                                    return false;
                                })
                                .data("ballId", count)
                                .appendTo(navigationHolder);
	                count++;
	            });
	        }

	        var checkNavigation = function () {
	            if (navigationHolder != undefined) {
	                navigationHolder.find(".selected").removeClass("selected");
	                navigationHolder.find(".ball:nth-child(" + (current + 1) + ")").addClass("selected");
	            }
	        }

	        var showSlide = function (child) {
	            if (current == child)
	                return;

	            var count = 0;

	            current = child;

	            slideShow.children(".slide").fadeOut("slow");
	            slideShow.children(".slide").each(function () {
	                if (count == child) {
	                    $(this).fadeIn("slow", function () {
	                        if (total > 1)
	                            startTimer();
	                    });

	                    checkNavigation();

	                    return false;
	                }
	                count++;
	            });
	        }

	        var nextSlide = function () {

	            current++;
	            var count = 0;

	            if (current == total)
	                current = 0;

	            slideShow.children(".slide").fadeOut("slow");
	            slideShow.children(".slide").each(function () {
	                if (count == current) {
	                    $(this).fadeIn("slow", function () {
	                        if (total > 1)
	                            startTimer();
	                    });

	                    checkNavigation();

	                    return false;
	                }
	                count++;
	            });
	        }

	        var startTimer = function () {
	            if (timer != undefined && timer != null)
	                clearTimeout(timer);

	            timer = setTimeout(nextSlide, options.interval * 1000);
	        }

	        var stopTimer = function () {
	            if (timer != undefined && timer != null)
	                clearTimeout(timer);
	        }

	        init();
	    }
	});


	function parseBody() {
	    $(".numericList").each(function () {
	        var columns = 3;
	        var count = 1;
	        var column = 1;
	        var row = 1;
	        var total_rows = Math.ceil($(this).children().length / columns);

	        $(this).children().each(function () {
	            if ($(this).find(".number").length == 0)
	                $(this).prepend("<span class=\"number\">" + count + "</span>");
	            else {
	                $(this).find(".number").remove();
	                $(this).prepend("<span class=\"number\">" + count + "</span>");
	            }

	            $(this).removeClass().addClass("column_" + column);
	            
	            if (row == total_rows) {

	                $(this).addClass("lastRow");
	            }

	            column++;
	            count++;

	            if (column == (3 + 1)) {
	                column = 1;
	                row++;
	            }
	        });
	    });
	}


	/* Body load function
	------------------------------------------------------------------------------------------------*/
	$(function () {

	    tooltip();

	    parseBody();

	    $("#changeLanguage").unbind().bind("click", function () {
	        $(this).fadeOut();
	        $(".languages").fadeIn();
	        return false;
	    });

	    $(".topNav li:first-child a").unbind().bind("click", function () {
	        if ($(this).attr("href").toLowerCase().indexOf("login") > -1) {
	            LoginBox.toggle();

	            return false;
	        }
	    });

	    $(".slider").each(function () {
	        $.fn.slideShow({ holder: $(this) });
	    });


	    if (window.location.hash != "") {
	        navigation(window.location.hash);
	    }

	    window.onhashchange = function () {
	        navigation(window.location.hash);
	    };

	    /* Search menu option */
	    var hideSearchBox = function (e) {
	        if ($(e.target).closest(".search_dropdown").get(0) == null) {
	            $(".search_dropdown").hide();
	            $(".menu_black li.search").removeClass("active");
	            $("body").unbind("click", hideSearchBox);
	        }
	    }

	    $(".menu_black li").hover(function () {
	        $(".search_dropdown").hide();
	        if ($(this).hasClass("search")) {
	            $(".search_dropdown").show();
	            //$(".dropSearch").focus();
	            //$(this).addClass("active");
	            $("body").unbind("click", hideSearchBox).bind("click", hideSearchBox);
	        }
	        else {
	            $(".dropSearch").blur();
	            $(".menu_black li.search").removeClass("active");
	            $(".search_dropdown").hide();
	            $("body").unbind("click", hideSearchBox);
	        }
	    });
	    $(".menu_black li.search").mouseleave(function () {
	        if (!$(".dropSearch").is(":focus")) {
	            $(".dropSearch").blur();
	            $(".search_dropdown").hide();
	            $(this).removeClass("active");
	            $("body").unbind("click", hideSearchBox);
	        }
	    });
	    $(".search_dropdown").hover(function () {
	        $(this).show();
	        //$(".dropSearch").focus();
	        $(".menu_black li.search").addClass("active");
	        $("body").unbind("click", hideSearchBox).bind("click", hideSearchBox);
	    });

	    $(".search_dropdown").mouseleave(function () {
	        if (!$(".dropSearch").is(":focus")) {
	            $(".dropSearch").blur();
	            $(this).hide();
	            $(".menu_black li.search").removeClass("active");
	            $("body").unbind("click", hideSearchBox);
	        }
	    });



	});
