/*
* MyExNav 1
* Version 1.0
* Autor : Cabcom13.de (www.Cabcom13.de)
*
* Licensed under GPL <http://en.wikipedia.org/wiki/GNU_General_Public_License>
* Copyright (c) 2010, Cabcom13.de <Cabcom13@aol.com>
* All rights reserved.
*
This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

(function(jQuery){
	jQuery.fn.myexnav = function(options) {
			var settings = {		
                                popup_trigger : '.popup_trigger',
                                popup_container: '',
                                hover_trigger:  '#last_posts span',
                                more_containers: ''
			};
			if(options) {
				jQuery.extend(settings, options);
			}


                           index1 = new Array();
               
                           return this.each(function () {
                                 $(this).each(function () {
                                   
                                   index1.push($(this).attr('id'));
                                 });

                                $(this).click(function(index) {
                                   clicked = $(this).attr('id').substring(14);                                               
                                       $.each(index1, function(key, value) {
                                          var tm = value.substring(14);
                                            if(tm != clicked){
                                                $('#popup_container-'+tm).fadeOut("fast", "swing");
                                                $('#popup_trigger-'+tm+' span').removeClass('hover');
                                            } else {

                                                x = $('#popup_trigger-'+clicked).position();
                                                if(clicked == 1){
                                                    $('#popup_container-'+clicked).css("left", x.left+34);
                                                } else {
                                                    $('#popup_container-'+clicked).css("left", x.left-1);
                                                }
                                                $('#popup_container-'+clicked).fadeIn("fast", "swing").bind('mouseleave', function() {
                                                  $(this).fadeOut("fast", function() {});
                                                  $('#popup_trigger-'+clicked+' span').removeClass('hover');
                                                });
                                                $('#popup_trigger-'+clicked+' span').addClass('hover');
                                            }
                                        });

                                    
                                $(this).mouseleave(function() {
                                    $(this + ' span').removeClass('hover');
                                    //$('#yourdkp_popup').fadeOut("fast", function() {});
                                });
                                    index = $(this).attr('id').split("-");
                                    $('#popup_container-'+index[1]).fadeIn("fast", "swing");
                                });

                            });
                           
			


	};
})(jQuery);
