	function popup_fs(url){
		// var url = 'http://www.doveweddingphotography.com/index2.php';
		var v = 'width='+screen.width + ', height='+screen.height + ', top=0, left=0' + ', fullscreen=yes';
		var p = window.open( link, 'jswindowname4', v);
		if (window.focus) { p.focus() }
	}


	function _popup(url) {
		document.location.href = url;
		// window.open(url);
	};


	// open link in another window
	$('a.js-el').click(function() {
		window.open($(this).attr('href'));
		return false;
	});


$(document).ready(function(){

	$('a.js-fullscreen').click(function(event) {
		event.preventDefault();
		var v = 'width='+screen.width + ', height='+screen.height + ', top=0, left=0' + ', fullscreen=yes';
		var p = window.open( $(this).attr('href'), 'jswindowname4', v);
		if (window.focus) { p.focus() }
	});

});

$(document).ready(function(){

	$('.js-hide').click( function(event) {
			event.preventDefault();
			$(this).parents('.js-hidebox').slideUp('slow');
		}
	);

	$('.js-reset').click( function(event) {
			event.preventDefault();
			// $(this).parents('form').reset();
		}
	);

	$('.js-submit').click( function(event) {
			event.preventDefault();
			error = false;

			$(this).parents('form').children('fieldset').children('input[type="text"], textarea').each( function() {
				if ($(this).hasClass('v-noempty')) {
					if (!validateNoempty($(this).val())) {
						$(this).animate( { opacity: 0.2 }, 175 ).animate( { opacity: 1 }, 150 );
						error = true;
					}

				} else if ($(this).hasClass('v-text')) {
					if (!validateText($(this).val())) {
						$(this).animate( { opacity: 0.2 }, 175 ).animate( { opacity: 1 }, 150 );
						error = true;
					}
				} else if ($(this).hasClass('v-mail')) {
					if (!validateEmail($(this).val())) {
						$(this).animate( { opacity: 0.2 }, 175 ).animate( { opacity: 1 }, 150 );
						error = true;
					}
				}
			});

			if (!error) {
				
var mesajul = $(this).parents('form').serialize();


$.ajax({
  url: ajax_path + "/add_ajax_comments.php?" + mesajul,
  cache: false
});  

	$(this).parents('form').children('fieldset').children('input[type="text"], textarea').each( function() {
this.value = this.defaultValue;
			});

  var node = $(this).parents('.js-hidebox');
  node.slideUp('slow');
				//$(this).parents('form').submit();
			}
		}
	);
	
		$('.js-submit-for-friend').click( function(event) {
			event.preventDefault();
			error = false;

			$(this).parents('form').children('fieldset').children('input[type="text"], textarea').each( function() {
				if ($(this).hasClass('v-noempty')) {
					if (!validateNoempty($(this).val())) {
						$(this).animate( { opacity: 0.2 }, 175 ).animate( { opacity: 1 }, 150 );
						error = true;
					}

				} else if ($(this).hasClass('v-text')) {
					if (!validateText($(this).val())) {
						$(this).animate( { opacity: 0.2 }, 175 ).animate( { opacity: 1 }, 150 );
						error = true;
					}
				} else if ($(this).hasClass('v-mail')) {
					if (!validateEmail($(this).val())) {
						$(this).animate( { opacity: 0.2 }, 175 ).animate( { opacity: 1 }, 150 );
						error = true;
					}
				}
			});

			if (!error) {
				
				//$(this).parents('form').submit();
var mesajul = $(this).parents('form').serialize();

$.ajax({
  url: ajax_path + "/sendtofriend.php?" + mesajul,
  cache: false
});  

	$(this).parents('form').children('fieldset').children('input[type="text"], textarea').each( function() {
this.value = this.defaultValue;
			});

 

  var node = $(this).parents('.js-hidebox');
  node.slideUp('slow');
 
			}
		}
	);

	$('a.js-add-comment').click( function(event) {
			var node = $(this).parents('.x-post').next('.js-comment').children('.f-add-comment');

			var tarea = node.children('form').children('.w-right').children('.js-ta-comm')

			var ax = 'js-add-comment js-img-id-';
			var k = $(this).attr('class');
			k = '{img}' + k.substr(ax.length, 255) + '{/img}';

			tarea.val( tarea.val() + k );

			if (node.css('display') == 'none') {
				node.slideDown('slow');
			}
		}
	);

	$('a[href="#f-add-comment"]').click( function(event) {
			event.preventDefault();

			var node = $(this).parents('.x-comment').next('.f-add-comment');
			node.slideToggle('slow');
		}
	);

	$('a[href="#f-send-to-friend"]').click( function(event) {
			event.preventDefault();

			var node = $(this).parents('.x-comment').next().next('.f-send-to-friend');
			node.slideToggle('slow');
		}
	);

	$('a[href="#hide-comments"]').click( function(event) {
			event.preventDefault();

			var ax = new Array();
			ax[0] = 'hide'; ax[1] = 'show';

			var node = $(this).parents('.x-comment').children('.js-hide-comment');
			node.slideToggle('normal');
            if ( $(this).html() == ax[0] ) { $(this).html(ax[1]); } else { $(this).html(ax[0]); }
		}
	);



});


