/*
** ****************************************************************************
** Unido CSS Framework (UCF) - Basic JS Functions using the jquery lib
** ****************************************************************************
** @package    ucf
** @version    0.1.9
** @link       http://www.unido.org
** @autor      Alexander Knett / LIVINGPIXEL
** @copyright  Copyright 2007 - All rights reserved
** ****************************************************************************
*/

/*
** ****************************************************************************
** Basic functions when document is ready
** ****************************************************************************
*/

$(document).ready(function() {

/* On the unido homepage there are 3 quick jump navs. Simply attach the event
** to chnage the location of the window. The <select> only need the class
** ucfQuickJump assigned.
*/

    $("select.ucfQuickJump").change(function() {

        // if you want only redirects within a specific site set the
        // url here (like http://www.unido.org/).
        siteprefix = ""

        // only redirect if we have a value
        if ($(this)[0].value != "") {
            window.location.href = siteprefix + $(this)[0].value;
        }
    });

/* Attach rollover states to images and input fields. Each image or input field
** needs the class ucfRollOverImg assigned. Images must use a special extension:
** _h.gif for the rollover state and _a.gif for the active state. All images
** have to be inside the same folder. Only .gif images supported for now. Makes
** sense, because we need transparency and in oder to support older browsers
** without a js hack we can not use .png format.
*/

    // Preload all rollovers
    $("img.ucfRollOverImg,input.ucfRollOverImg").each(function() {
    	// Set the original src
    	rollsrc = $(this).attr("src");
    	rollON = rollsrc.replace(/.gif$/ig,"_h.gif");
        activeON = rollsrc.replace(/.gif$/ig,"_a.gif");
    	$("<img>").attr("src", rollON);
        $("<img>").attr("src", activeON);
    });

    // Rollover State
    $("img.ucfRollOverImg,input.ucfRollOverImg").mouseover(function(){
        imgsrc = $(this).attr("src");
        imgsrcOri = imgsrc;
    	matches = imgsrc.match(/_h/);

    	// don't do the rollover if state is already ON
    	if (!matches) {
    	imgsrcON = imgsrc.replace(/.gif$/ig,"_h.gif"); // strip off extension
    	$(this).attr("src", imgsrcON);
    	}

    });

    // Active State
    $("img.ucfRollOverImg,input.ucfRollOverImg").mousedown(function(){
    	imgsrc = $(this).attr("src");
    	matches = imgsrc.match(/_a/);

    	// don't do the rollover if state is already ON
    	if (!matches) {
    	imgsrcON = imgsrc.replace(/_h.gif$/ig,"_a.gif"); // strip off extension
    	$(this).attr("src", imgsrcON);
    	}

    });

    // Recover Normal State
    $("img.ucfRollOverImg,input.ucfRollOverImg").mouseout(function(){
    	$(this).attr("src", imgsrcOri);
    });
});
