function mouseOver(id){
	if (id=="next") {
		document.getElementById("next").src ="../images/nextlight30x30.png";
	} else if (id=="previous") {
		document.getElementById("previous").src ="../images/prevlight30x30.png";
	} else if (id=="show"){
		document.getElementById("show").src ="../images/pluslight30x30.png";
	} else {
		document.getElementById("hide").src ="../images/minuslight30x30.png";
	}
};

function mouseOut(id){
	if (id=="next") {
		document.getElementById("next").src ="../images/next30x30.png";
	} else if (id=="previous"){
		document.getElementById("previous").src ="../images/prev30x30.png";
	} else if (id=="show"){
		document.getElementById("show").src ="../images/plus30x30.png";
	} else {
		document.getElementById("hide").src ="../images/minus30x30.png";
	}
};

//avoid possible conflict with Wibiya's $
var $j = jQuery.noConflict()

$j(document).ready(function(){
    $j('#hide').click(function(){ //hide side menu
		$j('aside').fadeOut('fast', function(){
			$j('#content').animate({}, 'fast');
		});
		$j(this).fadeOut('fast', function(){
			$j('#show').fadeIn('fast');
		});
		document.cookie="asideCookie=hidden";
    });
	$j('#show').click(function(){ //hide side menu
		$j('#content').animate({}, 'fast', function(){
			$j('aside').css('display', 'table-cell');
		});
		$j(this).fadeOut('fast', function(){
			$j('#hide').fadeIn('fast');
		});
		document.cookie="asideCookie=shown";
    });
	$j('div.language').mouseenter(function(){
		$j("img", this).stop().animate({
			"width"	: "32px",
			"height":"25px",
			"margin-left": "12px",
			"margin-right": "12px",
			"margin-top": "0px",
                        "margin-bottom": "0px"
			}, "fast");
	});
	$j('button.archive').click(function(){
			$j(this).siblings('.archive').toggle('slow');
    });
	$j('div.language').mouseleave(function(){
		$j("img", this).stop().animate({
			"width"	: "16px",
			"height":"13px",
			"margin-left": "20px",
			"margin-right": "20px",
			"margin-top": "6px",
                        "margin-bottom": "6px"
			}, "fast");
	
	});
	
	// toggle hide/show answers to exercises
	// the exercise-div and answer-div must be wrapped within same wrap-div	
	$j("button.no_password").click(function(){ 
			$j(this).siblings('.togglebox').toggle();
    	});
    	
    $j("button.password").click(function(){
    	if ($(this).siblings('.togglebox').css('display')!="none") {
    		$(this).siblings('.togglebox').toggle();
		} else {
			psswd=prompt("Enter the password:","");
    		if (psswd!=null && psswd=="sesame") { 
				$(this).siblings('.togglebox').toggle();
			}
		}
    });	
});

function externalLinks() {  
	if (!document.getElementsByTagName) return;  
 	var anchors = document.getElementsByTagName("a"), i;  
 	for (i=0; i<anchors.length; i++) {   
   		if (anchors[i].getAttribute("href") && anchors[i].getAttribute("rel") == "external")  
     		anchors[i].target = "_blank";  
	 }  
}; 

function swapToAppletVersion4(appletID, screenshotID, cb, w, h, f, inputBar, toolBar, rightClick) {
// w=width, h=height, f=filename,
	var attributes, parameters, appletTag, attribute, parameter, param, bodyRef, screenshot;
	inputBar = typeof(inputBar) != 'undefined' ? inputBar : 'false';
	toolBar = typeof(toolBar) != 'undefined' ? toolBar : 'false';
	rightClick = typeof(rightClick) != 'undefined' ? rightClick : 'false';
    attributes = {
		name: 'ggbApplet',
		code:'geogebra.GeoGebraApplet',
		codebase: cb,
		archive: 'geogebra.jar',
        width: w,
        height: h
    };
    parameters = {
        filename: f,
		java_arguments: '-Xmx512m -Djnlp.packEnabled=true',
        cache_archive: 'geogebra.jar, geogebra_main.jar, geogebra_gui.jar, geogebra_cas.jar, geogebra_algos.jar, geogebra_export.jar, geogebra_javascript.jar, jlatexmath.jar, jlm_greek.jar, jlm_cyrillic.jar, geogebra_properties.jar',
        cache_version: '4.0.10.0, 4.0.10.0, 4.0.10.0, 4.0.10.0, 4.0.10.0, 4.0.10.0, 4.0.10.0, 4.0.10.0, 4.0.10.0, 4.0.10.0, 4.0.10.0',
		framePossible: 'false',
		showResetIcon: 'true',
		showAnimationButton: 'true',
		enableRightClick: rightClick,
        errorDialogsActive: 'true',
		enableLabelDrags: 'false',
		showMenuBar: 'false',
		showToolBar: toolBar,
		showToolBarHelp: 'true',
		showAlgebraInput: inputBar,
		useBrowserForJS: 'true',
        allowRescaling: 'true'
    };


    appletTag = document.createElement("applet");

	if (attributes != 'undefined' && attributes !== null) {
    	for (attribute in attributes) {
        	appletTag.setAttribute(attribute,attributes[attribute]);
    	}
	}

    if (parameters != 'undefined' && parameters !== null) {
        for (parameter in parameters) {
            param = document.createElement("PARAM");
            param.setAttribute("name",parameter);
            param.setAttribute("value",parameters[parameter]);
            appletTag.appendChild(param);
        }
    }


    bodyRef = document.getElementById(appletID);
    screenshot = document.getElementById(screenshotID);
    bodyRef.removeChild(screenshot);
    bodyRef.appendChild(appletTag);
};


