﻿/* onload settings */
$().ready(function () {
	$('body').removeClass('nojs');
	$('#sec-nav ul li:first-child').addClass('p1');
	$('.col21 .col1 .block:last-child,.packagelist .package:last-child').addClass('last');
	if ($('.accordion').length > 0) {
		$('.accordion .cms:not(:first)').hide();
		$('.accordion h3:first-child').addClass('active');
	}
//    if($('.kvswitches li').length > 0){
//        $('.kvswitches li').removeClass('active');
//        $('.kvswitches li:first').addClass('active');
//        $('.keyvisuals .keyvisual').hide();
//        var indx = 0;
//        $('.keyvisuals .keyvisual:eq('+ indx+ ')').fadeIn(1200);
//    }

    if($('.keyvisuals .kv-bk').length > 0){
        $('.keyvisuals .kv-bk').click(function(){
            $('#keyvisual').removeClass('animated');
            var el = $('.kvswitches .active');
            if(el.prev().length == 0) {
                $('.kvswitches li:last').click();
            } else {
                el.prev().click();
            }
        });
    }
    if($('.keyvisuals .kv-fw').length > 0){
        $('.keyvisuals .kv-fw').click(function(){
            $('#keyvisual').removeClass('animated');
            var el = $('.kvswitches .active');
            if(el.next().length == 0) {
                $('.kvswitches li:first').click();
            } else {
                el.next().click();
            }
        });
    }

    if($('#keyvisual').length > 0){
        $('#keyvisual').addClass('animated');
        animateKeyvisual($('#keyvisual'));
    }

    if($('.newsletterform').length > 0) {
        $('.newsletterform input:text').each(function(){
            inputBlur(this);
        });
        if($('.newsletterform .msg-success').length > 0){
            _gaq.push(['_trackPageview','http://www.lifegenetics.eu//newsletter/vhvala']);
        }
    }


//    if($('.deliverytype ul li label').length > 0){
//        $('.deliverytype ul li:first label').click();
//        $('.deliverytype ul li:first input').click();
//    }

	$('a.lightbox').fancybox({
		'transitionIn'		:	'elastic',
		'transitionOut'		:	'elastic',
		'width'				:	700,
		'height'			:	380,
		'speedIn'			:	600,
		'speedOut'			:	200,
		'overlayShow'		:	true,
		'overlayOpacity'	:	0.6
	});
	$('a.iframe').fancybox({
		'width'				: 600,
		'height'			: 400,
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
	$('a.ajax').fancybox({
		'autoDimensions'	: true,
		'padding'			: 0,
		'overlayShow'		: false,
		ajax 				: {type : 'POST'}
	});
});

$('.accordion h3').click(function() {
	if($(this).hasClass('active')){
        $(this).removeClass('active');
	    $(this).next().fadeOut(200);
    } else {
        $('.accordion h3').removeClass('active');
        $('.accordion .cms').hide();
        $(this).addClass('active');
        $(this).next().fadeIn(200);
    }
});

$('.kvswitches li').click(function() {
    $('#keyvisual').removeClass('animated');
	if($(this).hasClass('active')) return false;
	$('.kvswitches li').removeClass('active');
    $(this).addClass('active');
    $('.keyvisuals .keyvisual').hide();
    var indx = $(this).index();
    $('.keyvisuals .keyvisual:eq('+ indx+ ')').fadeIn(1200);
});

/* switch product photos */
$('#slider .nav li span').click(function() {
	if($(this).parent().is('.active')) {
		return false;
	}
	/* wait until animation stops */
	if($('#slider .photos').children().is(':animated')) {
		return false;
	}
	$('#slider .nav li').removeClass('active');
	$(this).parent().addClass('active');
	var active = $(this).parent()[0].className.substr(0,2);
	$('#slider .photos img').fadeOut(500).delay(500);
	$('#slider .photos .' + active).fadeIn(800);
});

/* show / hide forms */
$('.loginform .sw').click(function() {
	$('.loginform').hide();
	$('.forgotpassword').show('slow');
});
$('.forgotpassword .sw').click(function() {
	$('.forgotpassword').hide();
	$('.loginform').show('slow');
});

function closeAddressPicker() {
    $('#lightbox').hide();
    var l = window.location.href;
    window.location.href = l;
    return false;
}

function inputFocus(el){
	if (el.value == el.title){
		el.value = '';
	}
}
function inputBlur(el){
	if (el.value == ''){
		el.value = el.title;
	}
}

function animateKeyvisual(elem){
    if(elem.hasClass("animated")){
        var el = $('.kvswitches .active');
        if(el.next().length == 0) {
            $('.kvswitches li').removeClass('active');
            $('.kvswitches li:first').addClass('active');
            $('.keyvisuals .keyvisual').hide();
            var indx = 0;
            $('.keyvisuals .keyvisual:eq('+ indx+ ')').fadeIn(1200);
        } else {
            $('.kvswitches li').removeClass('active');
            el.next().addClass('active');
            $('.keyvisuals .keyvisual').hide();
            var indx = el.next().index();
            $('.keyvisuals .keyvisual:eq('+ indx+ ')').fadeIn(1200);
        }
        setTimeout("animateKeyvisual($('#keyvisual'))", 5000);
    }
}

/* logo scroll */
$('#references .slider-fw').click(function() {
	var list = $('#references .slider .inside table');
	var width = parseInt(list.css('width'));
	var allowed_margin = 720 - width;
	var current_margin = parseInt(list.css('marginLeft'));
	if((allowed_margin - current_margin) < -150) {
		var margin = 150;
	} else {
		var margin = (allowed_margin - current_margin) * -1;
	}
	if(current_margin > allowed_margin) {
		list.animate({marginLeft:current_margin - margin + 'px'},500,function() {});
	}
});
$('#references .slider-bk').click(function() {
	var list = $('#references .slider .inside table');
	var current_margin = parseInt(list.css('marginLeft'));
	if(current_margin > -200) {
		margin = current_margin * -1;
	} else {
		var margin = 200;
	}
	if(current_margin != 0) {
		list.animate({marginLeft:current_margin + margin + 'px'},500,function() {});
	}
});
