$(function(){
    $('.blink').
        focus(function() {
            if(this.title==this.value) {
                this.value = '';
            }
        }).
        blur(function(){
            if(this.value=='') {
                this.value = this.title;
            }
        });
})

$(function(){
	$('#contact input.field, #contact textarea, #post-comment input.field, #post-comment textarea').
		focus(function(){
			$(this).parent().addClass("focused"); }).
		blur(function(){ 
			$(this).parent().removeClass("focused"); 
			
		});		
})
 


$(function(){
    slider_current_page = 1;
    fragments_count = $('.slides-container img').length;
    images_container_fragmet_width = $('.slides-container img').width();
    text_fragment_width = $('.text-content').width();
    
    images_container = $('.slides-container');
    text_container = $('.text-slider-container');

    function set_current_page() {
        $('a.slides-ctrl').removeClass('active').eq(slider_current_page-1).addClass('active');
    }
    $('.btn-slider').live('click', function() {
        if ($(this).hasClass('next')) {
            slider_current_page++;
            if (slider_current_page > fragments_count) {
                slider_current_page = 1;
                images_container.animate({'left': 0});
                text_container.animate({'left': 0});
                set_current_page();
                return false;
            };
            images_container.animate({'left': -1 * (slider_current_page - 1) * images_container_fragmet_width});
            text_container.animate({'left': -1 * (slider_current_page - 1) * text_fragment_width});
            set_current_page();
            return false;
        };

        if ($(this).hasClass('previous')) {
            slider_current_page--;
            if (slider_current_page < 1) {
                slider_current_page = fragments_count;
                images_container.animate({'left': -1 * ((fragments_count-1)*images_container_fragmet_width)});
                text_container.animate({'left': -1 * (fragments_count-1)*text_fragment_width});
                set_current_page();
                return false;
            };
            images_container.animate({'left': -1 * (slider_current_page - 1) * images_container_fragmet_width });
            text_container.animate({'left': -1 * ( slider_current_page-1 ) * text_fragment_width});
            set_current_page();
            return false;
        };
        return false;
    });
    $('.slides-ctrl').click(function() {
        slider_current_page = parseInt($(this).attr('href').replace('#', ''));
        images_container.animate({'left': -1 * (slider_current_page - 1) * images_container_fragmet_width });
        text_container.animate({'left': -1 * ( slider_current_page-1 ) * text_fragment_width});
        set_current_page();
        return false;
    })
});
$(function(){
    $('.highligh-first-words, .regular-page-content h2').each(function(){
        var html = $(this).html();
        $(this).html($(this).html().replace(/(.*? .*?) /, '<span>$1</span> '));
    });
    $('.contact-page h2').each(function(){
        var html = $(this).html();
        $(this).html($(this).html().replace(/(.*?) /, '<span>$1</span> '));
    });
});

$(function(){
    if (!$('#gallery').length) {
        return;
    }
    var max_height = -1;
    $('#gallery .fragment').each(function(){
        var num_images = $(this).find('img').length;
        var height = Math.ceil(num_images / 5) * 172;
        if (max_height < height) {
            max_height = height;
        }
    });
    $('.slider-container').height(max_height);

    $('a.cat-btn').click(function(){
        var idx = $('a.cat-btn').index(this);
        $('a.cat-btn').removeClass('active');
        $(this).addClass('active');

        var l = parseInt(-960 * idx);
        $('.slider-inner-container').animate({
            left: l + 'px'
        });
        return false;
    });
});


$(function(){
	function observe_click(e) {
	    if ($(e.target).parents('.nice-select-box.active').length==0) {
	    	$('.nice-select-box.active').removeClass('active').find('.opts').hide();
	    	$('.nice-select-box').css('position', 'relative');
	    	$(document).unbind('click', observe_click);
	    }
	}
	$('.nice-select-box').click(function() {
		if ($(this).hasClass('active')) {
			$('.nice-select-box').not(this).css('position', 'relative');
			$(this).removeClass('active');
			$(this).find('.opts').hide();
			$(document).unbind('click', observe_click);
		} else {
			$('.nice-select-box').not(this).css('position', 'static');
			$(this).addClass('active');
			$(this).find('.opts').show();
			setTimeout(function () {
			    $(document).bind('click', observe_click);
			})
		}
	});
	
	$('.nice-select-box a').click(function () {
	    $(this).parents('.nice-select-box').find('span:eq(0)').html($(this).html());
	    $(this).parents('.nice-select-box').find('a').removeClass('selected-option');
	    $(this).addClass("selected-option");
	    $(this).parents('.nice-select-box').find('input:hidden').val($(this).attr('rel'));
	    
	});
});