/**
 *
 * RentHouse
 * skrypty ogólne
 * 
 * @project renthouse
 * @lastmodified 
 * @requires JQuery 1.4.4+
 *
 */ 
 

/**
 * pictureViewer
 * jQuery Plugin
 * 
 * @revision 2
 * @requires jquery.colorbox.min.js
 * @author Mateusz Janik
 *
 */
(function($){
$.fn.pictureViewer = function() {
	
	return this.each( function() {

		var 
		$this = $(this),
		$picture = $('.pv-picture', $this),
		$thumbs = $('.pv-thumbs', $this)
		;
		
		// init "lightbox"
		$thumbs.find('.big')
		//.attr('rel','gallery')
		.colorbox(config.colorbox);
		
		$picture.find('a').click( function () {
			$thumbs.find('li.active > .big').click();
			return false
		} );
		
		$thumbs.find('a.thumb').click(function () {
			var $self = $(this); 
			var $item = $(this).parent('li');
			
			$picture
			.find('img').attr('src', $self.siblings('.medium').attr('href'))
			.end()
			.find('a').attr('href', $self.siblings('.big').attr('href'))
			.end();
			
			$item.addClass('active').siblings().removeClass() 
			
			return false
 
		}) // click
	});	// each
}
})(jQuery);
/**/
 
 
/**
 * in-field label
 *
 * @revision 2
 * @author Mateusz Janik
 */
(function($){
	$.fn.inFieldLabel = function() {
		this.each(function() {
			var $this = $(this);
			if($this.val() === '') {
				$this.val($this.attr('title'));
			}
			$this.focus(function() {
				$this.removeClass('default');
				if($this.val() === $this.attr('title')) {
					$this.val('');
				}
			});
			$this.blur(function() {
				if($this.val() === '') {
					$this.val($this.attr('title')).addClass('default');
				}
			});
		});
		return $(this);
	}
})(jQuery);	 
 
 
/* ************************************************
   Document ready 
*/
$(function(){

 	
	/**
	 * Input w "newsletterze"
	 */
	$('#footer form :text').inFieldLabel();
	
	
	/**
	 * "Lightbox" na stronie oferty
	 */
	var $single_offer = $('.single-offer'); 
	if (typeof $.fn.colorbox != 'undefined') {
		$single_offer.find("a[rel^=gallery]").colorbox(config.colorbox);
		
		$single_offer.find('.photos .picture a').click(function (e) {
			var href = $(this).attr('href');
			$single_offer.find('.thumbs a[href="'+href+'"]').eq(0).trigger('click');
			
			e.preventDefault();
		});
	}
	
	$('#fb_widget').hover(
		function() {
			$(this).animate({right: 0}, {queue: false});
		},
		function() {
			$(this).animate({right: '-248'}, {queue: false});
		});
	
	
	/**
	 * Karuzela
	 */
function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        //carousel.stopAuto();
    }, function() {
        //carousel.startAuto();
    });
};
	 
	 
	if (typeof $.fn.jcarousel != 'undefined') { 
	$('#teaser ul').jcarousel({
		buttonPrevHTML: '<div class="ctrl"></div>',
		buttonNextHTML: '<div class="ctrl"></div>',
        auto: 2,
		scroll: 1,
        animation: 'slow',
        wrap: 'circular',
        initCallback: mycarousel_initCallback
	});
	}

	
	
	
}) // Document ready


var config = config || {};

config.colorbox = {
	opacity: .8,
	transition: 'none',
	maxWidth: '90%',
	maxHeight: '90%'
}
