
var Hint = {
  init: function() {
     $('.hinti[rel]').each(function() {
     $(this).qtip(
          {
             content: {
                // Set the text to an image HTML string with the correct src URL to the loading image you want to use
                text: '<img class="throbber" src="'+$(this).attr('rel')+'" />'
             },
             position: {
                corner: {
                   target: 'centerMiddle', // Position the tooltip above the link
                   tooltip: 'bottomMiddle'
                },
                adjust: {
                   screen: false // Keep the tooltip on-screen at all times
                }
             },
             show: {
                when: 'mouseenter',
                solo: true // Only show one tooltip at a time
             },
             hide: {
               when: 'mouseout'
             },
             style: {
                tip: false, // Apply a speech bubble tip to the tooltip at the designated tooltip corner
                border: {
                   width: 1,
                   radius: 1,
                   color: '#bd0107'
                }
             },
             api: {
             }
          });

     });


     $('.hinto[rel]').each(function() {
     $(this).qtip(
          {
             content: {
                // Set the text to an image HTML string with the correct src URL to the loading image you want to use
                text: $(this).attr('rel')
             },
             position: {
                corner: {
                   target: 'centerMiddle', // Position the tooltip above the link
                   tooltip: 'bottomMiddle'
                },
                adjust: {
                   screen: false // Keep the tooltip on-screen at all times
                }
             },
             show: {
                when: 'mouseenter',
                solo: false // Only show one tooltip at a time
             },
             hide: {
               when: 'mouseout'
             },
             style: {
                tip: true, // Apply a speech bubble tip to the tooltip at the designated tooltip corner
                border: {
                   width: 1,
                   radius: 1,
                   color: '#bd0107'
                }
             },
             api: {
               onContentLoad: function() {  }
             }
          });

     });


  }
}

var Tabs = {
  init: function() {
  	var tabsG1 = $('.tab_g1');

  	if (tabsG1.length > 0) {
  		nv_code = '<ul>';
  		for(t = 0; t < tabsG1.length; t++) {
  			nv_code += '<li><a href="#" rel="1;'+$(tabsG1[t]).attr('rel')+'">'+$(tabsG1[t]).html()+'</a></li>';
  			$(tabsG1[t]).hide();
  		}
  		nv_code += '</ul>';
  		$('#nv_1').html(nv_code);
  	}


  	var tabsG4 = $('.tab_g4');

  	if (tabsG4.length > 0) {
  		nv_code = '<ul>';
  		for(t = 0; t < tabsG4.length; t++) {
  			nv_code += '<li><a href="#" rel="4;'+$(tabsG4[t]).attr('rel')+'">'+$(tabsG4[t]).html()+'</a></li>';
  			$(tabsG4[t]).hide();
  		}
  		nv_code += '</ul>';
  		$('#nv_4').html(nv_code);
  	}

	$('#nv_1 a').live('click', function() {
		$('#nv_1 a').removeClass('act');
		$(this).addClass('act');
		$('.table-gr1').hide();
		var prms = $(this).attr('rel');
		var eprms = prms.split(';');
		if (eprms[1]) {
			$('.table-gq-1-' + eprms[1]).show();
		}
		return false;
	});

	$('#nv_4 a').live('click', function() {
		$('#nv_4 a').removeClass('act');
		$(this).addClass('act');

		$('.table-gr4').hide();
		var prms = $(this).attr('rel');
		var eprms = prms.split(';');
		if (eprms[1]) {
			$('.table-or-' + eprms[1]).show();
		}
		return false;
	});

  	var nv_1_elements = $('#nv_1 a');
  	if(nv_1_elements.length > 0) {
  		$(nv_1_elements[0]).trigger('click');
  	}
  	var nv_4_elements = $('#nv_4 a');
  	if(nv_4_elements.length > 0) {
  		$(nv_4_elements[0]).trigger('click');
  	}

  }
};

var Elements = {
  init: function() {

	var accars = $('.cc li a');
	if (accars.length > 0) {
		for (q=0;q<accars.length; q++) {
			//console.log($(accars[q]).width());
			//$(accars[q]).css('width', $(accars[q]).html().length*13);
		//	$(accars[q]).parent().css('width', $(accars[q]).width()+80);
		}
	}

	$("a[rel^='prettyPhoto']").prettyPhoto({theme: 'light_rounded'});

	$('.toggle-param').live('click', function() {
		$('#p-gr' + $(this).attr('id')+ ' .group-content').stop().animate({height: 'toggle', 'opacity': 'toggle'}, 300, function() {


			});
			$(this).toggleClass('ac');
		return false;
	});


    $('input.dv').defaultValue();
    $('input.na').defaultValue();
    setTimeout(function(){ $('.cc').jcarousel()} ,1500);
	var status_txt = '';
    // Newsletter
    $('.yua form').bind('submit', function() {

        $.post("/newsletter/zapisz", { email: $('#nemq').val()  },
          function(data){

          	$('#ns-status').removeClass('err-item');
            if (data.code == -1) {
              $('#ns-status').html('Podany adres e-mail jest nieprawidłowy.');
              $('#ns-status').addClass('err-item');
            }
            if (data.code == -2) {
              $('#ns-status').html('Podany adres e-mail istnieje już w bazie.');
              $('#ns-status').addClass('err-item');
            }
            if (data.code == -3) {
              $('#ns-status').html('Nie udało się zapisać adresu.');
              $('#ns-status').addClass('err-item');
            }
            if (data.code == 1) {
             $('#ns-status').html('Adres został poprawnie zapisany.');
            }

          },'json');


      return false;
    });

    // Contact
    $('.form-contact form').bind('submit', function() {

        $.post("/kontakt/wyslij", {
        	imie_nazwisko: $('#eimie_nazwisko').val(),
        	email: $('#eemail').val(),
        	tresc: $('#etresc').val(),
        	telefon: $('#etelefon').val(),
        	temat: $('#etemat').val()
        },
          function(data){

          	$('#co-status').removeClass('err-item');
            if (data.code == -1) {
              $('#co-status').html('Nie wypełniono wymaganych pól.');
              $('#co-status').addClass('err-item');
            }
            if (data.code == 1) {
             $('#co-status').html('Formularz został wysłany.');
             console.log('aaa');
            }

          },'json');

      return false;
    });
  }
};


$(document).ready(function() {
  Hint.init();
  Elements.init();
  Tabs.init();
});

function hpop(url, width, height) {
	window.open('http://www.krezel.pl/'+url,"hpop",'width=' + width + ',height=' + height + ',left=50,top=50,resizable=yes,scrollbars=no,menubar=no' );
}


