/* Вкладки */

var aTabs

function initTabs(){

	aTabs = document.getElementById('Tab1').childNodes

	for( var i = 0; i < aTabs.length; i++ )
		if( aTabs[i].nodeType == 1 && aTabs[i].className != 'Div' )
			aTabs[i].firstChild.onclick = ShowTab

}

function ShowTab(){
	if( this.parentNode.className != 'Active' ){

		for( var i = 0; i < aTabs.length; i++ )
			if( aTabs[i].nodeType == 1 && aTabs[i].className != 'Div' ){

				document.getElementById( 'C' + aTabs[i].id.substr(1) ).style.display = 'none'
				aTabs[i].className = ''

			}

		document.getElementById( 'C' + this.parentNode.id.substr(1) ).style.display = ''
		this.parentNode.className = 'Active'
		this.blur()

	}
	return false
}


/* Картинки */

var aPics = new Array, aImages = new Array, curImage = 0, toImage, progress = 0

function initPics(){

	var aTmp = document.getElementById('Images').childNodes
	for( var i = 0; i < aTmp.length; i++ ) if( aTmp[i].nodeType == 1 ) aImages.push(aTmp[i])

	var aTmp = document.getElementById('ImagesControl').childNodes
	for( var i = 0; i < aTmp.length; i++ ) if( aTmp[i].nodeType == 1 ) aPics.push(aTmp[i])

	for( var i = 0; i < aPics.length; i++ ) aPics[i].onclick = ShowPic

}

function ShowPic(){
	if( this.className != 'Active' && !progress ){

		toImage = this.id.substr(1)

		for( var i = 0; i < aPics.length; i++ ){

			aImages[i].style.display = ( i != curImage && i != toImage ) ? 'none' : ''
			aPics[i].className = ''

		}

		this.className = 'Active'
		progress = 110
		MakeFun()

	}
}

function MakeFun(){
	if( progress ){
		progress -= 10
		aImages[curImage].style.marginLeft = ( progress - 100 ) + '%'
		aImages[toImage].style.marginLeft = progress + '%'
		setTimeout('MakeFun()',15)
	} else {
		aImages[curImage].style.display = 'none'
		curImage = toImage
		progress = 0
	}
}


/* Инициализация */

window.onload = function(){
	if( document.getElementById('Tab1') ) initTabs()
	if( document.getElementById('ImagesControl') ) initPics()
	if( document.getElementById('Send') ) FormGuard()
}


/* Защита формы от спамеров */
function FormGuard(){
	$('#Send').click(
		function(){
			$(this).attr("name","Send")
		}
	)
}