var dukLogic = {	
		init: function()
		{
			var qBlocks = $(".q-block");
			qBlocks.each(function(index, qblock){
				if(!$(qblock).hasClass("active")){
					var answ = $(qblock).find(".answer");
					answ.hide();
				}
				$(qblock).click(function(event){
					if($(this).hasClass("active")){
						$(this).removeClass("active");
						$(this).find(".answer").hide();
					}else{
						$(this).addClass("active");
						$(this).find(".answer").show();
					}
					event.preventDefault();
				});
			});
		}
};

//------------------------------------------------------------------- TAB logic ------------------------------
var tabLogic = {	
	init: function()
	{
		$('ul.tabs li').each(function(index, tabLi){
			var tabLink = $(tabLi).children();
			var tabHref = tabLink.attr('href');
			var tabBlockId = tabHref.replace(/#/,"");
			if(!$(tabLi).hasClass('current')){
				$("#"+tabBlockId).hide(); //hide all except current
			}	
			$(tabLink).click(function(event){
				tabLogic.clickListener(tabBlockId, tabLi);
				event.preventDefault();
			});
		});
	},
	hideAllTabBlock: function()
	{
		$('.tab-block').hide();
	},
	unselect: function()
	{
		$('ul.tabs li').removeClass('current');
	},
	clickListener: function(tabBlockId, tabLi)
	{
		tabLogic.unselect();
		tabLogic.hideAllTabBlock();
		$("#"+tabBlockId).show();
		$(tabLi).addClass('current');
	}
};
//---------------------------------------------------------------

var clockT = 0;
var clockObj = 0;
 
function stopClock(){
	clearTimeout(clockT);
	if (clockT)
		clockT = 0;
    clockObj = 0;
}
//---------------------------------------------------------------
 
function getDigitalClock(id) {
	if ((!clockObj) && (id))
		clockObj = $('#'+id);
	if (clockObj) {
		var nd = new Date();
		var h, m;
		var s;
		var time = "";
		h = nd.getHours();
		m = nd.getMinutes();
		s = nd.getSeconds();
		if (h <= 9) h = "0" + h;
		if (m <= 9) m = "0" + m;
		if (s <= 9) s = "0" + s;
		time += h + ":" + m + ":" + s;
		clockObj.text(time);
		clockT = setTimeout("getDigitalClock()", 1000);
	}
}
//---------------------------------------------------------------

//---------------- on load ----------------------------------------
$(document).ready(function (){

	jQuery('a[href^=#]:not(a.thickbox)').bind('click', function(event) {
        event.preventDefault();
        
		var name = jQuery(this).attr('href').substr(1);
        
        if(!name)
        {
            return false;
        }
        
        if($('a[name='+name+']').length)
        {
            jQuery.scrollTo('a[name='+name+']', 800, {offset: {top: -15}});
        }
        /*
        else if($('#'+name).length)
        {
            jQuery.scrollTo('#'+name);//, 800, {offset: {top: -15}});
        }
        */
	});
    //---------------------------------------------------------------
    
    $('form .text_field').focus(function(){
        if($.trim($(this).val()) == $(this).attr('title'))
        {
            $(this).val('');
        }
    });
    //---------------------------------------------------------------
    
    $('form .text_field').blur(function(){
        if($.trim($(this).val()) == '')
        {
            $(this).val($(this).attr('title'));
        }
    });
    //---------------------------------------------------------------
    
	if(document.getElementById('marquee') != null){
	  $('#marquee div').marquee('pointer').mouseover(function () {
			$(this).trigger('stop');
		}).mouseout(function () {
			$(this).trigger('start');
		}).mousemove(function (event) {
			if ($(this).data('drag') == true) {
				this.scrollLeft = $(this).data('scrollX') + ($(this).data('x') - event.clientX);
			}
		}).mousedown(function (event) {
			$(this).data('drag', true).data('x', event.clientX).data('scrollX', this.scrollLeft);
		}).mouseup(function () {
			$(this).data('drag', false);
		});
	}
    //---------------------------------------------------------------
    
	tabLogic.init();
	dukLogic.init();
	$('#faq-question-form-container').hide(); //paslepiam klausimo uzdavimo forma
    //---------------------------------------------------------------
	
	$("#submit-feedback").click(function(event){
		submitCatalogFeedbackForm();
		event.preventDefault();
	});
    //---------------------------------------------------------------
    
	$("#switch-disabled").click(function(event){
		if ($.cookie("regitra_disabled_friendly") == "on"){
			$.cookie('regitra_disabled_friendly', 'off', { path: '/'});
		}else{
			$.cookie('regitra_disabled_friendly', 'on', { path: '/'});
		}
	});
    //---------------------------------------------------------------
	
    getDigitalClock('time');
    
    /*
    $("#side-links li a").click(function(){
        var submenu = $(this).next();
        
        if(submenu.length)
        {
            if(submenu.is(':visible'))
            {
                submenu.slideUp(300);
            }
            else
            {
                submenu.slideDown(300);
            }
            
            return false;
        }
        else
        {
            return true;
        }
    });
    */
    
    /*
	$("#side-links li").hover(function(){
            var submenu = $(this).find('ul');
            
            if(submenu.length)
            {
                $(this).parent().find('li ul').not(submenu).slideUp();
                submenu.slideDown(300);
                //$(this).addClass('active');
            }
        }, function(){
            //do nothing
    });
    */
	//----------------------------------------------------------
    
    $('#drawer .drawer_video_link').click(function(){
        var id = $(this).attr('rel');
        var videoBlock = $('#'+id);
        
        videoBlock.show();
        $(this).blur();
        
        return false;
    });
	//----------------------------------------------------------
    
    $('#drawer .drawer_video_close').click(function(){
        var videoBlock = $(this).parent();
        var videoId = 'structure_' + videoBlock.attr('id');
        
        jwplayer(videoId).stop();
        
        videoBlock.hide();
        
        return false;
    });
	//----------------------------------------------------------
    
});

function validateSearchForm()
{
    var jField = $('#qSearchField');
    var value = $.trim(jField.val());
    var defaultValue = $.trim(jField.attr('title'));
    
    if ((defaultValue) && (value == defaultValue))
    {
        value = '';
    }
    $('#qSearchButton').blur();
    
    return (value) ? true : false;
}
//----------------------------------------------------------

