var slideshow_int;
$(function(){
	$('.subscribe input[type="text"]')
		.click(function(){
			if($(this).val() == subscribe_default)
				$(this).val('')
			$(this).addClass('focus')
		})
		.blur(function(){
			$(this).val($(this).val().replace(/^\s*|\s*$/g,''));
			if($(this).val() == '')
			{
				$(this)
					.val(subscribe_default)
					.removeClass('focus')
			}
		})

	if((!(jQuery.browser.msie && parseInt(jQuery.browser.version) == '6')))
	{
		$('#text form select').each(function(i){
			select_elem = $(this)
			select_parent = $(this).parents('.input-field')

			select_parent.append('<span id="sel'+i+'"class="select-container"></span>');

			select_parent.find('select').remove()

			$('#sel'+i).append(select_elem)

			select_elem.sSelect()
		})
	}

	// Gallery fancybox */
	$('a[rel=fancybox]').fancybox()

	// Tabbed block with pagination on fronpage
	$('#block1 #tabs a').click(function(){
		if($(this).parent().hasClass('active-tab'))
			return false

		$(this).parent().removeClass('hover-prev-active')
		$(this).parent().removeClass('hover-next-active')

		$(this).parents('#tabs').find('li').removeClass('active-tab')
		$(this).parent().addClass('active-tab')

		$(this).parents('.block:first').find('.content.active').hide().removeClass('active')
		$($(this).attr('href')).show().addClass('active')

		return false
	})
	$('#block1 #slides li a').click(function(){
		if($(this).parent().hasClass('active'))
			return false

		$(this).parents('#slides').find('li').removeClass('active-slide')
		$(this).parent().addClass('active-slide')

		$(this).parents('div.content').find('.page.active').hide().removeClass('active')
		$($(this).attr('href')).show().addClass('active')

		return false
	})

	// Hot Deals tabs
	$('#text .tabs a').click(function(){
		if($(this).parent().hasClass('active'))
			return false

		$(this).parent().removeClass('hover-prev-active')
		$(this).parent().removeClass('hover-next-active')

		$(this).parents('ul').find('.active').removeClass('active')
		$(this).parent().addClass('active')

		$('#text .tab-content').removeClass('active')
		$($(this).attr('href')).addClass('active')

		return false
	})

	$('#text .tabs a, #frontpage .tabbed-block .tabs a').mouseover(function(){
		parent_el = $(this).parent()

		if(parent_el.is(':last-child'))
			return

		if(parent_el.prev('li').hasClass('active'))
			parent_el.addClass('hover-prev-active')

		if(parent_el.next('li').hasClass('active'))
			parent_el.addClass('hover-next-active')
	})
	$('#text .tabs a, #frontpage .tabbed-block .tabs a').mouseout(function(){
		$(this).parent()
			.removeClass('hover-prev-active')
			.removeClass('hover-next-active')
	})

	// Showroom tabs
	$('.showroom-tabs a').click(function(){
		$(this).parents('ul').find('li').toggle()
		$('#showroom-tab-01').toggle('fade','','800')
		return false
	})
})

function pauseSlideshow(){
	clearTimeout(slideshow_int)
	slideshow_int = setTimeout('frontpageSlideshow()', 30000)
}

function frontpageSlideshow(){
	current = $('.big-banners .tabs li.active')

	if(current.is(':last-child'))
		next = $('.big-banners .tabs li:first-child')
	else
		next = $('.big-banners .tabs li.active').next('li')

	$(current.find('a').attr('href')).fadeOut(500)

	current.removeClass('active')
	next.addClass('active')

	$(next.find('a').attr('href')).fadeIn(500)

	current_index = $('.big-banners .tabs li').index(next);
	$('.big-banners .navigation .current').text(current_index +1)

	slideshow_int = setTimeout('frontpageSlideshow()', 5000)
}
