/**
 * @author Cold
 */

jQuery.fn.tabsMenu = function() {
  function update(div,id) {
    $("#" + div.id + " ul.tabs > li:not(.act)").each(function() {
      $(this).css("cursor", "pointer");
    });
    $("#" + div.id + " ul.tabs > li.act").each(function() {
      $(this).css("cursor", "");
    });
    $("#" + div.id + " div.tab-content").hide();
    $("#" + div.id + " div#tab-content-" + id).show();
  };
  return this.each(function() {
    var div = $(this)[0];
    var firstId = $("#" + div.id + ' .tab-content:first').attr('id').slice(12);
    update(div,firstId);
    $("#" + this.id + " ul.tabs > li").click(function() {
      if ($(this).hasClass("act"))
        return;
      $("#" + div.id + " ul.tabs > li").removeClass("act");
      $(this).addClass("act");
      update(div,$(this).attr('id'));
      return false;
    });
  });
};

jQuery.placeHolders = function() {
	values = [];
	$(".placeholder").each(function (i){
		values[i] = $(this).val();
		$(this)
		.focus(function(){
			if ($(this).val() == values[i]) $(this).val("");
		})
		.blur(function () {
			if ($.trim($(this).val()) == "") $(this).val(values[i]);
		});
	});
};

$(document).ready(function(){
	$('#medicine-menu').hover(function(){
		$(this).find('ul').fadeIn();
	},function() {
		$(this).find('ul').fadeOut();
	});
	$('#support-menu').hover(function(){
		$(this).find('ul').fadeIn();
	},function() {
		$(this).find('ul').fadeOut();
	});
	$('#choose-language').hover(function(){
		$('.main-menu ol').fadeIn();
		$('#choose-language span').toggleClass('act');
	},function() {
		$('.main-menu ol').fadeOut();
		$('#choose-language span').toggleClass('act');
	});
	$(".accordeon").hrzAccordion(
	{
	 	containerClass     		: "product-accordeon",
		listItemClass      		: "list-item",
		contentContainerClass	: "content",
		contentWrapper     		: "content-wrapper",
		contentInnerWrapper		: "content-inner-wrapper",
		handleClass        		: "handle",
		handleClassOver    		: "handle-over",
		handleClassSelected		: "handle-selected",
		openOnLoad				: 1,
		fixedWidth				: 869
	});
	var sectionInfo = $(".section-info .text p:not(:first-child)");
	$(".show-more.show a").click(function(){
            sectionInfo.slideDown('slow', function() {
                $('.show-more.show').hide();
                $('.show-more.hide').show();
            });
            return false;
	})
        $(".show-more.hide a").click(function(){
            sectionInfo.slideUp('slow', function() {
                $('.show-more.show').show();
                $('.show-more.hide').hide();
            });
            return false;
	});
	$('#faq-accordeon').accordion({autoHeight: false, active: false});
	$('#description-tabs').tabsMenu();
	$('.main-menu ul li:first').hover(function() {
		$('.main-menu .lc').toggleClass('act');
	});
	$.placeHolders();

    $('#description-tabs ul.tabs li:first').addClass('act');
    first_id = $('.pg-image:first').attr('rel')
    $('.pg-image').parent('div').attr('id', 'img-' + first_id );
    $('#img-' + first_id).zooms({ImageId: first_id});
    
    $('.pg-preview-link').click(function(){
        var id = $(this).attr('rel');
        $('.pg-image').removeClass('act');
        $('#pg-image-'+id).addClass('act').parent('div').attr('id', 'img-' + id);
        $('.pg-preview-wrap').removeClass('act');
        $('#pg-preview-wrap-'+id).addClass('act');
        $('#img-' + id).zooms({ImageId: id});
        return false;
    });
});

/**** support icon positioning *****/
function setTopForSupport() {
    support = $('div#scrVzu'); support.css('top', $(window).height()/2 + 'px');
    if ($(window).width() <= 1400) support.css('right', 0);
    else support.css('right', ($(window).width()/1400) * 100);
}
$(document).ready(setTopForSupport);
$(window).resize(setTopForSupport);

