﻿
$(document).ready(function($){
startup();
//advaccord();
});

// usage: log('inside coolFunc', this, arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
  log.history = log.history || [];   // store logs to an array for reference
  log.history.push(arguments);
  arguments.callee = arguments.callee.caller;  
  if(this.console) console.log( Array.prototype.slice.call(arguments) );
};
// make it safe to use console.log always
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();)b[a]=b[a]||c})(window.console=window.console||{});


// place any jQuery/helper plugins in here, instead of separate, slower script files.

function startup() {
	$('.topmenu a.submenu').click(function (event) {
		event.preventDefault();
	});
	
	if ($('.newsletterBox p.error').length || $('.mod_subscribe p.confirm').length || $('.mod_subscribe p.error').length) {
		$('.newsletterBox p.error, .mod_subscribe p.confirm, .mod_subscribe p.error').addClass('simple_overlay').attr('id', 'erro').insertBefore('#header-wrapper');
		$('.newsletterBox p.error, .mod_subscribe p.confirm, .mod_subscribe p.error').overlay();
		var api = $("#erro").overlay({oneInstance: false, api: true}); 
			api.load();
		
		var widthWindow = $(window).width();
		var overlayWidth = $('#erro').width();
		$("#erro").css({'left': + (widthWindow - overlayWidth) / 2 + 'px'});
		
	}
	
	$(".ce_gallery a").fancybox({
				'overlayShow'	: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic',
				'titleShow'		: false
			});
	
	
	if ($('#user-menu ul.level_2 li.currentSelection').length) {
			$('#user-menu ul.level_2 li.currentSelection').parent('ul').css('display','block').parent('li').addClass('open');
	};
	

	$(".mod_galleryviewer a[rel=group]").fancybox({
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'titleShow'		: false

	});


	
}




// znajdz najwyzszego taba
function findMaxValue(element) {
    //console.log($('#lewa .inside').height());
	//console.log($('#lewa .lmenu').height());
	//console.log($('#lewa .faded').height());
	var maxValue = undefined;
    $('#tabs > div', element).each(function() {
        var val = $(this).height();
        if (maxValue === undefined || maxValue < val) {
            maxValue = val;
        }
    });
    return maxValue;
}

function accord() {
$("#pricelist td.col_1 img").click(function (event) {
		//$(this).parent();
		//$('#pricelist td.col_1 div.pice-desc').slideUp().removeClass('open');
		//$(this).siblings('div.pice-desc').toggleClass('open');
		$(this).siblings('div.pice-desc').slideToggle("slow");
	});
};

function menuaccord() {
$("#user-menu a.submenu").click(function (event) {
		event.preventDefault();
		//$(this).parent();
		$(this).parent().siblings('li.submenu').children('ul').slideUp().siblings('a').removeClass('open');
		$(this).parent().siblings('li.submenu').removeClass('open');
		$(this).toggleClass('open');
		$(this).parent().toggleClass('open');
		$(this).next('ul').slideToggle("slow");
	});
};


function advaccord() {
$("#adsearch-button").click(function (event) {
		event.preventDefault();
		//$(this).parent();
		$(this).next('div.advanced').toggleClass('open');
	});
};


// teksty w inputach wyszukiwarki i newslattera
$.fn.ToggleInputValue = function(){
    return $(this).each(function(){
        var Input = $(this);
        var default_value = Input.val();

        Input.focus(function() {
           if(Input.val() == default_value) Input.val("");
        }).blur(function(){
            if(Input.val().length == 0) Input.val(default_value);
        });
    });
}

function kontaktform(){
	$('select#ctrl_country').change(function() {
		if ($('select#ctrl_country option:selected').val() == 'pl'){
			$('.province').css({'display':'block'});
		}else{
			$('.province').css({'display':'none'});
		}
	});
	
	var firstVal = $('select#ctrl_type option:nth-child(2)').val();
	var secondVal = $('select#ctrl_type option:nth-child(3)').val();

	// console.log(firstVal);
	// console.log(secondVal);
	
	$('select#ctrl_type').change(function() {
		if ($('select#ctrl_type option:selected').val() == firstVal){
			$('.talk, .presentacion').css({'display':'none'});
			$('.talk').css({'display':'block'});
		} else if ($('select#ctrl_type option:selected').val() == secondVal) {
			$('.talk, .presentacion').css({'display':'none'});
			$('.presentacion').css({'display':'block'});
		}else{
			$('.talk, .presentacion').css({'display':'none'});
		}
	});
}
