$(document).ready(function () {
    primaryNav();
    tabs();
    showMap();
    guestBook();
    if (javaTab == 0) {
        gallery();
        galleryColor();
    }
});

var javaTab = 0;

function guestBook() {

    var guestBook = $('.faq');

    guestBook.find('dt').each(function() {
        $(this).click(function() {
            //$(this).closest('.faq').find('dd').removeClass('active');

            guestBook.find('.active').each(function() {
                $(this).removeClass('active')
            })

            $(this).closest('dt').addClass('active');
            $(this).closest('dt').next().addClass('active');


            return false;
        })
    })
}


function inputFocus(e, msg) {
    if (e.value == msg) e.value = ''
}

function inputBlur(e, msg) {
    if (e.value == '') e.value = msg
}

function primaryNav() {
	var nav = $('.primary-nav');
	var items = nav.find('li');
	var commonItemsWidth = 0;
	
	items.each(function() {
		commonItemsWidth += $(this).width();
	});
	
	var navFreeSpace = ((nav.width() - commonItemsWidth) / items.length).toFixed(0);
	
	items.each(function() {
		$(this).find('a:first-child, span:first-child').not('.submenu a, .submenu span').css({
			'padding-left': (navFreeSpace / 2) - 1,
			'padding-right': (navFreeSpace / 2)
		});
	});
	
	items.hover(
		function() {
			$(this).find('.submenu').show(0)
		},
		function() {
			$(this).find('.submenu').hide(0)
		}
	)
	
	nav.find('.submenu').each(function() {
		$(this).hover(
			function() {
				$(this).show(0);
				$(this).prev().addClass('primary-nav-hover')
			},
			function() {
				$(this).hide(0);
				$(this).prev().removeClass('primary-nav-hover')
			}
		)
	})
}

function tabs() {
    var tabs = $('.tabs');
    var items = tabs.find('td');
    var itemIndex = 0;

    tabs.width(tabs.next().width())


    items.each(function() {
        itemIndex = $(items).index($(this));

        $(this).hover(function() {
            $(this).addClass('tabs-hover')
        },
		function() {
		    $(this).removeClass('tabs-hover')
		})

        if (itemIndex == 0) {
            $(this).addClass('tabs-first');
        }
    });
}

function showMap() {
    var obj = $('.service-center .rnd-image_a'),
		bigMap = { width: 634, height: 440 },
		widthCenter = parseInt((screen.availWidth - bigMap.width) / 2),
		heightCenter = parseInt((screen.availHeight - bigMap.height) / 2);

    obj.click(function() {
        window.open('img/map1big.jpg', '', 'width=' + bigMap.width + ', height=' + bigMap.height + ', top=' + heightCenter + ', screenY=' + heightCenter + ', left=' + widthCenter + ',screenX=' + widthCenter);
        return false;
    });
}

function gallery() {
    try {
        if ($('.gallery .scroll-holder').length) {
            $('.gallery .scroll-holder').jCarouselLite({
                btnNext: '.gallery .gallery-next',
                btnPrev: '.gallery .gallery-prev',
                mouseWheel: true,
                visible: 5,
                speed: 100,
                circular: false,
                vertical: true
            });

            $('.gallery .scroll-holder').each(function() {
                $(this).mousewheel(function(e, delta) {
                    e.stopPropagation();
                    e.preventDefault();
                })
            });

            $('.gallery .img-rounded').each(function() {
                $(this).click(function() {
                    $('.main-img').attr('src', $(this).find('img').attr('full'));
                })
            });
        }
    } catch (e) { }
}


function galleryPhotoTab() {
    try {
        if ($('.gallery-photos .scroll-holder').length) {
            $('.gallery-photos .scroll-holder').jCarouselLite({
                btnNext: '.gallery-photos .gallery-next',
                btnPrev: '.gallery-photos .gallery-prev',
                mouseWheel: true,
                visible: 5,
                speed: 100,
                circular: false,
                vertical: true
            });

            $('.gallery-photos .scroll-holder').each(function () {
                $(this).mousewheel(function (e, delta) {
                    e.stopPropagation();
                    e.preventDefault();
                })
            });

            $('.gallery-photos .img-rounded').each(function () {
                $(this).click(function () {
                    $('.main-img-photo').attr('src', $(this).find('img').attr('full'));
                })
            });
        }
    } catch (e) { }
}

function galleryColorTab() {
    try {
        if ($('.gallery-color .scroll-holder').length) {
            $('.gallery-color .scroll-holder').jCarouselLite({
                btnNext: '.gallery-color .gallery-next',
                btnPrev: '.gallery-color .gallery-prev',
                mouseWheel: true,
                visible: 5,
                speed: 100,
                circular: false,
                vertical: true
            });

            $('.gallery-color .scroll-holder').each(function () {
                $(this).mousewheel(function (e, delta) {
                    e.stopPropagation();
                    e.preventDefault();
                })
            });

            $('.gallery-color .img-rounded').each(function () {
                $(this).click(function () {
                    $('.main-img-color').attr('src', $(this).find('img').attr('full'));
                })
            });
        }
    } catch (e) { }
}

function galleryColor() {
    if ($('.gallery-color').length) {
        $('.gallery-color .img-rounded').each(function() {
            $(this).hover(
				function() {
				    $(this).find('i').addClass('img-rounded-hover')
				},
				function() {
				    $(this).find('i').removeClass('img-rounded-hover')
				}
			)
        })
    }
}
