;(function ($) {
	var preOpened = null;
	var mpreOpened = null;
	$.fn.toogleElement = function(options){
		var options = $.extend({
			ovrBull: 'images/arrow_ovr.jpg',
			norBull: 'images/arrow_nrl.jpg',
			keepOpen: null
		},options || {});
		
		$(this).each(function(){
			$(this).click(function(){
				/*alert($(this).attr('href'));
				alert($(preOpened).attr('href'));
				alert(preOpened);*/
				//alert($(this).attr('href'));
				//alert(preOpened);
				//alert(mpreOpened);
				//alert($(this).attr('href'));
				//alert($(preOpened).attr('href'));
				if($(this).attr('href') != $(preOpened).attr('href') && preOpened != null){
					$($(preOpened).attr('href')).slideToggle(700);
					if($($(preOpened).attr('rel')).attr('src') == options.norBull){
						$($(preOpened).attr('rel')).attr('src',options.ovrBull);
					}else{
						$($(preOpened).attr('rel')).attr('src',options.norBull);
					}
					mpreOpened = $(this);
					//alert(1);
				}else if(mpreOpened !=null && preOpened != null ){
					mpreOpened = null;
					//alert(2);
				}else if($(this).attr('href') == $(preOpened).attr('href')){
					mpreOpened = null;
					//alert(3);
				}else{
					mpreOpened = $(this);
					//alert(4);
				}
				preOpened = mpreOpened;
				$($(this).attr('href')).slideToggle(700);
				if($($(this).attr('rel')).attr('src') == options.norBull){
					$($(this).attr('rel')).attr('src',options.ovrBull);
				}else{
					$($(this).attr('rel')).attr('src',options.norBull);
				}
				return false; 
			});
			//alert(options.keepOpen);
			//alert('hi');
			/*if(options.keepOpen!=$(this).attr('href') || wLoaded){
				$($(this).attr('href')).slideToggle(0);
			}*/
			$($(this).attr('href')).slideToggle(0);
			if(options.keepOpen==$(this).attr('href')){
				$($(this).attr('href')).slideToggle(700);
				preOpened=this;
				options.keepOpen=null;
				$($(this).attr('rel')).attr('src',options.norBull);
			}
			
			if($($(this).attr('rel')).attr('src') == options.norBull){
				$($(this).attr('rel')).attr('src',options.ovrBull);
			}else{
				$($(this).attr('rel')).attr('src',options.norBull);
			}
		});
	};
})(jQuery);

