/* jQuery functions */
$(document).ready(function(){
	
	$.supersized({
	// Components
	vertical_center: 1, // Vertically center background
	horizontal_center: 1, // Horizontally center background
	slides: [ // Slideshow Images
			{image : 'http://kochamyrabaty.pl/wp-content/themes/kr/images/bg.jpg'},
			]
	});
	
	// Superfish Menu
	$('ul.menu').superfish({ 
		delay:       1000,                           // one second delay on mouseout 
		animation:   {opacity:'show',height:'show'}, // fade-in and slide-down animation 
		speed:       'normal',                       	 // faster animation speed 
		autoArrows:  false,                          // disable generation of arrow mark-up 
		dropShadows: false                           // disable drop shadows 
	});

	// jqTransform
	$('form.formCity, form.formCategory').jqTransform({imgPath:'kochamyrabaty/wp-content/themes/kr/images/forms/'});

	// Search switch
	$('.searchButtonDown').live('click',function(){
		$(this).removeClass('searchButtonDown');
		$(this).addClass('searchButtonUp');
		$('#searchInner').slideToggle();
	});
	$('.searchButtonUp').live('click',function(){
		$(this).removeClass('searchButtonUp');
		$(this).addClass('searchButtonDown');
		$('#searchInner').slideToggle();
	});

	// Toggle comment form
	$('#commentForm').hide();

	$('h4').click(function() {
		$('#commentForm').slideToggle(500);
		$(this).text($(this).text() == 'Dodaj komentarz [+]' ? 'Dodaj komentarz [-]' : 'Dodaj komentarz [+]');
		return false;
	});
	
	// Date pick
	$('.date-pick').datePicker();

	// goTop
	$.fn.scrollToTop=function(){
		
		$("#goTop").hide().removeAttr("href");
		
		if($(window).scrollTop()!="0"){
			$(this).fadeIn("slow")
		}
		var scrollDiv=$(this);
		
		$(window).scroll(function(){
								  
			if($(window).scrollTop()=="0"){
				$(scrollDiv).fadeOut("slow")
			}else{
				$(scrollDiv).fadeIn("slow")
			}
		
		});
		
		$(this).click(function(){
			$("html, body").animate({scrollTop:0},"slow");
		});
	
	}
	$("#goTop").scrollToTop();
	
	// Vgrid
	$('#gridContent').vgrid({
		easeing: 'easeOutQuint',
		useLoadImageEvent: true,
		time: 400,
		delay: 20,
		fadeIn: {
			time: 500,
			delay: 50
		}
	});

	// Tooltip only Text
	$('.masterTooltip').hover(function(){
	// Hover over code
		var title = $(this).attr('title');
		$(this).data('tipText', title).removeAttr('title');
		$('<p class="tooltip"></p>')
		.text(title)
		.appendTo('body')
		.fadeIn(1000);
	}, function() {
		// Hover out code
		$(this).attr('title', $(this).data('tipText'));
		$('.tooltip').remove();
	}).mousemove(function(e) {
		var mousex = e.pageX + -90; //Get X coordinates
		var mousey = e.pageY + -50; //Get Y coordinates
		$('.tooltip')
		.css({ top: mousey, left: mousex })
	});

});
