/**
*
* @author Stephan Manteufel <stephan@manteufel.info>
*
* @package www.manteufel.info
*
* @version $Id: general.js 38 2010-07-31 09:21:49Z bluecase $
*
* @license http://www.gnu.org/licenses/lgpl.html GNU LGPL
*
* @copyright 2010 Stephan Manteufel
*/

if(
    'undefined' == window.debug
) {
    var debug = false;
}

var _location = String(window.location).split('#')[0];
var formularFieldsHaveChanged = false;


var imagesPreload = function () {
    var _images = new Array();

    try {
        for (__i = 0; __i < _icons.length; __i++) {
            __k = _images.length;
            _images[__k] = new Image();
            _images[__k].src = './images/icons/' + _icons[__i];
        }
    } catch(e) {
        if (
            debug
        ) {
            alert(e);
        }
    }
}

var validating = function(_type) {
    switch(_type) {

    case 'css':
        window.open('http://jigsaw.w3.org/css-validator/validator?profile=css3&warning=0&uri=' + escape(_location), 'validator');
        break;
    case 'html':
        window.open('http://validator.w3.org/check?verbose=1&uri=' + escape(_location), 'validator');
        break;
    }
    return false;
}

var internLink = function(_anchor) {
    window.location = _location + '#' +  _anchor;
}

function __init() {
    try {
        imagesPreload();
        $('#chiefContent > div.topLink').each(function(i) {
            $(this).click(function() {
                internLink('top');
            });
        });
        $('#sideMenu > div').each(function() {
            $(this).click(function() {
                internLink($(this).attr('id').split('_')[1]);
                $('#' + $(this).attr('id').split('_')[1]).fadeTo(1000, 0.1).fadeTo(1000, 1);
            });
        });
        $('#memberDataSendMiddle').click(function() {
            $('#memberDataForm').submit();
        });
        $('#memberDataForm').submit(function() {
            $('#memberDataAction').val('do_login');
        });
        $('#navigationBar > li').each(function(i) {
            $(this).mouseover(function(){
                $(this).find('ul').css('display', 'block');
            });
            $(this).mouseout(function(){
                $(this).find('ul').css('display', 'none');
            });
        });
        $('input').each(function(){
            $(this).change(function() {
                formularFieldsHaveChanged = true;
            });
        });
        $('textarea').each(function(){
            $(this).change(function() {
                formularFieldsHaveChanged = true;
            });
        });
        $('select').each(function(){
            $(this).change(function() {
                formularFieldsHaveChanged = true;
            });
        });
        $('form').each(function(){
            $(this).submit(function(){
                formularFieldsHaveChanged = false;
            });
        });

    } catch(e) {
        if (
            debug
        ) {
            alert(e);
        }
    }
}

try {
    window.onbeforeunload = function(){
        if (
            formularFieldsHaveChanged
        ) {
            return unescape(changesNotSavedWarning);
        }
    }
} catch (e) {
    if (
        debug
    ) {
        alert(e);
    }
}