// COMMENTS SCROLLER
$(document).ready(function(){

	var scroll_inc, scroll_offs, scroll_speed, scroll_busy;

	scroll_busy = false;
	scroll_inc = 28; /* line-height */
	scroll_speed = 333;

	//var debug = document.getElementById('debug');
	//debug.innerHTML = scroll_node.css('top');

	$('a.js-scrolldown').click(function(event) {
			event.preventDefault();
			if (scroll_busy) { return; }

			var scroll_offs = $('.x-comment .w-scroll').height() - $('.w-hide').height() - scroll_inc;

			var	scroll_node = $(this).parents('.w-action').prev('.w-hide').children('.w-scroll');

			if (parseInt(scroll_node.css('top')) >= -scroll_offs) {
				scroll_busy = true;
				scroll_node.stop();

				scroll_move = Math.floor( Math.abs(parseInt(scroll_node.css('top'))) + scroll_inc);

				scroll_node.animate(
					{ top: -scroll_move + 'px' },
					scroll_speed,
					function() { scroll_busy = false; }
				);

			} else {
				scroll_busy = false;
				scroll_node.stop();
			}
		}
	);

	$('a.js-scrollup').click(function(event) {
			event.preventDefault();
			if (scroll_busy) { return; }

			var	scroll_node = $(this).parents('.w-action').prev('.w-hide').children('.w-scroll');

			if (parseInt(scroll_node.css('top')) <= -1) {
				scroll_busy = true;
				scroll_node.stop();

				scroll_move = Math.floor( parseInt(scroll_node.css('top')) + scroll_inc);

				scroll_node.animate(
					{ top: scroll_move + 'px' },
					scroll_speed,
					function() { scroll_busy = false; }
				);

			} else {
				scroll_busy = false;
				scroll_node.stop();
			}

		}
	);

});

// FORM HELPER
$(document).ready(function(){

 function populateElement(selector, defvalue) {

		$(selector).focus(function() {
				if ($(selector).val() == 'Website') {
                    	$(selector).val('http://');
                } else if ($(selector).val() == defvalue) {
						$(selector).val('');
				}
		});

		$(selector).blur(function() {
				if ($.trim($(selector).val()) == '') {
						$(selector).val(defvalue);
				}
		});
	};

	$('input[type="text"], input[type="password"], textarea').each(function() {
			populateElement($(this), $(this).val())
		}
	);

	/* */

	var _char_count = 500;

	$('textarea').keydown( function() {
			var node = $(this).parents('form').children('.w-left').
												 children('.w-action').children('.js-count-char').children('em');

			if ($(this).val().length >= _char_count) {
				$(this).val( $(this).val().substr(0, _char_count) );
			}

			node.html( _char_count - $(this).val().length );

		}
	);
});

// RIGHT MENU
$(document).ready(function(){
	$('.w-side .menu-lvl-2 .afx2').click(function(event) {
		event.preventDefault();

		node = $(this).parents('.menu-lvl-2').children('ul');
		if (node.css('display') == 'block') {
			$(this).removeClass('selected');
		} else {
			$(this).addClass('selected');
		}

			node.slideToggle('normal');
	});

});

// ---

function validateNoempty(text) {
	if (!text || text.length < 3) return false;

	return true;
}

function validateText(text) {
	if (!validateNoempty(text)) { return false; }

	var re_text = /[^A-Za-z0-9\s]/;
	if (text.match(re_text) != null ) {
		return false;
	}
	return true;
}

function validateEmail(email) {
	if (!validateNoempty(email)) { return false; }

    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null ) {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }

    if(splitted[2] != null) {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }
      return true;
    }
    return false;
}
