/*
* Набор всякого.
*/


// jQuery.noConflict();

(function($) {

	function InitSite()
		{
			InitVacancies();
			InitComplectation();
			InitPopups();
		}




	////////////////////////////////////////////
	// Вакансии
	////////////////////////////////////////////
	
	
	$.extend({
		AccordionList: new function()
			{
				// 
				this.defaults	= {
					cssDTOpened:		"Opened",
					cssDDOpened:		"Opened",
					cssDTClosed:		false,
					cssDDClosed:		false
				};
				// показывает DT/DD
				function ShowDD( oDL, oDT )
					{
						HideDD( oDL )
						$( oDT )
							.removeClass( oDL.config.cssDTClosed )
							.addClass( oDL.config.cssDTOpened )
								.next()
								.show("normal")
								.removeClass( oDL.config.cssDDClosed )
								.addClass( oDL.config.cssDDOpened );
								
						oDL.config.iOpened = $("DT", oDL).index(oDT);
					}

				// прячет DD
				function HideDD( oDL )
					{
						if( oDL.config.iOpened == -1 )
							return;

						$("DT", oDL).eq( oDL.config.iOpened )
							.removeClass( oDL.config.cssDTOpened )
							.addClass( oDL.config.cssDDClosed )
								.next()
								.hide("normal")
								.removeClass( oDL.config.cssDDOpened )
								.addClass( oDL.config.cssDDClosed );

						oDL.config.iOpened = -1;
					}

				// управляющая функция
				function ShowOrHideDD( oDL, oDT )
					{
						if(	oDL.config.iOpened > -1 && oDL.config.iOpened == $("DT", oDL).index( oDT ) )
							HideDD( oDL );
						else 
							ShowDD( oDL, oDT );
					}

				/* public методы */
				this.construct	= function( settings )
					{
						return this.each( function()
							{
								// если это не список, или нету dt, dd, то на выброс
								if( !(this.nodeName == "DL") )
									return;
									
								var self	= this;

									this.config		= { iOpened: -1 }; // индекс раскрытого элемента
									config			= $.extend( this.config, $.AccordionList.defaults, settings );

									$this	= $( this );			// для ускорения
									
									$("DT", this).click( function(){ ShowOrHideDD( self, this ); return false; });
									$("DT", this).bind("mouseenter mouseleave", function()
										{
											$( this ).toggleClass( self.config.cssDTOpened );
										});
								
							});
					}
			}
	});
	
	$.fn.extend({
		AccordionList: $.AccordionList.construct
	});

	function InitVacancies()
		{
		
			$(".Vacancy").AccordionList({
					cssDTOpened:	"GraphicalSelected",
					cssDTClosed:	"Graphical"
				});
		}


	////////////////////////////////////////////
	// Комплектация
	////////////////////////////////////////////
	
	function InitComplectation()
	{
		if ( $(".ControlLinks").length > 0 && $(".ControlContent").length > 0 ){
			$(".ControlLinks li").click(function(){
				$(".ControlContent > div").hide();
				$(".ControlContent > div").eq( $(".ControlLinks li").index( this ) ).show();
				$("#ControlTitle").text( $( this ).text() );
				$(".ControlLinks li").removeClass("GraphicalLocalSelected").addClass("GraphicalLocal").css("cursor","pointer");
				$(this).removeClass("GraphicalLocal").addClass("GraphicalLocalSelected").css("cursor", "default");
				return false;
			});
			$(".ControlLinks li:first").click();
		}
	}
	
	function InitPopups()
	{
		if ( $('a[rel="popup"]').length > 0 ) {
			$('a[rel="popup"]').click(function() {
				oWindow	= window.open($(this).attr("href"),'Технические характеристики','width=500,height=600,toolbar=0,location=0,scrollbars=yes,left='+ (screen.width - 500) / 2 +',top='+ (screen.height - 600) / 2 );
				oWindow.focus();
				return false;
			});
		}
	}
	


////////////////////////////////////////////////////////////////////////////////
	
	$(document).ready( function(){
			InitSite();
		});
	

})(jQuery);

