$(document).ready(function(){

	if ($('form#frmsender').length) {
		$('form#frmsender input#Submit').click(function() {
			
			if ($('form#frmsender input[name="txName"]').val().length == 0) {
				alert('Missing Contact Name');
				return false;
			}
			
			if ($('form#frmsender input[name="txEmail"]').val().length < 5) {
				alert('Missing contact email address');
				return false;
			}
			
			if ($('form#frmsender input[name="txLabel"]').val().length < 5) {
				alert('Missing image title');
				return false;
			}
			
		});
	}
	
	if (!$('#popupWin').length) {
		$('div#main').append('<div id="popupWin"></div>');
	}
	
    if ($('.popGalPhoto').length) {
    	
        $('.popGalPhoto').each(function() {
        	$(this).click(function(evt) {
        		$('#popupWin').html(''); 
		        $('#popupWin').hide();
		        
		        var _photoID = 0;
		        if ($(this).attr('photoID') == undefined) {
		        	var _tmp = $(this).attr('href').split('&');
		        	for(var i in _tmp) {
		        		var _tmp_s = _tmp[i].split('=');
		        		if (_tmp_s[0] == 'photoID') {
		        			_photoID = _tmp_s[1];
		        		}
		        	}
		        } else {
		        	_photoID = $(this).attr('photoID');
		        }
		        
	            $.get("?module=Gallery&event=WSView&photoID="+_photoID,
	                function(data){
	                	var _h = evt.pageY-200;
	                	if (_h < 0) {
	                		_h = 0;
	                	}
	                	var _l = evt.pageX-200;
	                	if (_l < 0) {
	                		_l = 0;
	                	}
	                	//_h = 0; // override above
	                	$('#popupWin').html(data);
	                	$('#popupWin').css('left', _l);
	                	$('#popupWin').css('top', _h);
	                    $('#popupWin').show();
	                }
	            );
	        	return false;
        	}); 
        });
    }
    
});