(function($){
	$.fn.gornjak_tabs = function()
	{
		var contents = new Array()
		$(this).find('li').each(function(){

			var a = $(this).children('a')
			var href = a.attr('href')

			var n = $(this).index()

			if (a.hasClass('on') && contents[n] == undefined)
			{
				contents[n] = $('div.tab_content').html()
			}

			a.click(function(){
				if (contents[n] == undefined)
				{
					$.ajax({
						type : 'post',
						url: href,
						success: function(data) {
							contents[n] = data
							$('div.tab_content').html(data)
						}
					});
				}
				else
					$('div.tab_content').html(contents[n])

				a.closest('ul').find('a').removeClass('on')
				$(this).addClass('on')

				return false
			})
		})
		return this
	}

	$.fn.gornjak_slider = function(){

		for (var i = 0; i < this.length ; i++)
		{
			set(this[i])
		}

		function set(object)
		{
			var controll = $(object).find('.centr')

			var slides = $(object).find('table.slides')
			var num = slides.find('td').length
			var act = 1

			$(object).find('a.right').click(function(){

				act = num
				var n = act - 1

				slides.animate({
					left : ('-' + (396 * n))
				},500)

				set_on()

				return false
			})

			$(object).find('a.left').click(function(){

				act = 1
				slides.animate({
					left : 0
				},500)

				set_on()

				return false
			})

			controll.find('a').not(':last, :first').click(function(){

				act = $(this).index()
				var n = act - 1

				slides.animate({
					left : (n != 0 ? '-' + (396 * n) : 0)
				},500)
				set_on()
				return false
			})

			controll.find('a:last').click(function(){

				if (act != num)
				{
					slides.animate({
						left : '-=396'
					},500)
					act++
					set_on()
				}

				return false
			})

			controll.find('a:first').click(function(){
				if (act != 1)
				{
					slides.animate({
						left : '+=396'
					},500)
					act--
					set_on()
				}
				return false
			})

			function set_on ()
			{
				controll.find('a.on').removeClass('on')
				controll.find('a:eq('+act+')').addClass('on')
			}
		}

		return this
	}
})(jQuery)

$(document).ready(function() {
	$('a[hrefpop=true]').addClass('highslide');
	$('a[hrefpop=true]').click(function(){
		return hs.expand(this);
	});

	//	$('input.input_clear').focus(function(){
	//		if (this.defaultValue == $(this).val())
	//			$(this).val('')
	//	})

	//	$('input.input_clear').blur(function(){
	//		if ($(this).val().length == 0)
	//			$(this).val(this.defaultValue)
	//	})

	$('ul.vkl').gornjak_tabs()
	$('.imgcat').gornjak_slider()
});

function openYouTube(opener) {
	var returnValue;

	// Safari Mobile doesn't have Flash, so we just let the device use the built-in
	// YouTube viewer.
	if (/(iPhone|iPod|iPad)/.test(navigator.userAgent))
		returnValue = true;
	else
		returnValue = hs.htmlExpand(opener, {
			objectType: 'iframe',
			width: 600,
			height: 505,
			transitions: ['fade'],
			allowSizeReduction: false,
			outlineType: 'rounded-white',
			outlineWhileAnimating: true,
			wrapperClassName: 'draggable-header no-footer',
			preserveContent: false,
			objectLoadTime: 'after',
			align : 'center'
		})
	return returnValue;
}

// В оформить заявку OnLine передаем.
var order_id = null

function modal (type,id)
{
	if (type == 'div.chat')
	{
		if (id !== undefined)
			order_id = id

		if ($('div.chat').length == 0)
			$.post('ajax.php',{type:'det_dialog_chat'},function(data){
				$('body').append(data)
				$('div.chat').modal({
				opacity: 50,
				overlayCss: {backgroundColor:"black"},
				overlayClose: true})
			})
		else
			$('div.chat').modal({
				opacity: 50,
				overlayCss: {backgroundColor:"black"},
				overlayClose: true
			})


		var text = 'Здравствуйте.<br>Вы можете получить цену и сроки в течении 24 часов после оформлении заявки.';
		var p = ' '
		setTimeout(function(){
			var text_chat = setInterval(function(){
				if (text.length > p.length)
				{
					p = p + text.charAt(p.length - 1)
					$('dd.text_chat').html(p)
				}
				else
					clearInterval(text_chat)
			},50)
		},2000)
	}
}

function table_link_download_order (id)
{
	$.post('ajax',{type: 'table_link_download_order', id : id},function (data){
		location.href = data
	})
}

